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/22 09:09:17 UTC

LookupDispatchAction-problem getting started

Hi all,

I can't get started with the example about using LookupDispatchAction of Ted Husted, Tip #3 (http://husted.com/struts/tips/index.html).
What is my error or can I get some working code ?

This is the problem:
++++++++++++++++
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)

+++++++++++++++++

This is the code

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

Thanks, Volker.

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


Re: LookupDispatchAction-problem getting started

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Tiller, Volker" <Ti...@lau.mlu.lsa-net.de>

> I can't get started with the example about using LookupDispatchAction
> of Ted Husted, Tip #3 (http://husted.com/struts/tips/index.html).
> What is my error or can I get some working code ?

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

The 'method' parameter should be set to the _value_ from 
ApplicationResources.properties (not the key).  I'm not sure how to encode 
the spaces to do this manually, maybe method=add+it+all or 
method=add%20it%20all.  Or maybe the spaces will just work. (It's early...)

Here's what happens:
- the framework sees "add it all" as the value of the 'method' parameter
- it figures out that 'add it all' came from the 'button.add' property
- looks up 'button.add' in the keyMethodMap and finds 'add'
- calls the 'add' method in your Action

(Naming the parameter something other than 'method' may make things 
clearer-- maybe 'choice'.)

HTH,
-- 
Wendy Smoak



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