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

More then one condition in JSTL when?

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:choose>
                                          <c:when test="${omni.content_type_media == null}">
                                               <c:set var="content_type_media" value=""/>
                                            </c:when>
                                          <c:when test="${omni.content_type_media == '<ADD CONTENT>'}">
                                               <c:set var="content_type_media" value=""/>
                                            </c:when>
                                          <c:when test="${omni.content_type_media == 'None'}">
                                               <c:set var="content_type_media" value=""/>
                                            </c:when>
                                          <c:otherwise>
                                              <c:set var="content_type_media" value="${omni.content_type_media.value}"/>
                                            </c:otherwise>
                                    </c:choose>
0
894359
Asked:
894359
  • 2
1 Solution
 
KruleCommented:
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'">
0
 
KruleCommented:
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'">
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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