Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send data selected in a table into action in Struts2 without using checkbox or radiobutton?

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?

like image 396
minusSeven Avatar asked Oct 21 '22 18:10

minusSeven


2 Answers

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>   
like image 51
Roman C Avatar answered Nov 01 '22 15:11

Roman C


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>
like image 27
user2077648 Avatar answered Nov 01 '22 14:11

user2077648