0

リストを反復して行を表示する私のコード

<c:if test="${not empty ftp}">
    <c:forEach var="event" items="${ftp}">
                <tr><td><input type="text" name="hostName" id="hostName" value="${event.hostName}"size="30" maxlength="200"/></td>
                <td><input type="text" name="directory" id="directory" value="${event.directory}" size="30" maxlength="200"/></td>
                <td><input type="text" name="userName" id="userName" value="${event.userName}" size="20" maxlength="20"/></td>
                <td><input type="text" name="password" id="password" value="${event.password}" size="20" maxlength="20" onblur="checkEnableButton();"/></td>
                <td><input type="button" id="delete" onclick="if(confirm( 'Do you want to delete')) deleteRow(this);" value="-" /></td></tr>
            </c:forEach>
</c:if>

これはうまくいきます..しかし、私のリストが空の場合、空白行を表示する必要があります..? JSPページから行を動的に削除および追加したい場合はどうすればよいですか..?

4

1 に答える 1

0

ループも同じチェックを行い、実際に空の場合は処理をスキップするため、現在使用している を<c:if test="${not empty ftp}">...</c:if>削除できます。forEach

空の場合に行を表示するには、次のようにします。

<c:if test="${empty ftp}">
    ...display empty table row here...
</c:if>

動的に処理したい場合は、JavaScript を開発する必要があります。JSTL はサーバー上で実行されますが、JavaScript を使用すると動的なクライアント側の処理を実行できます。

于 2012-09-05T16:43:14.997 に答える