13 Jun 12:13
Best way to handle optional attributes in 1.6.2
sebb <sebbaz <at> gmail.com>
2009-06-13 10:13:46 GMT
2009-06-13 10:13:46 GMT
I'm generating HTML using a Velocity style sheet with version 1.6.2
The source contains lots of elements which are used to generate table
cell entries:
<property name="Name" required="">Description</property>
The "required" attribute is supposed to be "Yes" or "No", with a
default of "No".
The VSL currently has:
<td>
#if($items.getAttributeValue("required") != "")
$items.getAttributeValue("required")
#else
No
#end
</td>
This works OK provided that the "required" attribute is present,
however I would like to treat a missing attribute the same way as the
empty string.
The above code used to work in Velocity 1.5, but now I get
<td>$items.getAttributeValue("required")</td>
instead of
<td>No</td>
The following works, but seems rather messy:
<td>
#if($items.getAttributeValue("required") &&
$items.getAttributeValue("required") != "")
$items.getAttributeValue("required")
#else
No
#end
</td>
Is there a better way to handle optional attributes?
RSS Feed