What is the main difference between Action and DispatchAction classes

Showing Answers 1 - 18 of 18 Answers

Ganesh

  • May 24th, 2007
 

A DispatchAction contains a number of different methods other than the
standard execute(). These methods are executed based on some request parameter.
Your action mapping in struts-config specifies the request parameter to examine.
Then, whatever the value of that parameter is for a given request, Struts will
try to execute the method in the action whose name matches the value of the
parameter.


A LookupDispatchAction by contrast determines which method to call not based
directly on a request parameter's value, but by doing a lookup to determine the
method, based on the value of the parameter. You provide a method that accepts
the value of the request parameter and returns the method to execute. How you
actually implement the lookup is of course up to you, but a simple Map is
probably most typical.


I suppose if I were to state the difference as concisely as possible, I would
probably say this...


The method to execute on a DispatchAction is determined by Struts based on
the value of a specified request parameter, whereas the method to execute on a
LookupDispachAction is determined by your Action itself based on the value of a
specified request parameter

Baburao

  • Sep 25th, 2007
 

The main difference of Action and Dispatch action is in Action thers is only one execute method is used but Dispatch action more number of execute methods is written.

  Was this answer useful?  Yes

DispatchAction class is the subclass of action class.this class enables to the user to collect related functions into a single action.it elemenates the need of creating multiple independent actions for each funtion. 

koseavase

  • Jan 23rd, 2008
 

DispatchAction is used to group related actions together

Instead of a single execute() method, in DispatchAction their are many methods each representing an logical action.

DispatchAction dispatch the request to the method (representing an logical action) based on the value of the name parameter

  Was this answer useful?  Yes

ckanth99

  • Mar 26th, 2008
 

An Action class is part of the controller which is used as an adaptor between the web tier and business tier.  An Action class is invoked by ActionServlet to perform an operation depending on the request URL.

DispatchAction and LookupDispatchAction both are used to combine related operations into a single class, so that they can share common resources like helper methods without exposing them to other classes.

DispatchAction selects the method to execute depending on the request parameter value which is configured in the xml file. This will be problematic for internationalized applications since the values will be different for different locales. So, LookupDispatchAction looks into the resource bundle file and find out the corresponding key name. We can map this key name to a method name by overriding the getKeyMethodMap() method.

Overall, Action class is used to perform an operation.  DispatchAction is used to encapsulate related actions into a single class.  LookupDispatchAction is similar to DispatchAction, but it will be used for Internationalized applications.

  Was this answer useful?  Yes

If our Form has single function we have to go for action class but if our Form has to perform multiple functions then we have go for dispatch action.In struts config we have to provide parameter="methodToCall"  and in the jsp we have to   provide    

 <html:link action="crudDispatchActionmethodToCall=create">Create</html:link>

If single Form has to perform mutiple functions then we have to go for DispatchAction so that in a single action class we can write multiple methods(execute Methods with our own names) in an action class ,bec it reduces the number of action classes to be Created

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions