You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Lachlan Holmes <la...@hotmail.com> on 2001/12/13 01:25:48 UTC

multiple buttons on a form

Is there a way to have multiple submit buttons on a form and be able to tell which button was pressed in the following action?

Regards,
Lachlan

Re: multiple buttons on a form

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Yes.

The nightly builds contain a patch I submitted, called LookupDispatchAction.
It keys off of the use of ApplicationResource messages for button labels and
allows reflection to call a different method for each button pressed.  The
Javadocs explain it in great detail.

Even without that base class action, you'll get the button label as a
request.getParameter("action") if all your buttons have the name "action".
But using the button label in an Action greatly munges the View with the
Controller and makes things fragile (Java shouldn't break if a button label
is changed in the JSP).

    Erik


----- Original Message -----
From: "Lachlan Holmes" <la...@hotmail.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, December 12, 2001 7:25 PM
Subject: multiple buttons on a form


Is there a way to have multiple submit buttons on a form and be able to tell
which button was pressed in the following action?

Regards,
Lachlan



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: multiple buttons on a form

Posted by Keith Bacon <ke...@yahoo.com>.
Lachlan, I hope this helps - a bit long I know.
============
Below is what I have used. It shows multiple buttons &
how to have data associated with the buttons. I hope
this can be understood! I've seen other similar
examples in archive butnot with the passing of data
with the button, th way i do it may be a bit flakey.
Keith.

===============
Code for jsp - Redisplay Button & Maint Button that
passed key value to form bean. property= gives names
of properties in form bean
If user presses maintButton struts calls
setMaintButton(key) on the form bean.
-----
<html:submit property="redisplayButton">
	<bean:message
key="Biff1LinkList.jsp.literal.redisplayButton"/>
</html:submit>

<% String key = listItem.getLinkIDAsString(); %>
<html:submit property="maintButton" value="<%= key
%>">
   <bean:message
key="Biff1LinkList.jsp.literal.redisplayButton"/>
</html:submit>

=====================
In Form bean
-----
	boolean redisplayButton;
	boolean maintButton;
	String  maintButtonData;
	/**
	* RedisplayButton - ActionServlet calls this if it
was pressed
	*/
	public void setRedisplayButton(String sss) {
			//dbmd("setRedisplayButton: value passed="+ sss);
		redisplayButton = true;
	}
	/**
	* Action class uses this to see if this button was
pressed
	*/
	public boolean isRedisplayButton() {
		return redisplayButton;
	}
	/**
	* maintButton - ActionServlet calls this if it was
pressed
	* Val. passed in is from value= parm on <html:submit
tag.
	*/
	public void setMaintButton(String sss) {
		maintButton = true;
		maintButtonData = sss;
	}
	/**
	* action class uses this to see if this button was
pressed
	*/
	public boolean isMaintButton() {
		return maintButton;
	}
	/**
	* action class uses this to get the key
	* if this maintButton was pressed
	*/
	public String getMaintButtonData() {
		return maintButtonData;
	}

======================
In Action class
-----
	if (myForm.isRedisplayButton()) {
		//
		// redisplay page (use change selection/sort parms)
		//
	} else if (thisForm.isMaintButton()) {
		//
		// get the key value (from value= parm
		// of the <html:submit tag.
		//
		String selectedLinkID = myForm.getMaintButtonData();

-------------
end of keiths example 
=======================================
--- Nathan Anderson <na...@sum-ware.com> wrote:
> I know that people have done this before, so I'm
> sure someone can help you
> out [or you can find an answer in the mail archive].
>  But I was thinking
> about this today, and I wondered what would happen
> if you create a "submit"
> property in your form bean, and then give each
> submit button a different
> value.
> 
> Someone must have tried that... what happens?
> 
> Nathan Anderson
> 
> -----Original Message-----
> From: Lachlan Holmes
> [mailto:lachlanholmes@hotmail.com]
> Sent: Wednesday, December 12, 2001 4:26 PM
> To: Struts Users Mailing List
> Subject: multiple buttons on a form
> 
> 
> Is there a way to have multiple submit buttons on a
> form and be able to tell
> which button was pressed in the following action?
> 
> Regards,
> Lachlan
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: multiple buttons on a form

Posted by Nathan Anderson <na...@sum-ware.com>.
I know that people have done this before, so I'm sure someone can help you
out [or you can find an answer in the mail archive].  But I was thinking
about this today, and I wondered what would happen if you create a "submit"
property in your form bean, and then give each submit button a different
value.

Someone must have tried that... what happens?

Nathan Anderson

-----Original Message-----
From: Lachlan Holmes [mailto:lachlanholmes@hotmail.com]
Sent: Wednesday, December 12, 2001 4:26 PM
To: Struts Users Mailing List
Subject: multiple buttons on a form


Is there a way to have multiple submit buttons on a form and be able to tell
which button was pressed in the following action?

Regards,
Lachlan


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: multiple buttons on a form

Posted by Phase Communcations <ma...@phase.ws>.
visit the strutsx.org and look at the image button patch.

-----Original Message-----
From: Lachlan Holmes [mailto:lachlanholmes@hotmail.com]
Sent: Wednesday, December 12, 2001 5:26 PM
To: Struts Users Mailing List
Subject: multiple buttons on a form


Is there a way to have multiple submit buttons on a form and be able to tell
which button was pressed in the following action?

Regards,
Lachlan


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>