Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

diffrence between dispatch action and lookupdispatch action

write simple web appliction (insert records in database)

Answer Posted / java_developer

The difference between LookupDispatchAction and
DispatchAction is that the actual method that gets called in
LookupDispatchAction is based on a lookup of a key value
instead of specifying the method name directly.

Details :

LookupDispatchAction is subclass of DispatchAction.
In case of DispatchAction, you have to declare the method
name in the JSP page.
For Example :
http://localhost:8080/emp/empaction.do?step=add // IN CASE
OF DispatchAction
here step=add , we are delaring method name in JSP.
or
<html:submit property="step">Add</html:submit> //IN CASE OF
DispatchAction
so we can't use localization for button.


To over come both the issues below
a)method name declaration in JSP
b)can't use localization for button
We will go for LookupDispatchAction.

In the LookupDispatchAction :
For example :
If there are three operation like add, delete, update employee.
You can create three different Actions ?
AddEmpAction, DeleteEmpAction and UpdateEmpAction.
This is a valid approach, although not elegant since there
might be duplication of code across
the Actions since they are related. LookupDispatchAction is
the answer to this
problem. With LookupDispatchAction, you can combine all
three Actions into one.

Example :
Step 1.
three buttons might be
<html:submit property="step">
<bean:message key="button.add"/>
</html:submit>
<html:submit property="step">
<bean:message key="button.delete"/>
</html:submit>
<html:submit property="step">
<bean:message key="button.update"/>
</html:submit>

//No need method name declaration in JSP . Button name from
resource bundle.

Step 2.
In the the Resource Bundle. //Here you can add localization.
button.add=Add
button.delete=Delete
button.update=Update

Step 3.
Implement a method named getKeyMethodMap() in the subclass
of the
LookupDispatchAction. The method returns a java.util.Map. The
keys used in the Map should be also used as keys in Message
Resource
Bundle.

public class EmpAction extends LookupDispatchAction {

public Map getKeyMethodMap()
{
Map map = new HashMap();
map.put("button.add", "add");
map.put("button.delete", "delete");
map.put("button.update", "update");
}


public ActionForward add(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception
{
//your logic
mapping.findForward("add-success");
}

public ActionForward delete(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception
{
//your logic
mapping.findForward("delete-success");
}

public ActionForward update(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception
{
//your logic
mapping.findForward("update-success");
}

}

in struts-config.xml

<action path="/empaction"
input="/empform.jsp"
type="list.EmpAction"
parameter="step"
scope="request"
validate="false">
<forward name="add-success"
path="addEmpSuccess.jsp"
redirect="true"/>
<forward name="delete-success"
path="deleteEmpSuccess.jsp"
redirect="true"/>
<forward name="update-success"
path="updateEmpSuccess.jsp"
redirect="true"/>
</action>

for every form submission, LookupDispatchAction does the
reverse lookup on the resource bundle to get the key and
then gets the method
whose name is associated with the key from
getKeyMethodmap().


Flow of LookupDispatchAction:
a) Form the button name "Add" get the key "button.add" fro
resource bundle.
b) then in the Map getKeyMethodMap() find the value
associated with the key "button.add".
c) value from the Map is "add" . then call add() method of
the same action class.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain about struts relation to html tags?

906


What is the difference between plain-validator and field-validator?

900


Are actions thread safe?

920


Who makes the struts?

889


what is ACID test for fresh engineers??what is the pattern??

2742


Can you give an overview of how a struts application flows?

904


What is http forward?

922


What are inner class and anonymous class?

942


What is the difference between filters and interceptors ?

1034


Explain about token feature in struts?

927


Why are struts tightly coupled?

935


How exceptions are handled in struts application?

1089


What are the bundled validators?

964


Briefly tell the two kinds of form beans.

917


When should we use SwtichAction?

1006