使用 <s:iterator>在多列上填充动态数组列表 [英] Using &lt;s:iterator&gt; to populate a dynamic arraylist over multiple columns

查看:19
本文介绍了使用 <s:iterator>在多列上填充动态数组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在多个表列上填充 ArrayList,这最初是在我们的旧页面上使用 Scriptlets 完成的,但我知道现在这种做法不受欢迎.而且我在使用 struts 标签翻译它时遇到了麻烦.

I am trying to populate an ArrayList over multiple table columns, this was originally done using Scriptlets on our old page but I know that the practice is frowned upon now. And I am having trouble translating it over using struts tags.

我希望桌子最终变成这样,

I want the table to end up like this,

 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>

推荐答案

你需要像这样为索引设置 ovn 变量

You need to set your ovn variable for the index like this

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

这篇关于使用 <s:iterator>在多列上填充动态数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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