一尘不染

使用 在多个列上填充动态数组列表

jsp

我试图在多个表列上填充一个ArrayList,这最初是使用旧页面上的Scriptlets来完成的,但是我知道这种做法现在不受欢迎了。我在使用struts标签进行翻译时遇到了麻烦。

我希望桌子能像这样结束

 Checkbox 1 Name 1   Checkbox 2 Name 2
 Checkbox 3 Name 3   Checkbox 4 Name 4
 etc....

这是原始的脚本代码:

<% for (int j=0; j < getDocumentList().length; j++) {
     setPacket(j);
     setStringIndex(Integer.toString(j));
%>
<tr>
    <td><input type="checkbox" name="displayTag<%= getStringIndex() %>"/></td>
    <td class="labelText"><%= getFormName() %></td>
    <%
        j++;
        if (j < getDocumentList().length) {
            setPacket(j);
            setStringIndex(Integer.toString(j));
    %>
    <td><input type="checkbox" name="displayTag<%= getStringIndex() %>"/></td>
    <td class="labelText"><%= getFormName() %></td>
    <%  } %>
</tr>
<% } %>

编辑:这是最终形式的代码!

<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr>
        <td class="maintain_test_info_table_subholder width5per"><fmt:message key="column.select"/></td>
        <td class="maintain_test_info_table_subholder width40per"><fmt:message key="column.docname"/></td>
        <td class="maintain_test_info_table_subholder width5per"><fmt:message key="column.select"/></td>
        <td class="maintain_test_info_table_subholder width40per"><fmt:message key="column.docname"/></td>
    </tr>
    <s:iterator value="documentsList" var="documentList" status="status">
        <s:if test="#status.index == 0">
            <s:set var="docIndex" value="%{#status.index}" />
        </s:if>
        <s:else>
            <s:set var="docIndex" value="%{#docIndex+1}" />
        </s:else>
        <c:set var="rowClass" value="row_even"/>
        <s:if test="#status.odd == true">
            <c:set var="rowClass" value="row_odd"/>
        </s:if>
        <s:if test="%{#documentListSize > #docIndex}">    
            <tr class="${rowClass}">
                <s:hidden name="%{'documentsList['+#docIndex+'].documentId'}" />            
                <s:hidden name="%{'documentsList['+#docIndex+'].documentName'}" />
                <s:hidden name="%{'documentsList['+#docIndex+'].documentSelected'}" />
                <td class="tablecell_middle width5per" >
                    <input type='checkbox' id='displayTag_${docIndex}' value="${documentsList[docIndex].documentSelected}"/>
                </td>
                <td class="tablecell_middle width40per" id='documentName_${docIndex}'>
                    <c:out value="${documentsList[docIndex].documentName}"/>
                </td>
                <s:set var="docIndex" value="%{#docIndex+1}" />
                <s:if test="%{#documentListSize > #docIndex}">
                    <s:hidden name="%{'documentsList['+#docIndex+'].documentId'}" />            
                    <s:hidden name="%{'documentsList['+#docIndex+'].documentName'}" />
                    <s:hidden name="%{'documentsList['+#docIndex+'].documentSelected'}" />
                    <td class="tablecell_middle width5per" >
                        <input type='checkbox' id='displayTag_${docIndex}' value="${documentsList[docIndex].documentSelected}"/>
                    </td>
                    <td class="tablecell_middle width40per" id='documentName_${docIndex}'>
                        <c:out value="${documentsList[docIndex].documentName}"/>
                    </td>
                </s:if>  
            </tr>
        </s:if>
    </s:iterator>
</table>

阅读 210

收藏
2020-06-08

共1个答案

一尘不染

您需要像这样设置索引的ovn变量

<s:set var="stringIndex" value="%{#status.index++}"/>
2020-06-08