tmonteit
asked on
<c:when> problem
I have a variable in a JSTL Page I need to send to a choose block. Problem is, I can't get any 'when' block to match. In all cases, the <c:otherwise> is printed.
form.type is a String.
What am I dong wrong?
For this example, form.type is set to the String "foo". So, "Showing FOO" should print.
------begin------------
type= <c:out value="${form.type}"/> <br>
<c:choose>
<c:when test="${form.type == 'foo'}">
Showing FOO
</c:when>
<c:when test="${form.type == 'bar'}">
Showing BAR
</c:when>
<c:otherwise>
Unknown Content
</c:otherwise>
</c:choose>
-------end-------------
form.type is a String.
What am I dong wrong?
For this example, form.type is set to the String "foo". So, "Showing FOO" should print.
------begin------------
type= <c:out value="${form.type}"/> <br>
<c:choose>
<c:when test="${form.type == 'foo'}">
Showing FOO
</c:when>
<c:when test="${form.type == 'bar'}">
Showing BAR
</c:when>
<c:otherwise>
Unknown Content
</c:otherwise>
</c:choose>
-------end-------------
ASKER
Yes , <c:out value="${form.type}"/> prints "foo"
I don't see an error.
what is instance type of your "type" variable defined in your "form" object? What I mean is, is the following true?
class MyForm { // For example
String type;
}
class MyForm { // For example
String type;
}
ASKER
Exactly ...
class MyForm {
String type;
}
class MyForm {
String type;
}
make sure no white-space char appended on form.type -- just for in case...
Try to remove the second <c:when> but keep the <c:otherwise>. Just curious though
<c:when test="${form.type == 'foo'}">
Showing FOO
</c:when>
<%-- Remove this --%>
<%--
<c:when test="${form.type == 'bar'}">
Showing BAR
</c:when>
--%>
<c:when test="${form.type == 'foo'}">
Showing FOO
</c:when>
<%-- Remove this --%>
<%--
<c:when test="${form.type == 'bar'}">
Showing BAR
</c:when>
--%>
What is your output for the following code:
a)
<c:if test="${form.type == 'foo'}">
Showing FOO
</c:if>
b)
<c:choose>
<c:when test="${'a' == 'a'}">
Showing a
</c:when>
<c:otherwise>
Not match
</c:otherwise>
</c:choose>
a)
<c:if test="${form.type == 'foo'}">
Showing FOO
</c:if>
b)
<c:choose>
<c:when test="${'a' == 'a'}">
Showing a
</c:when>
<c:otherwise>
Not match
</c:otherwise>
</c:choose>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Does that print "foo" ?