saoj
Joined: 22/12/2007 07:20:02
Messages: 22
Offline
|
This chapter is important because it will show you all the ways you can use to setup your actions in the application manager. If you decide not to configure anything, then Mentawai will use its conventions, for example a request to http://www.mysite.com/HelloAction.hello.mtw will call the hello() method of the HelloAction class. The default consequence for the action will be a forward to the /HelloAction/hello.jsp.
As we have discussed in earlier chapters, sometimes there is no way out and you have to configure your actions. This chapter will show you how to do it.
Note that we are adding a global filter that will be applied to all actions. We are also adding a filter specific to the action (VOFilter). Two consequences (one for JSP and one for SUCCESS) and a global consequence for the result LOGIN are being added as well.
No inner action was specified, so by default this configuration will be considered for all inner actions inside UserAction.class. The following actions will be executed with the filters and consequences configured above:
http://www.mysite.com/User.mtw
http://www.mysite.com/User.add.mtw
http://www.mysite.com/User.del.mtw
Basically all inner actions inside the UserAction class will have the configuration specified for the UserAction class. Now let's get more specific.
You can add consequences and filters specific for a single inner action. Let's add a filter and a consequence specific for the add inner action, in other words, for requests to http://www.mysite.com/User.add.mtw:
So for our example, we will have the following filters being executed, in the following order:
AuthenticationFilter -> VOFilter -> AuthorizationFilter -> UserAction.add
Note that global filters are always executed first, then comes the action specific filters, then comes the inner action specific filters.
For consequences, the rule is simple:
First try to get a consequence specific to the inner action. If not found, try to get a consequence specific to the action. If not found, try to get a global consequence. If still not found, go by the Mentawai conventions: forward to /User/add.jsp.
You can get even more specific creating a whole ActionConfig object just for the inner action you want to configure. The filters and consequences you define will be applied only for the inner action specified in the action config. Below is an example:
You can play with the order of the filters with some methods like ActionConfig.addFilterFirst(), that will add a filter to be executed BEFORE the global filters. You can also make your action implement the GlobalFilterFree interface, to signal to the controller that it does not want any global filters. And you can also add a global filter that will be executed LAST, in other words, after all other filters have been executed. This will be rare cases, when for some very particular scenario you need to take more control in the invocation chain of filters.
Below are some examples of these rare methods:
|