2. Set the action name to the action attribute of html:link
// eventdispatchaction.jsp |
|
3. Either directly use the method name to call as a query string parameter, or use an alias.
// eventdispatchaction.jsp ( Direct calling ) |
// eventdispatchaction.jsp ( Calling using an alias ) |
What are the advantages?
-
Events can be attached to controls directly.
-
No need to use a separate hidden variable or a query string for mapping the method name to the actual method to call.
-
Actual method to call can be aliased with a pseudo name.
What are the disadvantages?
-
The need to extend the class from EventDispatchAction and hence cannot extend our class from a custom base class.
EventActionDispatcher
How to create one?
-
Extend your action from Action, similar to the case in ActionDispatcher. This is what is desirable for us.
// CRUDEventActionDispatcher.java /** * This is an example class for demonstrating EventActionDispatcher * functionality. Observe here that we can also extend our class from * BaseAction class like in ActionDispatcher example and move our * session validation to that class. *
|
2. Set the action name to the action attribute of html:link.
// eventactiondispatcher.jsp |
3. Either directly use the method name to call as a query string parameter, or use an alias.
// eventactiondispatcher.jsp ( Direct calling ) |
// eventactiondispatcher.jsp ( Calling using an alias ) |
What are the advantages?
-
Events can be attached to controls directly.
-
No need to use a separate hidden variable or a query string for mapping the method name to the actual method to call.
-
Actual method to call can be aliased with a pseudo name.
What are the disadvantages?
1. None.
Note that the use of true (read=true) while using the query string variable to specify the event name is optional. Also, note that this variable is different from the one we used earlier (methodToCall). Here we directly specify the event name or its alias not the variable name or the actual method to call.
Assumptions
-
It is assumed that you have the complete source code of this discussion with you.
-
For some examples, I assume that our application is a full fledged web application wherein a user is authenticated before entry into the system and we are validating the user session in a base class. Why is this so important? Because, to use some types of aggregations, we should extend our action class from a specific subclass of Action. This restricts us from extending the action class from a custom base class. DispatchAction is an example of such an action.
-
It is assumed that all we are interested in are the Create, Read, Update and Delete operations on an entity in the database. These
actions, also called CRUD actions, are the basis for all the examples of this discussion.
-
One more assumption is that it is assumed that we are interested in attaching events to the HTML controls, which you may be familiar in JSF, where in we attach events to the controls using action and actionListener attributes.
-
It is assumed that the examples provided depict only one way of usage. You are free to experiment with the code, like for instance, replacing query string with hidden variables.
Source Code
0 comments:
Post a Comment