JSTL presentation problem- if statement
I need to represent the columns based on the value of the fetched from an arraylist.
<c:forEach items="${row}" var="cell">
<c:if test="${(cell != 'Read') || (cell !='Write')}" >
<td id="access">${cell}</td>
</c:if>
<c:if test="${(cell == 'Read') || (cell =='Write')}" >
<td>${cell}</开发者_如何转开发td>
</c:if>
</c:forEach>
I have 3 types of value coming in cell- Read, Write and Others. For Others it is going into != condition, but for Read and Write, it satisfy both the if statements. I was not able to use if-else. Thanks in advance
Here is the equivalent if-else statement of your code if the second IF in your code as the ELSE.
<c:forEach items="${row}" var="cell">
<c:choose>
<c:when test="${cell ne 'Read' or cell ne 'Write'}">
<td id="access">${cell}</td>
</c:when>
<c:otherwise>
<td>${cell}</td>
</c:otherwise>
</c:choose>
</c:forEach>
Check your conditional statement in IF. As voidnnull point out about your first IF instead of using || (or) use && (and).
That is because you are using the ||
operator in the first test condition.
Use the && operator and it will work as expected.
<c:if test="${(cell != 'Read') && (cell !='Write')}" >
Additionally for a if-else construct using JSTL, use <c:choose>
tag under which you can use <c:when>
and <c:otherwise>
. They work in a similar manner to if-else.
Example: http://www.exampledepot.com/egs/javax.servlet.jsp.jstl.core/if.html
精彩评论