File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Dispatch VS LookupDispatch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Dispatch VS LookupDispatch" Watch "Dispatch VS LookupDispatch" New topic
Author

Dispatch VS LookupDispatch

sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
I have an Action extended to DsipatchAction with edit,delete methods.

My jsp form action = "edit.do"

<td><html:submit property="method" value="edit" />
<td><html:submit property="method" value="delete" />

Struts config file is :

<action path="/edit" type="com.xxx.web.actions.LifeAAction"
name="dataForm" scope="session" parameter="method" validate="true" input="page.lifeA">
<forward name="edit" path="page.edit" />
</action>

<action path="/delete" type="com.xxx.web.actions.LifeAAction"
name="dataForm" scope="session" parameter="method">
<forward name="success" path="page.success" />
</action>

Edit calling th action and then jsp. But when i submit delete action it is calling action and exceuting delete method but it is trying to send to edit page again instead success page. Reason my jsp form action ="/edit.do".

Ok now I thought of using LookUpDispatchAction class.

I extended action to LookupDispatchAction then implimented

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

In JSP i chaged to :

<td><html:submit><bean:message key="button.edit"/></html:submit>
<td><html:submit><bean:message key="button.delete"/></html:submit>

I also changed parameter name from "method" to "submit" in struts config file

<action path="/edit" type="com.xxx.web.actions.LifeAAction"
name="dataForm" scope="session" parameter="submit" validate="true" input="page.lifeA">
<forward name="edit" path="page.edit" />
</action>

<action path="/delete" type="com.xxx.web.actions.LifeAAction"
name="dataForm" scope="session" parameter="submit">
<forward name="success" path="page.success" />
</action>


Now when i click edit I am getting the follwing error. Can some one point me?.

the example http://www.husted.com/struts/tips/003.html is using

protected Map getKeyMethodMap(ActionMapping mapping,
ActionForm form,
HttpServletRequest request) {} with parameters but LookupDisptach action has method without signature. Not sure wich one is lates and to use.


[Servlet Error]-[Request[/edit] does not contain handler parameter named submit]: javax.servlet.ServletException: Request[/edit] does not contain handler parameter named method
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at javax.servlet.ServletException.<init>(ServletException.java:107)
at org.apache.struts.actions.LookupDispatchAction.execute(LookupDispatchAction.java:199)

Thanks
Sudhakar
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
The error was gone after I did the change in jsp and config files. I am using paramater="method" in struts config and in jsp

<td><html:submit property="method"><bean:message key="button.edit"/></html:submit>

<td><html:submit property="method"><bean:message key="button.delete"/></html:submit>

I explisitly specified property="method". I red that if i use parameter="submit" struts submit tag has default name as submit. But some how it does not work.

But i stil have problem with when i press delete button , delete method was executed but it is trying to redirect to edit.jsp instead of success page as my jsp from action="edit.do"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dispatch VS LookupDispatch