velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Best way to handle optional attributes in 1.6.2
Date Sat, 13 Jun 2009 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?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Mime
View raw message