Firing events
Related Topics ...
Once you have an event declared, we can fire that event by calling either the fireEventName or fireTargetedEventName method added to the WebApp by the Event Declaration builder call.
Targeting an Event Towards a Specific Model
We can target an event towards a particular model by calling the fireTargetedEventName method and specifying a WebAppAccess object for the target model and any arguments defined in the Event Declaration. In the target model, include an Event Handler which specifies an action that processes the arguments passed and executes some model action.
We can target an event to the following locations (these names correspond to String constants in com.bowstreet.webapp.WebAppAccess):
- EVENT_TARGET_ALL -- Target the event to all models. Each model receives the event. If it has a matching event declaration and an event handler, the event is processed.
- EVENT_TARGET_PARENT -- Target the event to this model's "parent," which would be the model containing this model or linking to this model.
- EVENT_TARGET_SELF -- Target the event to this model. No other models receive notification of the event occurring.
- An instance of the WebAppAccess object for the "target model -- Target the event to a specific model. Use the webAppAccess.getModelInstance() method to retrieve the WebAppAccess object for another model.
To fire an event at one of the above specified targets:
- From an Action List, fire targeted event at PARENT.
fireTargetedEvent2(${Java/WebAppAccess.EVENT_TARGET_PARENT})
- From a Java method, fire targeted event at PARENT.
webAppAccess.callMethod("fireTargetedEvent2", WebAppAccess.EVENT_TARGET_PARENT);
To fire an event at a specific model:
- In the source model, create a method or method call that calls the fireEventName or fireTargetedEventName method.
For example, you might create a Method Call Builder that calls the fireTargetedEvent1 method, passing an instance of the WebAppAccess object for the target model and two String arguments: We can also call the fireEventName or fireTargetedEventName directly in a method as shown below:
WebAppAccess targetModel = webAppAccess.getModelInstance("TargetModel", null, true);
fireTargetedEvent1(webAppAccess, targetModel, "This is foo.", "This is bar.");
- Execute the method or method call that fires the event as part of another method or by adding it as an action in an Action List builder call. The following code calls the FireTargetedEvent method call shown above:
webAppAccess.callMethod("FireTargetedEvent");