1

JSPページに次のものがあります

 <table border=1>
        <thead>
            <tr>
                <th>User Id</th>
                <th>First Name</th>                
                <th>DOB</th>                
                <th colspan=2>Action</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${users}" var="user">
                <tr>
                    <td><c:out value="${user.userid}" /></td>
                    <td><c:out value="${user.firstName}" /></td>                    
                    <td><fmt:formatDate pattern="dd-MMM-yy" value="${user.dob}" /></td>                    
                    <td><a href="UserController?action=edit&userId=<c:out value="${user.userid}"/>">Update</a></td>
                    <td><a href="UserController?action=delete&userId=<c:out value="${user.userid}"/>">Delete</a></td>
                </tr>
            </c:forEach>
        </tbody>
    </table>
<p><a href="UserController?action=insert">Add User</a></p>

通常のユーザーは、[ユーザーの追加]ボタンをクリックして10行しか入力できません。管理者は、テーブルに任意の数の行を入力できます。

管理者が追加した行は、管理者と通常のユーザーが追加した他のすべての行のみが表示できますが、通常のユーザーは管理者が追加した行を表示できません。

上記のルールに基づいてJSPで行を条件付きでレンダリングするにはどうすればよいですか?

ありがとう

4

1 に答える 1

3

タグを使用して、<c:if>条件付きでデータを表示できます。このようなもの:

<c:forEach items="${users}" var="user">
    <c:if test="${user.role != 'admin'}">
        <!-- code here -->
    </c:if>
</c:forEeach>

また、すでに追加されているユーザーの数が10で、ユーザーの現在のユーザーが管理者でない場合は、条件付きで[ユーザーの追加]リンクを無効にする必要があると思います。

于 2013-03-26T05:59:29.240 に答える