Quantcast

Trouble with DispatchAction

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Trouble with DispatchAction

zuban
Hi,

at first my code.

my DispatchAction-Class:
public class ExampleAction extends DispatchAction {

        public ActionForward delete(ActionMapping mapping, ActionForm form,
                        HttpServletRequest request, HttpServletResponse response) throws Exception {
                System.out.println("******* delete");
                return mapping.findForward("continue");
        }
       
        public ActionForward add(ActionMapping mapping, ActionForm form,
                        HttpServletRequest request, HttpServletResponse response) throws Exception {
               
                System.out.println("******* add");
               
        return mapping.findForward("continue");
        }
}

my jsp:
<html:html>
<head>
</head>
<body>       
        <html:form action="/ExampleSubmit">
                <html:submit onclick="this.form.method.value='delete'">
                </html:submit>
           
        </html:form>       
</body>
</html:html>

and the part of the struts-config.xml:
<action path="/ExampleShow"
                        type="org.apache.struts.actions.ForwardAction"
                        parameter="/jsp/Example.jsp"/>
               
                <action    path="/ExampleSubmit"
                type="ExampleAction"
                name="exampleForm"
                scope="request"
                input="/jsp/Example.jsp"
                parameter="method">

        <forward name="continue"    
                 path="/jsp/Example.jsp" redirect="true"/>
                </action>

When click of the button, I get this error:
----------------------------------------------------------------------------------------------------------------------------------------
javax.servlet.ServletException: javax.servlet.ServletException: Request[/ExampleSubmit] does not contain handler parameter named 'method'.  This may be caused by whitespace in the label text.
        org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
        org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
        org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

javax.servlet.ServletException: Request[/ExampleSubmit] does not contain handler parameter named 'method'.  This may be caused by whitespace in the label text.
        org.apache.struts.actions.DispatchAction.unspecified(DispatchAction.java:197)
        org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:245)
        org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
        org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
        org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
        org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
        org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
        org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
        org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
        org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
        org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
        org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
-----------------------------------------------------------------------------------------------------------------------------------

It is working if I type manualy ExampleSubmit.do?method=delete
(The delete-method in the action-class ist calling)


It is also working with this submit-button:
<html:submit property="method" value="delete"/>

But why doesn't work <html:submit onclick="this.form.method.value='delete'">
                </html:submit> ?


This should be the same like in this example:
http://struts.apache.org/1.x/struts-extras/dispatchValidator.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Trouble with DispatchAction

newton.dave
--- zuban <[hidden email]> wrote:
> <html:form action="/ExampleSubmit">
>   <html:submit
onclick="this.form.method.value='delete'"/>
> </html:form>
>
> Request[/ExampleSubmit] does not contain handler
> parameter named 'method'. This may be caused by
> whitespace in the label text.

It could also be caused by there not being a form
value for the parameter named 'method' at all.

d.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Trouble with DispatchAction

Laurie Harper
In reply to this post by zuban
zuban wrote:

> It is working if I type manualy ExampleSubmit.do?method=delete
> (The delete-method in the action-class ist calling)
>
> It is also working with this submit-button:
> <html:submit property="method" value="delete"/>
>
> But why doesn't work <html:submit onclick="this.form.method.value='delete'">
> </html:submit> ?
>
> This should be the same like in this example:
> http://struts.apache.org/1.x/struts-extras/dispatchValidator.html

I don't see anything like your code on that page. Setting the form's
method is not the same as passing a 'method' request parameter. What
you're doing is telling the browser to make an HTTP DELETE request
instead of a GET or POST. What are you trying to achieve by using the
onclick handler?

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Trouble with DispatchAction

zuban

Laurie Harper wrote
zuban wrote:
> It is working if I type manualy ExampleSubmit.do?method=delete
> (The delete-method in the action-class ist calling)
>
> It is also working with this submit-button:
> <html:submit property="method" value="delete"/>
>
> But why doesn't work <html:submit onclick="this.form.method.value='delete'">
> </html:submit> ?
>
> This should be the same like in this example:
> http://struts.apache.org/1.x/struts-extras/dispatchValidator.html

I don't see anything like your code on that page. Setting the form's
method is not the same as passing a 'method' request parameter. What
you're doing is telling the browser to make an HTTP DELETE request
instead of a GET or POST. What are you trying to achieve by using the
onclick handler?
I'd like to have a request-parameter named "method" and the value of "method" should be set in dependence of the submit-button (if more then one submit-buttons).
In other words the onclick-handler should set the request-paremter "method" to a special value.
i.e. if I click on a "add-button" "method" will have the value "add" and if I click on the "delete-button" "method" will have the value "delete".
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Trouble with DispatchAction

Michael Jouravlev
On 5/6/07, zuban <[hidden email]> wrote:

>
> Laurie Harper wrote:
> >
> > zuban wrote:
> >> It is working if I type manualy ExampleSubmit.do?method=delete
> >> (The delete-method in the action-class ist calling)
> >>
> >> It is also working with this submit-button:
> >> <html:submit property="method" value="delete"/>
> >>
> >> But why doesn't work <html:submit
> >> onclick="this.form.method.value='delete'">
> >>              </html:submit> ?
> >>
> >> This should be the same like in this example:
> >> http://struts.apache.org/1.x/struts-extras/dispatchValidator.html
> >
> > I don't see anything like your code on that page. Setting the form's
> > method is not the same as passing a 'method' request parameter. What
> > you're doing is telling the browser to make an HTTP DELETE request
> > instead of a GET or POST. What are you trying to achieve by using the
> > onclick handler?
> >
>
> I'd like to have a request-parameter named "method" and the value of
> "method" should be set in dependence of the submit-button (if more then one
> submit-buttons).
> In other words the onclick-handler should set the request-paremter "method"
> to a special value.
> i.e. if I click on a "add-button" "method" will have the value "add" and if

Simple ways don't work for you, eh? Why would not you just use plain old

<input type="submit" name="method" value="delete" />

Do you need to have different events for one button depending on some
other condition? if not, then the only other reason would be that you
want to have a fancier button caption instead of "delete". In this
case forget about DispatchAction. Better choices like
EventDispatchAction or EventActionDispatcher are available:
http://wiki.apache.org/struts/EventActionDispatcher

Michael.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Trouble with DispatchAction

zuban
Michael Jouravlev wrote
Simple ways don't work for you, eh? Why would not you just use plain old

<input type="submit" name="method" value="delete" />
No, because of using resource bundles to set the value of the buttons for different languages.

Michael Jouravlev wrote
Do you need to have different events for one button depending on some
other condition? if not, then the only other reason would be that you
want to have a fancier button caption instead of "delete". In this
case forget about DispatchAction. Better choices like
EventDispatchAction or EventActionDispatcher are available:
http://wiki.apache.org/struts/EventActionDispatcher

Michael.
That looks fine. I'll try it out. Thanks!
Loading...