Dispatch Action
Basically Dispatch action is used when you have multiple submit buttons in a single form.
The Dispatch action is a class which extends the Struts DispatchAction,
and encpsulates all the action methods (similar to execute method in Action class)
in one single class.
In the Struts-Config.xml you need to define the DispatchAction class and the parameter name that you passing in the URL.
Based on the parameter the Controller will invoke the action method.
The DispatchAction is a special Action class within Struts
that allows different functions to be called depending on a value of a parameter in a request object
Every Action in the JSP page need not have a different/Separate Action class to handle the request.
Instead one Dispatch Action class can handle all this.
Basing on the action selected a value is passed to the Dispatch Action and the corresponding method gets executed which
would handle the Action. Dispatch Action extends the Action class.
This way the Dispatch Action reduces the Developement time and also eases the process of maintenance.
DispatchAction is another useful built-in Struts Action. However you cannot use it as is.
You will have to extend it to provide your own implementation.
An interesting thing to notice is that the value of the HTTP
request parameter named step is same as the four method names in CreditAppAction
http://localhost:8080/bank/screen-credit-app.do?step=reject&id=2
http://localhost:8080/bank/screen-credit-app.do?step=approve&id=2
http://localhost:8080/bank/screen-credit-app.do?step=addComment&id=2
DispatchAction knows what parameter to look for in the incoming URL
request through this attribute named parameter in struts-config.xml.
(the request parameter that will uniquely identify all actions.)
the arguments and their order in these methods is fixed by DispatchAction
the method invocation by reflection at runtime is successful.
Basically Dispatch action is used when you have multiple submit buttons in a single form.
The Dispatch action is a class which extends the Struts DispatchAction,
and encpsulates all the action methods (similar to execute method in Action class)
in one single class.
In the Struts-Config.xml you need to define the DispatchAction class and the parameter name that you passing in the URL.
Based on the parameter the Controller will invoke the action method.
The DispatchAction is a special Action class within Struts
that allows different functions to be called depending on a value of a parameter in a request object
Every Action in the JSP page need not have a different/Separate Action class to handle the request.
Instead one Dispatch Action class can handle all this.
Basing on the action selected a value is passed to the Dispatch Action and the corresponding method gets executed which
would handle the Action. Dispatch Action extends the Action class.
This way the Dispatch Action reduces the Developement time and also eases the process of maintenance.
DispatchAction is another useful built-in Struts Action. However you cannot use it as is.
You will have to extend it to provide your own implementation.
An interesting thing to notice is that the value of the HTTP
request parameter named step is same as the four method names in CreditAppAction
http://localhost:8080/bank/screen-credit-app.do?step=reject&id=2
http://localhost:8080/bank/screen-credit-app.do?step=approve&id=2
http://localhost:8080/bank/screen-credit-app.do?step=addComment&id=2
DispatchAction knows what parameter to look for in the incoming URL
request through this attribute named parameter in struts-config.xml.
(the request parameter that will uniquely identify all actions.)
the arguments and their order in these methods is fixed by DispatchAction
the method invocation by reflection at runtime is successful.
No comments:
Post a Comment