hi,
I am just a novice java developer, developing an application which requires more than one submit button in a single form, for which i have extended LookupDispatchAction class. However i am unable to fix the error with the message
java.lang.NoSuchMethodException, which appears whenever i click on the buttons in spite of having the method in the action class. Below is the code snippet. I request if anyone could help me out. Thanks.
JSP
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix = "html" %>
<%@ taglib uri = "/WEB-INF/struts-bean.tld" prefix = "bean"%>
<html><body>
<html:form action="homeSearch.do">
<table>
<tr>
<td><strong>Search by Email</strong></td>
<td><html:submit property="dowhat">
<bean:message key="ldApp.submit.button.eSearch"/>
</html:submit></td>
</tr>
<tr>
<td><strong>Search by Eid</strong></td>
<TD><html:submit property="dowhat">
<bean:message key="ldApp.submit.button.idSearch"/>
</html:submit> </TD>
</tr>
<tr>
<td><strong>Search by Phone</strong></td>
<td><html:submit property="dowhat">
<bean:message key="ldApp.submit.button.pSearch"/>
</html:submit></td>
</tr>
</table>
</html:form></body></html>
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans >
<form-bean name="tmpForm" type="org.apache.struts.action.DynaActionForm" />
</form-beans>
<global-exceptions />
<global-forwards >
<forward name="email" path="/emailHome.jsp"/>
<forward name="id" path="/idHome.jsp"/>
<forward name="phone" path="/PhoneHome.jsp"/>
</global-forwards>
<action-mappings>
<action path="/homeSearch" name="tmpForm" type="com.lookup.struts.myLDAction"
parameter="dowhat" scope="request" input="/Home.jsp"
>
<forward name="email" path="/emailHome.jsp"/>
<forward name="id" path="/idHome.jsp"/>
<forward name="phone" path="/PhoneHome.jsp"/>
</action>
</action-mappings>
<message-resources parameter="com.lookup.struts.ApplicationResources" />
</struts-config>
myLDAction class
public class myLDAction extends LookupDispatchAction {
protected Map getKeyMethodMap() {
// TODO Auto-generated method stub
Map mp = new HashMap();
mp.put("ldApp.submit.button.eSearch", "EmailSearch");
mp.put("ldApp.submit.button.idSearch", "IDSearch");
mp.put("ldApp.submit.button.pSearch", "PhoneSearch");
return mp;
}
public ActionForward EmailSearch(ActionForm af, ActionMapping am,
HttpServletRequest req, HttpServletResponse res) throws Exception{
DynaActionForm df = (DynaActionForm)af;
// do search logic
return am.findForward("email"); // forwards to a jsp page
}
public ActionForward IDSearch(ActionForm af, ActionMapping am,
HttpServletRequest req, HttpServletResponse res) throws Exception{
DynaActionForm df = (DynaActionForm)af;
// do search logic
return am.findForward("id"); // forwards to a jsp page
}
public ActionForward PhoneSearch(ActionForm af, ActionMapping am,
HttpServletRequest req, HttpServletResponse res) throws Exception{
DynaActionForm df = (DynaActionForm)af;
// do search logic
return am.findForward("phone"); // forwards to a jsp page
}
}
{cod*e}*
*Error*
Jan 13, 2009 1:58:56 PM org.apache.struts.actions.DispatchAction dispatchMethod
SEVERE: Action[homeSearch] does not contain method named 'EmailSearch'
java.lang.NoSuchMethodException: com.lookup.struts.myLDAction.EmailSearch(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
at java.lang.Class.getMethod(Class.java:978)
...............
Edited by: Chinglai on 13 Jan, 2009 1:29 PM
Edited by: Chinglai on 13 Jan, 2009 2:01 PM