You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Tiller, Volker" <Ti...@lau.mlu.lsa-net.de> on 2005/08/18 11:55:53 UTC

LookupDispatchAction, trying Ted Husted Tip #3

Trying the example in

http://husted.com/struts/tips/index.html

#3 Use LookupDispatchAction ...

I use following Action, Form, JSP, application.properties and struts-config

+++Action

public final class MyAction extends LookupDispatchAction {
    
private static Log log = LogFactory.getLog(MyAction.class);

    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
      log.info("--- in add()");
      return mapping.findForward("success");
    }

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

}

+++Form:

public final class MyForm extends ActionForm {
       
	private String prop;

	public String getProp() {
		return prop;
	}

	public void setProp(String prop) {
		this.prop = prop;
	}
    
}

+++JSP: /tiles/test.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ include file="taglibs.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>test LookupDispatchAction...</title>
</head>
<body>

<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>


</body>
</html>



+++application.properties:

button.add=add it all
button.delete=delete it all

+++struts-config

    <global-forwards>
        <forward name="welcome" path="/Welcome.do"/>
        <forward name="testit" path="/test.do"/>
    </global-forwards>

    <form-bean 
        name="MyForm" 
        type="lau.layers.actions.forms.MyForm"/>

<action-mappings>
 <action path="/test"
	type="lau.layers.actions.MyAction"
	name="MyForm"
	scope="request"
	input="/tiles/test.jsp"
	parameter="method">
	<forward name="success" path="/Welcome.do"></forward>
 </action>
 </action-mappings>
 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The forward
 
 <html:link forward="testit" styleClass="menuitem">test it</html:link>
 
gets

ERROR DispatchAction:220 - Request[/test] does not contain handler parameter named 'method'.  This may be caused by whitespace in the label text.

Altering the global forward 'testit' to

<forward name="testit" path="/test.do?method=button.add"/>

gets

javax.servlet.ServletException: Action[/test] missing resource 'button.add' in key method map
	org.apache.struts.actions.LookupDispatchAction.getLookupMapName(LookupDispatchAction.java:240)
	org.apache.struts.actions.LookupDispatchAction.getMethodName(LookupDispatchAction.java:281)
	org.apache.struts.actions.LookupDispatchAction.execute(LookupDispatchAction.java:158)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

What have I missunderstood about LookupDispatchAction ?
Many thanks for a hint!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org