Solved

<c:when> problem

Posted on 2006-11-10
9
223 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
Technology Partners: 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Check out this step-by-step guide for asking an anonymous question on Experts Exchange.
Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Suggested Courses

734 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