You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by sjones <sj...@yahoo.com> on 2003/05/31 00:13:50 UTC

- How do you detect which button was clicked.

All,


I have a Jsp with two button in one form. The button click
determines what page the users sees next.

How do i detect which button was clicked.

i tryed to change the hidden field before submitting the form
but that is not working.

It is driving me nuts !!


I have :
<html:form action="/CreateTask.do" method="GET">
 <html:hidden property="dispatch" value="error"/>
 <h1><bean:message key="title"/></h1>
 <html:button property="button1" value="success1" onclick="submit()"/>
 <html:button property="button2" value="success2" onclick="submit()"/>
</html:form>

and in my Action.java :

 DynaActionForm dynaForm = (DynaActionForm)form;
 String strAction = (String)dynaForm.get("dispatch");
 System.out.println("strAction= " + strAction);





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


Re: - How do you detect which button was clicked.

Posted by sjones <sj...@yahoo.com>.
Thanks i will try this.

"Brandon Goodin" <ma...@phase.ws> wrote in message
news:MCEFJGLDHNNMPENCIDECKEFBFKAA.mail@phase.ws...
> Read the docs on DispatchAction/LookupDispatchAction. But, basically, give
> your buttons both the same name. Then whichever one is clicked will be the
> value. Then you can determine what needs to be done server side.
>
> Brandon Goodin
>
> -----Original Message-----
> From: news [mailto:news@main.gmane.org]On Behalf Of sjones
> Sent: Friday, May 30, 2003 4:14 PM
> To: struts-user@jakarta.apache.org
> Subject: <html:button> - How do you detect which button was clicked.
>
>
> All,
>
>
> I have a Jsp with two button in one form. The button click
> determines what page the users sees next.
>
> How do i detect which button was clicked.
>
> i tryed to change the hidden field before submitting the form
> but that is not working.
>
> It is driving me nuts !!
>
>
> I have :
> <html:form action="/CreateTask.do" method="GET">
>  <html:hidden property="dispatch" value="error"/>
>  <h1><bean:message key="title"/></h1>
>  <html:button property="button1" value="success1" onclick="submit()"/>
>  <html:button property="button2" value="success2" onclick="submit()"/>
> </html:form>
>
> and in my Action.java :
>
>  DynaActionForm dynaForm = (DynaActionForm)form;
>  String strAction = (String)dynaForm.get("dispatch");
>  System.out.println("strAction= " + strAction);
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org




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


RE: - How do you detect which button was clicked.

Posted by Brandon Goodin <ma...@phase.ws>.
The nature of the reset button is to reset the html form back to it's
original state. So, if you have a prepoluated form and use the reset it will
not submit. It will only change the values of the form back to it's default
state. If you want to make the form black as a result of a button click then
you will either have to set up a new button and make a request on the server
then pass back a blank, unpopulated form. If you want to use javascript you
will have to intercept the form submit and then set all of the form values
to blank within a javascript funtion. Personally, I would go the server
route and have the Action produce a blank form.

Brandon Goodin

-----Original Message-----
From: Mike Whittaker [mailto:mike_whittaker@ntlworld.com]
Sent: Friday, May 30, 2003 5:27 PM
To: Struts Users Mailing List
Subject: RE: <html:button> - How do you detect which button was clicked.


>
>Read the docs on DispatchAction/LookupDispatchAction. But, basically, give
>your buttons both the same name. Then whichever one is clicked will be the
>value. Then you can determine what needs to be done server side.
>
>Brandon Goodin
>

And should I use one of these if I want to reset a form, which has been
prepopulated, and the user wishes a blank form.  One button to submit, one
button for the raw jsp (reset)?

--
Mike W


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



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


RE: - How do you detect which button was clicked.

Posted by Mike Whittaker <mi...@ntlworld.com>.
>
>Read the docs on DispatchAction/LookupDispatchAction. But, basically, give
>your buttons both the same name. Then whichever one is clicked will be the
>value. Then you can determine what needs to be done server side.
>
>Brandon Goodin
>

And should I use one of these if I want to reset a form, which has been
prepopulated, and the user wishes a blank form.  One button to submit, one
button for the raw jsp (reset)?

--
Mike W


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


RE: - How do you detect which button was clicked.

Posted by Brandon Goodin <ma...@phase.ws>.
Read the docs on DispatchAction/LookupDispatchAction. But, basically, give
your buttons both the same name. Then whichever one is clicked will be the
value. Then you can determine what needs to be done server side.

Brandon Goodin

-----Original Message-----
From: news [mailto:news@main.gmane.org]On Behalf Of sjones
Sent: Friday, May 30, 2003 4:14 PM
To: struts-user@jakarta.apache.org
Subject: <html:button> - How do you detect which button was clicked.


All,


I have a Jsp with two button in one form. The button click
determines what page the users sees next.

How do i detect which button was clicked.

i tryed to change the hidden field before submitting the form
but that is not working.

It is driving me nuts !!


I have :
<html:form action="/CreateTask.do" method="GET">
 <html:hidden property="dispatch" value="error"/>
 <h1><bean:message key="title"/></h1>
 <html:button property="button1" value="success1" onclick="submit()"/>
 <html:button property="button2" value="success2" onclick="submit()"/>
</html:form>

and in my Action.java :

 DynaActionForm dynaForm = (DynaActionForm)form;
 String strAction = (String)dynaForm.get("dispatch");
 System.out.println("strAction= " + strAction);





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



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