KB Article #181767

How do you test if a whiteboard attribute is empty?

Problem

How do you test if some whiteboard attribute is empty?

Resolution

You can use JUEL (Java Unified Expression Language) in a selector expression. The expression ${empty my.attribute} will be true whenever my.attribute is either null or an empty string. That can be used with the Evaluate Selector filter to take different paths depending on whether the variable is set or not.


Or you can use the ternary operator to provide a default value when the attribute is empty by using an expression like ${empty my.attribute ? "default value" : my.attribute} which will evaluate to "default value" whenever the attribute is empty and give you the attribute value the rest of the time.


Evaluation of the selector expression itself will not change the value of the attribute. The JUEL expressions do not do assignment, they only returns the value of the expression to the caller. If you wish to change the attribute value actually stored on the whiteboard, you need to use a Set Attribute filter to give an attribute a new value. Using Set Attribute to give the variable a new value using the ternary operator is the simplest way to ensure that an empty variable is changed into a reasonable default value.