I am using display tag to display data in a table on a JSP (using struts 2). Now I want to give two links for each row, one for editing & one for deleting the row.
My jsp structure and what I am currently trying is :
<s:url id="editReport" action="editReport" />
<sd:div href="%{editReport}" listenTopics="editReport" formId="actionForm" showLoadingText="false" preload="false">
<s:url id="updLists" action="updLists" />
<sd:div href="%{updLists}" listenTopics="updLists" formId="enterDayReport" showLoadingText="false" preload="false">
<s:form id="enterDayReport" action="enterDayReport">
<sd:autocompleter label="Customer " name="customer" list="customerList" valueNotifyTopics="updLists" autoComplete="false" searchType="substring"/>
<sd:autocompleter label="Contact " name="contact" list="contactList" valueNotifyTopics="updLists" autoComplete="false" searchType="substring"/>
<s:select label="Stage " name="stage" list="stageList" headerKey="0" headerValue="Select" />
<s:select label="Type " name="type" list="typeList" headerKey="0" headerValue="Select" />
<sd:datetimepicker label="Date" name="date" formatLength="small" displayFormat="dd - MMM - yyyy"/>
<s:textarea label="Summary" name="summary" cols="40" rows="10"/>
<s:submit value="Save Report"/>
</s:form>
</sd:div>
</sd:div>
<s:url id="deleteReport" action="deleteReport" />
<sd:div href="%{deleteReport}" listenTopics="deleteReport" formId="actionForm" showLoadingText="false" preload="false">
<disp:table name="dayReportsList" export="true" class="dataTable">
<disp:column property="contactCode" title="Contact"/>
<disp:column property="customerCode" title="Customer"/>
<disp:column property="stage" title="Stage"/>
<disp:column property="type" title="Type"/>
<disp:column property="summary" title="Summary"/>
<disp:column property="reportDate" title="Date" format="{0,date,dd-MMM-yyyy}" />
<disp:column property="rowId" href="%{editReport}" paramId="rowID" paramProperty="rowId" title="Action">
<s:form id="actionForm" name="actionForm">
<s:hidden id="rowId" name="rowId" value="%{rowId}"/> // This is not getting populated.
<s:a onclick="dojo.event.topic.publish('editReport')">Edit<s:property value="rowId"/></s:a><br>
<s:a onclick="dojo.event.topic.publish('deleteReport')">Delete</s:a>
</s:form>
</disp:column>
</disp:table>
</sd:div>
The problem I am facing here is that, the name
of the form associated with every row in the display tag is same. So when I try to access the rowId
variable in my action class, I get the value of the first row's rowId only, no matter the button of which row is clicked.
I have seen some examples on stack overflow and google which use URL rewriting, but I don't want to use that.
Please advise.
Thanks!!