File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Diggerence in action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Diggerence in action" Watch "Diggerence in action" New topic
Author

Diggerence in action

Sagar Kumbhar
Greenhorn

Joined: Oct 27, 2007
Posts: 17
hi,
i am new to struts and i want to know that what is the difference between action and dispach action..

waiting for reply.


SCJP 5
Alaa Nassef
Ranch Hand

Joined: Jan 28, 2008
Posts: 467
Hello Sagar,
The answer is quiet simple. Action is a class that you extend, and overwrite the execute where you put your action logic. But there is a small problem that might face you in some applications, where in a single page you might need to give the user the opportunity to choose from several actions. The problem is that the html form can have (at a time) one and only one action.

There are several solutions to this problem. One of them is to use javascript to change the form's action, then submit it. Another solution is to have a parameter in the form, and you check for it in your action, and according to the value of that parameter, you choose what to do through conditions in your code. A third solution is using DispatchAction.

DispatchAction is simply the same the same as the second solution, except that you don't have to write the conditions yourself. All you have to do is to create the methods that you want for that action having a signature similar to that of execute that is present in the Action class. You'll have to change the config of the action in the configuration file a little, to add a parameter. This parameter is going to be present in the form bean class and in the JSP, the values of this parameter are going to be the same as the method names. According to the value, struts will automatically call the appropriate method.

Check the pdf for advanced actions in this site. It's very informative.
[ January 30, 2008: Message edited by: Alaa Nassef ]

Visit my blog: http://jnassef.blogspot.com/
Sagar Kumbhar
Greenhorn

Joined: Oct 27, 2007
Posts: 17
hey
thanks Alaa Nassef
i got my doubt cleared with such a detail explaination
thanks once again!!
Alaa Nassef
Ranch Hand

Joined: Jan 28, 2008
Posts: 467
No problem. Always glad to help.
 
 
subject: Diggerence in action