开发者

Get value from a row in a JSP page using display tag

开发者 https://www.devze.com 2023-01-11 18:22 出处:网络
Sorry for a bunch of Struts2 / JSP questions, but I have a table generated with Display tag: <display:table 开发者_运维知识库name=\"table\" pagesize=\"10\" id=\"row\" requestURI=\"\">

Sorry for a bunch of Struts2 / JSP questions, but I have a table generated with Display tag:

<display:table 开发者_运维知识库name="table" pagesize="10" id="row" requestURI="">
<display:column title="Action">
    <s:form theme="simple">
        <s:submit action="remove" value="Remove" 
        onclick="return confirm('Are you sure you want to delete this item?');"/>
        <s:submit action="displayEdit" value="Edit"/>
    </s:form>
</display:column>
<display:column property="cpc" title="CPC"/>
<display:column property="companyName" title="Company Name"/>
<display:column property="eventType" title="Event Type"/>
<display:column property="industryType" title="Industry Type"/>
<display:column property="previousEvents" />
<display:column property="creditNotifications" />
<display:column property="interimNotifyEnterprise" />
</display:table>

Now I want to be able to delete or edit a certain row (I already have the actions written out), but how would I get the specific data for each row so I can tell my Action class which row to edit or delete?


I mentioned this in the previous question you asked the other day. You just need to something in your row, possibly a hidden field, that can be used to uniquely identify the item.

I suggested using an <s:hidden key="rowID" /> in the row, which would get submitted with the action. As long as you had a property like that on your object, and in the remove action, you had a setter to receive that value, you could use that to uniquely identify the row.


It seems that your table does not have unique identifier field in class Object per Row. You can add field -id in you bean-class that you are going to display. (companyId in Company bean class). So that every row in the table will display unique 'company' object and depending upon 'companyId' field you may edit/delete selected object by passing 'companyId' to Action class.

You may no like to display 'companyId' column in your UI layout to end-user. In that case you can just create hyperlink of 'edit' and 'delete' column using 'companyId' as parameter.

See displaytag tutorial at this site for more detail.


use below to get row id. eg i used radio button,

<display:column  property="radioButton" title="ID">
                  <input type="radio" value='<%=data_rowNum.intValue()-1%>' name='rowNr' onClick="fnEnableControls()"/>
</display:column>

now u can easily get the value of rowNr using req.getParameter and based on this u can get the record from the list which u have supplied to display tag table.

0

精彩评论

暂无评论...
验证码 换一张
取 消