2

以下は、私が試している大まかな反復です。

<c:forEach  items="${row.myList}" var="mainRow" varStatus="table">
        ${ table.first? '<table>':'<tr><td><strong>${mainRow.heading}</strong></td></tr>'}

            <c:forEach items="${mainRow.values}" var="value" >
             <tr>
                <td><input type="checkbox"  value="${value}"/>${value}</td>
              </tr>
            </c:forEach>
             ${ table.last? '</table>':''}
        </c:forEach>

問題は、属性値の代わりに${mainRow.heading}を出力することです。また、他にどのようなオプションがありますか。最初、最後のように。それに関するドキュメントはありますか?

4

2 に答える 2

1
${ table.first? '<table>':'<tr><td><strong>${mainRow.heading}</strong></td></tr>'}

EL式内の文字列リテラル内にEL式を埋め込んだため、上記の式は希望どおりではありません。あなたが欲しいのは

${table.first? '<table>' : '<tr><td><strong>' + mainRow.heading + '</strong></td></tr>'}

また

<c:choose>
    <c:when test="${table.first}">
        <table>
    </c:when>
    <c:otherwise>
        <tr><td><strong>${mainRow.heading}</strong></td></tr>
    </c:otherwise
</c:choose>

これはより長いですが、より読みやすいIMOです。

于 2013-03-07T12:17:24.603 に答える
1

コードスニペットで'<tr><td><strong>${mainRow.heading}</strong></td></tr>'は、JSPに関する限り、は単なる文字列であるため、置換はありません。代わりにこれを使用してください

${ table.first? '&lt;table&gt;':'<tr><td><strong>'.concat(mainRow.heading).concat('</strong></td></tr>') }

(一致しないタグを避けるために、htmlエンティティを使用する必要がありました。)

その他のvarStatusオプションはここに記載されています:http://docs.oracle.com/cd/E17802_01/products/products/jsp/jstl/1.1/docs/api/javax/servlet/jsp/jstl/core/LoopTagStatus.html

于 2013-03-07T12:20:22.963 に答える