Reputation: 159
What is problem in this code... I've tried a lot of solutions, but always error in the if loop ..
<script type="text/template" id="tableItemPageView">
<% if(%>${pageContext.request.userPrincipal.name } === <@= table.user @><%){ %>
<td><@= table.id @></td>
<td><@= table.name @></td>
<td><@= table.changed @></td>
<td><@= table.description @></td>
<td class="correctUser"><a href="#tables/edit/<@=table.id@>">Edit </a><a
href="#tables/show/<@=table.id@>"> Players</a><a id="removeTable"> Delete</a>
<% }else{ %>
<td><@= table.id @></td>
<td><@= table.name @></td>
<td><@= table.changed @></td>
<td><@= table.description @></td>
<% } %>
</script>
On this solution I have one error , after "if" have error "Syntax error on token "(", Expression expected after this token".
I want to check is it the registered user the same as the user who created the table...
Upvotes: 1
Views: 1058
Reputation: 46861
I suggest you to use JavaServer Pages Standard Tag Library or Expression Language instead of Scriplet
that is more easy to use and less error prone.
Use Implicit object that are available in JSP to access any attribute from any scope.
Use if
core tag library
<c:if test="${requestScope.userPrincipal.name == ’XYZ’}">
...
</c:if>
OR use when/otherwise
core tag library that is equivalent to JAVA switch statement
<c:choose>
<c:when test="${requestScope.userPrincipal.name == ’XYZ’}" >
...
</c:when>
<c:otherwise>
...
</c:otherwise>
</c:choose>
Upvotes: 2