Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in using DispatchAction

 
Mandar Velankar
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using DispatchAction to call my own public method in class which extends DispatchAction, but problem is my required method is not called , instead execute() method is called. Where is problem?
Here is my code

JSP Page
....
....
<html:form action="/addshade">
<html:hidden property="method" value="mymethod" />
<table width="100%" border="0" cellpadding=3 cellspacing=1 bgcolor="#FFFFFF" class="TextContenttext" >
<tr bgcolor="#f0f0f0">
<td colspan="2"><html:errors/></td>
</tr>
....
....
</table>
</html:form>
....
....

Action mapping entry in struts-config.xml
....
....
<action-mappings>
<action path="/addshade"
type="coreservlets.production.ShadeAction"
name="shadeFormBean"
scope="session"
input="/pages/production/add_shade.jsp"
parameter="method"
>
<forward name="missing-value"
path="/pages/production/add_shade.jsp"
redirect="true"/>
<forward name="success"
path="/pages/production/saveshade.jsp"/>
</action>
</action-mappings>
....
....

Action Class

....
....
public class ShadeAction extends DispatchAction{

/** Creates a new instance of ShadeAction */
public ShadeAction() {
}
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
request.getSession().getServletContext().log("ShadeAction::Inside execute of ShadeAction");
....
....
}
....
....
public ActionForward mymethod(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
request.getSession().getServletContext().log("ShadeAction::Inside mymethod of ShadeAction");
return(mapping.findForward("success"));
}

}

But from logs , it shows execute() method is called.
Where is mistake? Thanks a lot.
wait for your replies.

Regards
Mandar Velankar
 
RoshaniG Gopal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mandar,

As far as I know you the ActionClass will run the execute() methods of the ActionClass and not any other method. In case you want to call any other method you have to call from within the execute().
Please refer to foll for more information.
http://struts.apache.org/1.2.7/api/org/apache/struts/action/Action.html
 
Kamesh Rao
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using a dispatch action you need to set the parameter property in the action mapping of the struts-config.xml file with some value and when submitting such an action you have to send a request parameter with the parameter name to the one you entered in the config file and the value of this parameter should be the method which you want to call in your action.

Example:
In struts config file you will have an entry like this

< action path="/search" parameter="methodType" .... >

In your jsp you should submit as follows

http://localhost:8080/contextpath/search?methodType=someMethodName

Hope it helps
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The logic that forwards to your custom method is in the execute method of DispatchAction. If you override the execute method in your class, you override that logic, thereby disabling the ability to dispatch to another method.

In most cases when extending DispatchAction, you don't want to override the execute method, but merely write your own methods. If you do override execute, you must call super.execute(...) from that method.
 
Mandar Velankar
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Merrill,

I got the reason , because I overrided execute method.I also find the same

thing while experimenting but doesn't know reason , now i got it.

Thanks again.

Regards

Mandar Velankar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic