The If Tag

Content may be conditionally processed using the "if" tag. This tag may be used in two forms: a bodiless form, which provides a value for one cell only, and with a body, which conditionally processes an entire block of cells.

Attributes

  • The "if" tag supports all base tag attributes.
  • test: Boolean Required. This is the test condition. A JEXL Expression can evaluate to the boolean values true or false, or the string literals "true" or "false".
  • elseAction: String Optional. Available only if the tag has a body. This value describes the action taken when the test condition is false. The following values are supported:
    • shiftUp This is the default. Block contents will be deleted, and any existing cell contents from below the block will be shifted up.
    • shiftLeft Block contents will be deleted, and any existing cell contents from the right of the block will be shifted left.
    • clear Block contents will be cleared. No shifting occurs.
    • remove Block contents will be removed, including all borders, merged regions, and formatting.
  • then: Object Required if the tag is bodiless. This is the value of the cell if the condition is true.
  • else: Object Optional, but only available if the tag is bodiless. This is the value of the cell if the condition is false. This defaults to an empty cell.

If With a Body

The "if" tag evaluates the condition specified in the required attribute "test". If true, then the "if" tag transforms the entire body, and any "elseAction" value is ignored. If false, then the entire body is removed. Upon removal, content that lies below that block is shifted up to overwrite the block.

<jt:if test="${condition}">${expr1}        
  ${expr2}   To be erased if false!  
${expr3}   ${expr4} </jt:if>  
Shift me up!    

... if the condition is true, then the above block gets transformed into...

Expression 1        
  Expression 2   To be erased if false!  
Expression 3   Expression 4    
Shift me up!    

... else, if the condition is false...

Shift me up!    
         
         
         

The optional "elseAction" attribute controls how the content of the block is removed when the condition is false. The value "shiftLeft" changes the default direction of the shifting to left, i.e. content to the right of the block is shifted left to overwrite the block. The default value for this attribute is "shiftUp", which is shown above.

<jt:if test="${condition}" elseAction="shiftLeft">${expr1}     ${expr2} Additional
  ${expr3}     Content
    Label:   Is Shifted
      ${expr4}</jt:if> Left
Below, things don't change !!!

... if the condition is false...

Additional        
Content        
Is Shifted        
Left        
Below, things don't change !!!

The elseAction value "clear" indicates not to perform any shifting of content outside of the block. Instead, values inside the block's cells are simply cleared. Other things such as borders, formatting, and merged regions remain intact.

<jt:if test="${condition}" elseAction="clear">${expr1}     ${expr2} Additional
  ${expr3}   Content
    Label:   Is Not Shifted
      ${expr4}</jt:if> Left
Below, things don't change !!!

... if the condition is false...

        Additional
      Content
        Is Not Shifted
        Left
Below, things don't change !!!

The elseAction value "remove" also does not perform any content shifting outside of the block. However, unlike the "clear" value, "remove" will additionally remove the entire cells of the block, which removes all borders, merged regions, and formatting.

<jt:if test="${condition}" elseAction="remove">${expr1}     ${expr2} Additional
  ${expr3}   Content
    Label:   Is Not Shifted
      ${expr4}</jt:if> Left
Below, things don't change !!!

... if the condition is false...

        Additional
        Content
        Is Not Shifted
        Left
Below, things don't change !!!

Bodiless If

In the bodiless form, the "if" tag also requires a "then" tag, and it can accept an optional "else" tag. Rich Text String formatting is supported in the "then" and "else" attributes.

  <jt:if test="${condition}" then="${value1}" else="${value2}"/>  

... if the condition is true...

  Result1  

... else if the condition is false...

  Result2