| | 1 | There are six built-in event-handlers that are commonly used: |
| | 2 | |
| | 3 | 1. modelglue.onApplicationStart |
| | 4 | 1. modelglue.onSessionStart |
| | 5 | 1. modelglue.onSessionEnd |
| | 6 | 1. modelglue.onRequestStart |
| | 7 | 1. modelglue.onRequestEnd |
| | 8 | 1. modelglue.onQueueComplete |
| | 9 | |
| | 10 | The first five events listed should be intuitive enough as to when they are invoked -- the sixth, onQueueComplete, is fired after all the views for a request have been queued, and before they are rendered. |
| | 11 | |
| | 12 | Each of these event-handlers broadcasts a message of the same name without the "modelglue." prefix, so for example, the modelglue.onRequestStart event-handler broadcasts an onRequestStart message. |
| | 13 | |
| | 14 | So if you wish, you can just add a message-listener to your controller XML definition for the |
| | 15 | appropriate message broadcast. |
| | 16 | |
| | 17 | |
| | 18 | {{{ |
| | 19 | <controller name="GlobalController" type="This.Is.An.Example.Controller"> |
| | 20 | <message-listener message="onApplicationStart" /> |
| | 21 | <message-listener message="onSessionStart" /> |
| | 22 | <message-listener message="onSessionEnd" /> |
| | 23 | <message-listener message="onRequestStart" /> |
| | 24 | <message-listener message="onRequestEnd" /> |
| | 25 | <message-listener message="onQueueComplete" /> |
| | 26 | </controller> |
| | 27 | }}} |
| | 28 | |
| | 29 | If you used the definition above, Model Glue would call the method GlobalController.onApplicationStart() when the application started up. Model Glue would also call the GlobalController.onSessionStart() method whenever a new session was created... and so on for each of the six messages above. |
| | 30 | |
| | 31 | If you prefer, however, you can define the relevant event-handler as a complete event-handler. This can give you more control over just calling a controller method. The following example shows how you might use the onRequestStart built in event to log all requests and check permissions before each request. If the permissions are not correct, we redirect the user to an Action.Not.Allowed page. |
| | 32 | |
| | 33 | {{{ |
| | 34 | |
| | 35 | <event-handler name="ModelGlue.onRequestStart"> |
| | 36 | <broadcasts> |
| | 37 | <message name="writeAuditLogForRequestAttempt" /> |
| | 38 | <message name="verifyPermissions" /> |
| | 39 | </broadcasts> |
| | 40 | <results> |
| | 41 | <result name="InvalidPermissions" do="Action.Not.Allowed" redirect="true" /> |
| | 42 | </results> |
| | 43 | </event-handler> |
| | 44 | |
| | 45 | }}} |
| | 46 | |
| | 47 | Using the built in event handlers in Model Glue will give you access to important application events and help you add functionality to your applications at each slice of application lifecycle. |