JSTL在循环中每隔5个字段集创建一个新行

时间:2012-02-28 16:41:04

标签: html jsp jstl

您好我正在迭代并在表格中显示字段集列表。为了试图使布局有点像样。我想在每次循环到第5个fieldSet时创建一个新行。感谢

JSP:

<div class="det" id="displayFields">
    <table class="det">
        <tr>
            <td>
                <c:forEach items="${detFieldMap}" var="detFieldEntry">     
                    <fieldset class="det">         
                        <legend>${detFieldEntry.key}</legend>  
                        <c:forEach items="${detFieldEntry.value}" var="detBean">    
                            <input type="checkbox" name="fieldNames" value="${detBean.fieldName}" <c:if test="${preselectionMap[detBean.fieldName]}">checked="checked"</c:if>>${detBean.displayName}</input>          
                            </br>    
                        </c:forEach> 
                    </fieldset> 
                </c:forEach>
            </td>
        </tr>
    </table>
</div>

1 个答案:

答案 0 :(得分:3)

这有效:

<div class="det" id="displayFields">
    <table class="det">
        <tr>
            <td>
                <c:forEach items="${detFieldMap}" var="detFieldEntry" varStatus="loop">
                    <c:if test="${not loop.first and loop.index % 5 == 0}"> 
                        </td>
                            </tr>
                        <tr>
                            <td>
                    </c:if>
                    <fieldset class="det">         
                        <legend>${detFieldEntry.key}</legend>  
                        <c:forEach items="${detFieldEntry.value}" var="detBean">    
                            <input type="checkbox" name="fieldNames" value="${detBean.fieldName}" <c:if test="${preselectionMap[detBean.fieldName]}">checked="checked"</c:if>>${detBean.displayName}</input>            
                            </br>    
                        </c:forEach> 
                    </fieldset>
                </c:forEach>
            </td>
        </tr>
    </table>
</div>