Multiple button support
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Erik_Hatcher
Posted On:   Wednesday, November 7, 2001 07:34 PM

How should multiple button support be handled in Struts? Each button gets submitted with different text, but in order to separate the view from the controller that text should not appear in the Action. I'm curious how others have dealt with this situation.

Re: Multiple button support

Posted By:   Ted_Husted  
Posted On:   Friday, November 9, 2001 08:47 AM

Without Javascript, I don't think there is another solution,
since that is all the information that HTTP provides.


With Javascript, you can have the button set a hidden
property on the form, and then key on that.


This example uses the property "forward", which could also be a
property on the ActionForm.






UPDATE

COPY

CANCEL





function set(target) {
document.forms[0].forward.value=target;
};



A good trick here is to use a generic "routing" or "relay" action,
so you don't have to hardcode some type of switch into the Action.
It's just one line in the perform method:




return mapping.findForward(request.getParameter("forward"));



This can be used any number of times in a Struts application, just
by changing the form bean and the local forwards in its mapping.



path="/prospect/Submit"
type="org.apache.scaffold.http.RelayAction"
name="prospectForm"
scope="request"
validate="false">
name="update"
path="/do/prospect/Store"/>
name="cancel"
path="/do/prospect/Current"/>



HTH - Ted

About | Sitemap | Contact