Who knows HTML forms and JSPs/Struts

Gooberlx2

Lifer
May 4, 2001
15,381
6
91
Here's my problem:

I must have two submit buttons in a jsp that map to two different action classes. However, both buttons must have access to the same data (i.e. a selected radio button) in a HTML form. As far as I know buttons in two different HTML forms do not see each other's "data". Thus I would assume I need to put both buttons in the same HTML form.

Since actions are defined at the HTML form level (i.e. <form action="/myAction"> ) and not the button level, can I check which button was pressed inside the perform() (or execute() or whatever) of my Action run (i.e. via the session or request or something)?

Any ideas or other work arounds?

Note1: I am a student working on a class-wide project, with our prof as the main project manager. Thus I have no priviledges to change any kinds of configs. (i.e. If Actions could be mapped to buttons)

Note2: We are NOT allowed to use javascript.
 

Argo

Lifer
Apr 8, 2000
10,045
0
0
Hmm, javascript would be my choice number 1. Since you're not allowed to use it, I'd try the following. Have two submit buttons in your form, name the first one s1 and the second one s2. I believe the "action" class could check the values of s1 and s2 parameters to see whichever one was pressed. Then perform the necessary action.
 

Gooberlx2

Lifer
May 4, 2001
15,381
6
91
Yeah I was thinking that could be a solution.....but I can't find any info on how to get that info out in the Action.perform(). My best guess is it's in either the session or the request which are passed to the Action.perform(). Hmm. :-/ Otherwise It could be the Form that's passed, but then I don't know how to set that info. Arrgh!
 

manly

Lifer
Jan 25, 2000
12,616
3,406
136
Submit buttons can be named.

Submit images are always named.

That's how you differentiate which submit is triggered in a form.
 

Gooberlx2

Lifer
May 4, 2001
15,381
6
91
Very cool! you're right, the struts html taglibs defines that there's "property" and "value" attributes for submit buttons. Thus if I set the property="button" (and have getters and setters for a "button" String field variable in my java Form) the "pressed" button will be stored to the java Form.

However this'll require slight changes to our struts-config.xml where our actions won't always be forwarding "success" (where they were before). So I don't know if my prof'll approve...but I've emailed him the possible solution because atleast it's worth a shot.
 

Gooberlx2

Lifer
May 4, 2001
15,381
6
91
I had another thought. Anyone know if struts simply save all form item regardless of which submit button in which html form is pressed? 'Cause if that's the case then all I need to do is make a separate html form with merely the one button mapped to a different Action.