使用Displaytag时从Struts2表中的行中检索值 [英] Retrieving Value from Row in Struts2 Table While using Displaytag

查看:73
本文介绍了使用Displaytag时从Struts2表中的行中检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这有点重新发布,但是我觉得重新发布我的问题会让事情变得更清楚.

I am aware that this is somewhat a re-post, but I feel like re-posting my question will make things more clear.

这是我的JSP页面中我的表的代码:

Here is the code for my table in my JSP page:

<display:table name="table" pagesize="25" requestURI="">
<display:column title="Action" >
    <s:form theme="simple">
        <s:hidden key="cpc" />
        <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" sortable="true" headerClass="sortable"/>
<display:column property="companyName" title="Company Name" sortable="true" headerClass="sortable"/>
<display:column property="eventType" title="Event Type" sortable="true" headerClass="sortable"/>
<display:column property="industryType" title="Industry Type" sortable="true" headerClass="sortable"/>
<display:column property="previousEvents" sortable="true" headerClass="sortable"/>
<display:column property="creditNotifications" sortable="true" headerClass="sortable"/>
<display:column property="interimNotifyEnterprise" sortable="true" headerClass="sortable"/>
</display:table>

该表的源是一个ArrayList,其中TableRow是所有各个字段的包装器类(我对所有字段都有getter和setter).现在,当我检查我的HTML源代码时,在隐藏字段中看到了这一点:

The source for the table is an ArrayList, where TableRow is a wrapper class of all the various fields (and I have getters and setters for all the fields). Now when I check my HTML source code, I see this for the hidden field:

<input type="hidden" name="cpc" value="" id="displayResults_cpc"/>

由于某种原因,找不到任何值...在我使用Displaytag之前,它工作正常,并且我的Action类中确实有一个吸气剂和吸气剂(现在它返回一个空字符串).

For some reason, there is no value to be found... It was working fine before I used Displaytag, and I do have a getter and setter in my Action class (right now it returns an empty String).

这是前两行的HTML代码:

This is the HTML code for the first two rows:

<tr class="odd">
<td>

<form id="displayResults" name="displayResults" onsubmit="return true;" action="/CompanyNameTableManager/displayResults.action;jsessionid=566617D98154AB762002B06D9D1087CD" method="post">
        <input type="hidden" name="cpc" value="" id="displayResults_cpc"/>
        <input type="submit" id="displayResults_remove" name="action:remove" value="Remove" onclick="return confirm('Are you sure you want to delete this item?');"/>

        <input type="submit" id="displayResults_displayEdit" name="action:displayEdit" value="Edit"/>

    </form>  
</td>
<td>10.1.1</td>
<td>Comapny A</td>
<td>abc</td>
<td>123</td>
<td>true</td>
<td>true</td>

<td>true</td></tr>
<tr class="even">
<td>

<form id="displayResults" name="displayResults" onsubmit="return true;" action="/CompanyNameTableManager/displayResults.action;jsessionid=566617D98154AB762002B06D9D1087CD" method="post">
        <input type="hidden" name="cpc" value="" id="displayResults_cpc"/>
        <input type="submit" id="displayResults_remove" name="action:remove" value="Remove" onclick="return confirm('Are you sure you want to delete this item?');"/>

        <input type="submit" id="displayResults_displayEdit" name="action:displayEdit" value="Edit"/>

    </form>
</td>
<td>10.1.2</td>
<td>Comapny B</td>
<td>abc</td>
<td>123</td>
<td>true</td>
<td>false</td>
<td>false</td></tr>

推荐答案

我想我已经避免了使用按钮,但是如果有人好奇的话,这就是我最终使用的按钮:

I guess I copped out from using buttons, but if anyone is curious, here is what I ended up using instead:

<s:form theme="simple" method="post">
<display:table name="table" pagesize="25" requestURI="" uid="row">
<display:column title="Select">
    <s:checkbox name="checked[%{#attr.row_rowNum - 1}]" fieldValue="%{#attr.row.cpc}" theme="simple"/>
</display:column>
<display:column property="cpc" title="CPC" sortable="true" headerClass="sortable"/>
<display:column property="companyName" title="Company Name" sortable="true" headerClass="sortable"/>
<display:column property="eventType" title="Event Type" sortable="true" headerClass="sortable"/>
<display:column property="industryType" title="Industry Type" sortable="true" headerClass="sortable"/>
<display:column property="previousEvents" sortable="true" headerClass="sortable"/>
<display:column property="creditNotifications" sortable="true" headerClass="sortable"/>
<display:column property="interimNotifyEnterprise" sortable="true" headerClass="sortable"/>
</display:table>
    <s:submit action="remove" value="Remove" 
    onclick="return confirm('Are you sure you want to delete this item / these items?');"/>
    <s:submit action="displayEdit" value="Edit"/>
    <s:submit value="Add New Row" action="displayAdd"/>
</s:form>

这篇关于使用Displaytag时从Struts2表中的行中检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆