How work with Java StringTemplate boolean?
-
23-06-2021 - |
Frage
I wrote the following StringTemplate template lines:
<instance.attributes: { attr | <attr.value>}>
<instance.attributes: { attr | <if(attr.value)>skip<else>don't skip<endif> } >
in order to write skip if the Object value return by Instance.getAttributes().getValue()
is a boolean which value is true.
This result in
1
skip
and
0
skip
(for now I only have one attribute)
What is the problem and why I don't get ?
0
don't skip
Lösung
From the StringTemplate wiki
<if(attribute)>subtemplate <else>subtemplate2 <endif>
if attribute has a value or is a boolean object that evaluates to true, include subtemplate else include subtemplate2. These conditionals may be nested.
I assume that 0 means not false
, but some value that indicates presence of value and evaluates to true. You need to compute boolean value that evaluates to false before pushing it to the template.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow