java - JSP and JSTL conditionally render rows in table based on rule -
i have following in jsp page
<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>
a normal user allowed enter 10 rows clicking add user button, administrator enter number of rows table.
rows added administrator can viewed administrators , other rows added normal user, normal user cannot view rows added administrators.
how can conditionally render rows in jsp based on above mentioned rule?
thanks
you can use <c:if>
tag conditionally display data. this:
<c:foreach items="${users}" var="user"> <c:if test="${user.role != 'admin'}"> <!-- code here --> </c:if> </c:foreeach>
also believe need conditionally disable add user link if number of users added 10 , user current user not admin.
Comments
Post a Comment