Passing value from Struts tag in JSP to Action class

O

Oleg Konovalov

Hi,

I am populating JSP page with rows retrieved from the database and
represented as a List of Beans in forEach loop:
<c:forEach var="list" items="${OperationsForm.OperationsList}">
...
<c:choose>
<c:when test="${list.isCompleted =='Y'}" >
<td width="100">Completed</td>
<td width="100">&nbsp;</td>
</c:when>
<c:eek:therwise>
<td width="100">Pending</td>
<td width="100"><input type="image" onclick="
rowId=value; form.action='action.do?command=notify'"
value="${list.OperationId}" />
</td>
</c:eek:therwise>
</c:choose>
</tr>
</c:forEach>
Have hidden field: html:hidden property="rowId" value="-1"/>

User is clicking the button corresponding to one of the rows
and I need to pass the value of that rowId to the Action class, so it does
something in the database [action completed]
Now how do I pass it , is that the right way of doing it with calling
request.getSession().getAttribute(rowId) in the Action class ?
As of now I am getting Javascript error "Object doesn't support this
property or method", complaining about rowId=value;

Using Struts 1.3

Please help !

TIA,
Oleg.
 
R

Richard Senior

Oleg said:
User is clicking the button corresponding to one of the rows
and I need to pass the value of that rowId to the Action class, so it does
something in the database [action completed]
Now how do I pass it , is that the right way of doing it with calling
request.getSession().getAttribute(rowId) in the Action class ?
As of now I am getting Javascript error "Object doesn't support this
property or method", complaining about rowId=value;

You don't need JavaScript. Use the Struts <html:button> tag:

<html:form action="myActionInStrutsConfig">

...

<c:forEach var="item" items="${OperationsForm.OperationsList}">

<html:button property="x" value="${item.OperationId}" />

</c:forEach>

</html:form>

When the button is pressed, the form is submitted and you get a request
parameter "x" available to your Action set to the operation id value
that's on the button. Obviously you'll have a better name for "x".
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top