• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

<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-------------
0
tmonteit
Asked:
tmonteit
  • 2
  • 2
  • 2
  • +3
1 Solution
 
rrzCommented:
>type= <c:out value="${form.type}"/>
Does that print  "foo"  ?
0
 
tmonteitAuthor Commented:
Yes , <c:out value="${form.type}"/> prints "foo"
0
 
rrzCommented:
I don't see an error.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Peter KwanCommented:
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;
}
0
 
tmonteitAuthor Commented:
Exactly ...

class MyForm {
   String type;
}
0
 
owenli27Commented:
make sure no white-space char appended on form.type -- just for in case...
0
 
suprapto45Commented:
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>
   --%>
0
 
Peter KwanCommented:
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>
0
 
Hassan_GhanemCommented:
try to write the condition this way ${form.type eq 'foo'} instead of ${form.type == 'foo'}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now