Question

I am working on a defect in which by default all check-box need to be selected, if multiple channels are used. However, currently in case of multiple channels selects the fist channel check-box remains unselected only

THE JSTL code is

<label data-use-main="#"
    class="left-align  form-inline checkbox ${fn:length(messageForm.configuredChannels) > 1 ? '' : 'hidden'}">
      <form:checkbox path="emailMessageForm.useMainMessageEmail" />&nbsp;&nbsp;
      <label>
        <spring:message code="message.use.main.content.email"></spring:message>
      </label>
</label>

I m not able to understand how ${fn:length(messageForm.configuredChannels) > 1 ? '' : 'hidden'}"> works as the checkbox checked condition depends on it.

Was it helpful?

Solution

messageForm.configuredChannels is a collection and the fn:length() function is checking to see if the collection contains more than one element. If the collection contains more than one element the label containing the checkbox is displayed and if not it is hidden by adding a css class.

Lets break the expression down:

${fn:length(messageForm.configuredChannels) > 1 ? '' : 'hidden'}"

1.  ${}
    This just denotes a JSP EL expression

2.  fn:length(messageForm.configuredChannels) > 1 ? '' : 'hidden'
    This is a ternary operator

3.  fn:length(messageForm.configuredChannels)
    Returns amount of elements in collection
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top