小编典典

使用Displaytag时从Struts2表中的行中检索值

jsp

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

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

<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源代码时,在隐藏字段中看到了这一点:

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

出于某种原因,找不到任何值…在使用Displaytag之前,它运行良好,并且在Action类中确实有一个getter和setter方法(现在它返回一个空String)。

编辑:这是前两行的HTML代码:

<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>

阅读 245

收藏
2020-06-10

共1个答案

小编典典

我想我已经结束了使用按钮的过程,但是如果有人好奇,这就是我最终使用的按钮:

<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>
2020-06-10