I have a table displayed using struts:iterator tag. The table value are contained in ArrayList
. I have one edit button on each of the rows of the list. When the user clicks an edit button the contents of that row should be sent to the action and the corresponding result page. I am not allowed to use checkbox and radio button.
Is there some param
tag I can use set that row as a parameter and get it back in the result page. Or is there a way to set that row in session and get it back from the session? How do I achieve this in Struts2?
You shouldn't set a whole row as a parameter, all you need is to set a parameter id
of the row. Then you can retrieve the record again when you need to save it. To set the parameter you can use the link like this
<s:a action="edit" value="Edit"><s:param name="id" value="%{#row[ID]}"/></s:a>
Using the following code you can set the values of each row into bean for example when you click on delete link we can use <s:bean/>
instantiates an object of the bean class and <s:param/>
can be used to set the values into the bean
<s:iterator value="contactList" var="contactBean">
<s:url id="deleteUrl" action="deleteLink">
<s:bean name="net.viralpatel.contact.model.Contact"></s:bean>
<s:param name="id" value="#contactBean.id"></s:param>
<s:param name="firstName" value="#contactBean.firstName"></s:param>
</s:url>
<s:a href="%{deleteUrl}">
Delete
</s:a>
</s:iterator>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With