aspose file tools*
The moose likes Struts and the fly likes LookupDispatchAction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "LookupDispatchAction" Watch "LookupDispatchAction" New topic
Author

LookupDispatchAction

Andr� Branco
Greenhorn

Joined: Sep 28, 2004
Posts: 7
Hi!

I would like to know if it�s possible to invoke an action (using LookupDispatchAction) using a link for example
SomeAction.do?method=add

I know that is possible to do using DispatchAction, and that I can relate any action with a submit button, for example.

Any tips?

Thanks!

Regards,
Andr�.
Sagar Kar
Greenhorn

Joined: Sep 03, 2004
Posts: 25
This is the explanation found in the LookupDispatchAction's JavaDoc API.
Hope this helps.

An abstract Action that dispatches to the subclass mapped execute method. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified by the parameter property of the corresponding ActionMapping. To configure the use of this action in your struts-config.xml file, create an entry like this:

<action path="/test"
type="org.example.MyAction"
name="MyForm"
scope="request"
input="/test.jsp"
parameter="method"/>

which will use the value of the request parameter named "method" to locate the corresponding key in ApplicationResources. For example, you might have the following ApplicationResources.properties:

button.add=Add Record
button.delete=Delete Record

And your JSP would have the following format for submit buttons:

<html:form action="/test">
<html:submit property="method">
<bean:message key="button.add"/>
</html:submit>
<html:submit property="method">
<bean:message key="button.delete"/>
</html:submit>
</html:form>

Your subclass must implement both getKeyMethodMap and the methods defined in the map. An example of such implementations are:

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

public ActionForward add(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// do add
return mapping.findForward("success");
}

public ActionForward delete(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// do delete
return mapping.findForward("success");
}


Warm regards,<br />Sagar Kar.<br />SCJP 1.4, SCBCD 1.3
Sagar Kar
Greenhorn

Joined: Sep 03, 2004
Posts: 25
This is the explanation found in the LookupDispatchAction's JavaDoc API.
Hope this helps.

An abstract Action that dispatches to the subclass mapped execute method. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified by the parameter property of the corresponding ActionMapping. To configure the use of this action in your struts-config.xml file, create an entry like this:

<action path="/test"
type="org.example.MyAction"
name="MyForm"
scope="request"
input="/test.jsp"
parameter="method"/>

which will use the value of the request parameter named "method" to locate the corresponding key in ApplicationResources. For example, you might have the following ApplicationResources.properties:

button.add=Add Record
button.delete=Delete Record

And your JSP would have the following format for submit buttons:

<html:form action="/test">
<html:submit property="method">
<bean:message key="button.add"/>
</html:submit>
<html:submit property="method">
<bean:message key="button.delete"/>
</html:submit>
</html:form>

Your subclass must implement both getKeyMethodMap and the methods defined in the map. An example of such implementations are:

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

public ActionForward add(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// do add
return mapping.findForward("success");
}

public ActionForward delete(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// do delete
return mapping.findForward("success");
}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: LookupDispatchAction