Solved

<c:when> problem

Posted on 2006-11-10
9
218 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
  • 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

If you thought ransomware was bad, think again! Doxware has the potential to be even more damaging.
As a business owner, there are many things that keep you up at night. Profit margins, employee retention, human resource protocols, whether your product or service will remain competitive. When you own or manage a technology company that operates la…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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