Passing value from Struts tag in JSP to Action class

Discussion in 'Java' started by Oleg Konovalov, Aug 11, 2007.

  1. 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.
    Oleg Konovalov, Aug 11, 2007
    #1
    1. Advertising

  2. Oleg Konovalov wrote:

    > 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".

    --
    Regards,

    Richard
    Richard Senior, Aug 14, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Bloggs
    Replies:
    1
    Views:
    719
    Sudsy
    Aug 3, 2003
  2. rjweytens
    Replies:
    6
    Views:
    16,047
    rjweytens
    Jun 25, 2004
  3. shruds
    Replies:
    1
    Views:
    746
    John C. Bollinger
    Jan 27, 2006
  4. Replies:
    0
    Views:
    584
  5. Mongoose
    Replies:
    0
    Views:
    1,519
    Mongoose
    Oct 15, 2009
Loading...

Share This Page