Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between DispatchAction and LookupDispatchAction.

 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Can anybody tell me what is the difference between DispatchAction and LookupDispatchAction.
Thanks in advance,
Samir
 
Ravi Seshu
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
DispatchAction dispatches the action based on the parameter value. where as lookupdispatchAction which is a subclass of it, inherits all the properties but has one more additional method called getmethodkey() for all those mappings ... ex. specified in properties file.s..
-eswar
 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thats fine...but what is the use of the HashMap . Why do we need to store all the values in the key value pair.Can you please explanin with the practical example
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say you have 3 buttons on your form: add, delete, and update. If your website is in English and you're not planning to use internatoinalization, you would code the three buttons:

<html:submit property="action">add</html:submit>
<html:submit property="action">update</html:submit>
<html:submit property="action">delete</html:submit>

You could then use DispatchAction and code the methods add(), update(), and delete(), and Struts would forward to the appropriate method based on the button pressed.

However, if you use internationalization, this won't work because the label of the button could be in any number of languages. In this case, you need to use LookupDispatch action and code your JSP like this:

<html:submit property="action"><bean:message key="label.add" /></html:submit>
<html:submit property="action"><bean:message key="label.update /></html:submit>
<html:submit property="action"><bean:message key="label.delete" /></html:submit>

You'll then code the getMethodKey() to find the appropriate method based on the message key. That way, regardless of what language is actually used at runtime, Struts will still dispatch to the correct method.
 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot for your valuable guidance. This discusion forum is really helpfull for improving once ability in java.
Thank you once again.
 
carox kaur
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although this post is very old, I do not want to start a new thread.....a part of my question is answered here I think....I am not able to differentiate between the use of LookupDispatch action and Dispatch action. what lacks in dispatch action so that we have to use Lookup dispatch action?

So this means that, when we code like this:
<html:submit property="action">add</html:submit>
<html:submit property="action">update</html:submit>
<html:submit property="action">delete</html:submit>

the value of the parameter 'action' will be selected from the caption of the buttons? How the value of the action parameter is selected? If this is true, then it may also mean that the captions on the buttons should match the method names in the action class?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic