More then one condition in JSTL when?

Posted on 2006-05-23
Last Modified: 2013-11-24
IS there a way to combine the first three conditions in to one since they all set the same value??

<c:when test="${omni.content_type_media == null}">
<c:when test="${omni.content_type_media == '<ADD CONTENT>'}">
<c:when test="${omni.content_type_media == 'None'}">
                                          <c:when test="${omni.content_type_media == null}">
                                               <c:set var="content_type_media" value=""/>
                                          <c:when test="${omni.content_type_media == '<ADD CONTENT>'}">
                                               <c:set var="content_type_media" value=""/>
                                          <c:when test="${omni.content_type_media == 'None'}">
                                               <c:set var="content_type_media" value=""/>
                                              <c:set var="content_type_media" value="${omni.content_type_media.value}"/>
Question by:894359
    LVL 3

    Expert Comment

    One option is to create a function in your Omni bean that looks like so:

    public boolean isContentTypeMediaValid() {
      return content_type_media == null || content_type_media.equals("<ADD CONTENT>") || content_type_media.equals("None");

    then use

    <c:when test="${omni.contentTypeMediaValid}"> ...

    Another solution would be to simply use the logical operators:

    <c:when test="${omni.content_type_media == null or omni.content_type_media == '<ADD CONTENT>' or omni.content_type_media == 'None'">
    LVL 3

    Accepted Solution

    Err sorry, small brain lapse there, that should read:

    <c:when test="${omni.content_type_media == null || omni.content_type_media == '<ADD CONTENT>' || omni.content_type_media == 'None'">

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now