From: Tom McCobb [mailto:[EMAIL PROTECTED] In another section of the page I display an iterated list of items in a collection. I am stuck on how to get the value of "i", the index of the row
wherein the button was clicked.
Are you willing to use JSTL? The <c:forEach> tag has 'varStatus' which will give you the integer position as you loop through the collection. This won't be exactly right, I haven't worked with it for a while, but...
<c:forEach items="${myCollection}" var="myItem" varStatus="myLoopIndex">
<c:out value="${myLoopIndex}"/> <c:out value="${myItem}"/>
</c:forEach>
Are these links, or do you need to submit the form with the index as one of the form properties? Do you have any objection to JavaScript?
With Struts-EL and JSTL, I haven't needed to venture into the Nested taglib, although I understand there are things it can do that Struts-EL/JSTL cannot. This may be one of them...
Actually you can do everything with JSTL/EL that the nested tag does, but I must admit the nested tag makes things cleaner. In the above it doesn't matter much because you don't have Lists nested within each other.
Imagine a case, though, where you had a Company object that a Collection of divisions and then each division had a collection of departments and you want to display a form that lest you edit the departments in each division. You'll see the benefit of nested below (sorry for the ugly wrapping you'll get. If you want I can send the example to you offlist).
<%-- JSTL way --%>
<c:forEach items="${companyForm.divisions}" var="division" varStatus="divstatus">
Division: <html:text property="divisions[${divstatus.index}].name" value="${division.name}" /><br>
<c:forEach items="${division.departments}" var="department" varStatus="depstatus">
--- Department: <html:text property="divisions[${divstatus.index}].departments[${depstatus.index}].name" value="${department.name}" /><br>
</c:forEach>
</c:forEach>
<%-- Nested tag way Notice how much less to write out--%>
<nested:iterate property="divisions"> Division: <nested:text property="name" /><br> <nested:iterate property="departments"> --- Department: <nested:text property="name" /><br> </nested:iterate> </nested:iterate>
-- Rick
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]