Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

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>
Avatar of Krule
Krule
Flag of Canada image

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'">
ASKER CERTIFIED SOLUTION
Avatar of Krule
Krule
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial