Solved

<c:when> problem

Posted on 2006-11-10
9
222 Views
Last Modified: 2011-10-03
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
Comment
Question by:tmonteit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 27

Expert Comment

by:rrz
ID: 17919759
>type= <c:out value="${form.type}"/>
Does that print  "foo"  ?
0
 

Author Comment

by:tmonteit
ID: 17919775
Yes , <c:out value="${form.type}"/> prints "foo"
0
 
LVL 27

Expert Comment

by:rrz
ID: 17919812
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!

 
LVL 16

Expert Comment

by:Peter Kwan
ID: 17919818
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
 

Author Comment

by:tmonteit
ID: 17919830
Exactly ...

class MyForm {
   String type;
}
0
 
LVL 9

Expert Comment

by:owenli27
ID: 17919861
make sure no white-space char appended on form.type -- just for in case...
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 17920279
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
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 17921460
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
 
LVL 4

Accepted Solution

by:
Hassan_Ghanem earned 400 total points
ID: 17924249
try to write the condition this way ${form.type eq 'foo'} instead of ${form.type == 'foo'}
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question