Basic Struts question

R

RamRod

Assuming I have the following lines in a JSP

<td>
<html:submit property="AProperty" value="AValue"/>
<html:submit property="BProperty" value="BValue"/>
</td>

I now wish to discern, in my one Action class, whether the button
associated with AValue or the Button associated with BValue was
pressed. How is this accomplished?

I assumed that one of the 4 elements passed to the Action class would
reveal this value - most likely the -form- object or the -mapping-
object - this does not appear to be the case ...

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)

Any ideas ?

Thanks.
 
A

Andreas Wollschlaeger

RamRod said:
Assuming I have the following lines in a JSP

<td>
<html:submit property="AProperty" value="AValue"/>
<html:submit property="BProperty" value="BValue"/>
</td>

I now wish to discern, in my one Action class, whether the button
associated with AValue or the Button associated with BValue was
pressed. How is this accomplished?

I assumed that one of the 4 elements passed to the Action class would
reveal this value - most likely the -form- object or the -mapping-
object - this does not appear to be the case ...

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)

Any ideas ?

Thanks.

The forms AProperty resp. BProperty value should be set to "AValue"
resp. "BValue".

I used several <html:submit>'s referring the _same_ property and then
something like this in execute();

if("AValue".equals(getAProperty())
{

}
else if ("BValue".equals(getAProperty())
{

}
....



HTH
Andreas
 
M

Matt Parker

Andreas said:
The forms AProperty resp. BProperty value should be set to "AValue"
resp. "BValue".

I used several <html:submit>'s referring the _same_ property and then
something like this in execute();

if("AValue".equals(getAProperty())
{

}
else if ("BValue".equals(getAProperty())
{

}
...

Really you should give the button a name attribute for this because the
value of the button will change with internationalization:-

<html:submit name="AButton" property="AProperty" value="AValue"/>
<html:submit name="BButton" property="BProperty" value="BValue"/>

The name will appear as a request parameter so:-

if (request.getParameter("AButton") != null)
{
System.out.println("AButton pressed");
}
else if (request.getParameter("BButton") != null)
{
System.out.println("BButton pressed");
}

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top