Trying to get this conditional to work. How do I get this variable to be set?

32 Views Asked by At

I am trying to conditionally set this variable so I don't have to display date slashes when I display an empty entry.

  <c:choose>
    <c:when test="${fn:length(findYear[1]) eq 0}">...</c:when>
    <c:set var="dateformat" value="fn:length(findYear[1]) " />
    <c:when test="${fn:length(findYear[1]) gt 0}">
      <c:set var="dateformat" value="${findYear[1]} / ${findYear[2]} / ${findYear[0]}" />
    </c:when>
  </c:choose>

  <tr:column  width="71px" align="center" headerText="Date" sortable="true" sortProperty="type">
    <tr:outputText value= "${dateformat}">
      <!--  "${findYear[1]} / ${findYear[2]} / ${findYear[0]}"  readOnly= "true"  > -->
    </tr:outputText>​

Right now, nothing is showing up when I call the variable. Any help would be appreciated.

1

There are 1 best solutions below

0
Usagi Miyamoto On

Try something like this:

<c:choose>
  <c:when test="${empty findYear[1]}">
    <c:set var="dateformat" value="${findYear[0]}" />
  </c:when>
  <c:otherwise>
    <c:set var="dateformat" value="${findYear[1]} / ${findYear[2]} / ${findYear[0]}" />
  </c:otherwise>
</c:choose>
  • The empty operator returns true when the argument is null or empty string.
  • The first <set> statement was outside of any <when> block, and its value did not contain ${}...
  • As your conditions complete one another, <otherwise> could be used.