Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Diggerence in action

 
Sagar Kumbhar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i am new to struts and i want to know that what is the difference between action and dispach action..

waiting for reply.
 
Alaa Nassef
Ranch Hand
Posts: 471
Hibernate Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sagar Kumbhar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey
thanks Alaa Nassef
i got my doubt cleared with such a detail explaination
thanks once again!!
 
Alaa Nassef
Ranch Hand
Posts: 471
Hibernate Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem. Always glad to help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic