java - Multiple Instances of <C:if / Choose /When> condition to be made as one -
1: have jsp multiple html "tr's"
<tr>'s
my page
<% ...%> <html> ... <body> <table> <tr class="1"> first line</tr> <br/> <tr class="2"> second line</tr> <br/> <tr class="3"> third line</tr> <br/> <tr class="4"> fourth line</tr> <br/> <tr class="5"> fifth line</tr> <br/> ... </html>
2: getting user session (if logged in). note>>:using liferay themedisplay here
<%string useremail=themedisplay.getuser().getemailaddress();%> <c:set var="useremail" value="<%=useremail%>"></c:set>
3: made check see if guest or registered/logged in user.
then display changes first , last "tr's" logged-in user.
<% ...%> <html> ... <body> <table> <c:if test="${not empty useremail}"> <tr class="1"> first line registered user</tr> <c:if test="${empty useremail}"> <tr class="1"> first line</tr> <br/> <tr class="2"> second line</tr> <br/> <tr class="3"> third line</tr> <br/> <tr class="4"> fourth line</tr> <br/> <c:if test="${not empty useremail}"> <tr class="5"> fifth line registered user</tr> <c:if test="${empty useremail}"> <tr class="5"> fifth line</tr> <br/> ... </html>
this working fine!!
my question>>>>>if want make check constant of sort, not repeated many times on jsp/html page. done ???
<c:if> //to declared once. , called ever <tr> needs check??
a few alternatives:
- use
c:set
set registered variable on page, usec:choose
.
<c:set var="registered" value="${not empty useremail}"/> <c:choose> <c:when test="${registered}"> <tr class="1"> first line registered user</tr> </c:when> <c:otherwise> <tr class="1"> first line</tr> </c:otherwise> </c:choose>
- write first , last lines blank table rows, use
c:choose
run javascript insert data want.
<table> <tr id="firstrow"></tr> ... <tr id="lastrow"></tr> </table> <c:choose> <c:when test="${not empty useremail}"> <script> document.getelementbyid('firstrow').innerhtml = 'this first line registered user'; document.getelementbyid('lastrow').innerhtml = 'this fifth line registered user'; </script> </c:when> <c:otherwise> <script> document.getelementbyid('firstrow').innerhtml = 'this first line'; document.getelementbyid('lastrow').innerhtml = 'this fifth line'; </script> </c:otherwise> </c:choose>
Comments
Post a Comment