« Return to Thread: Best way to handle optional attributes in 1.6.2

Re: Best way to handle optional attributes in 1.6.2

by Nathan Bubna :: Rate this Message:

Reply to Author | View in Thread

That should be:

#if( "$!items.getAttributeValue('required')" != "" )

Or just $!items.getAttributeValue('required') if you don't mind
showing empty strings.

Or if you really want to clean up the look:

public class AltTool {
  public Object empty(Object val, Object alt) {
    return (val == null || val.toString().length() == 0) ? alt : val;
  }
}
context.put("alt", new AltTool());

$alt.empty($item.getAttributeValue('required'), 'No')

On Sat, Jun 13, 2009 at 5:39 AM, Jude
Robinson<dotcode+velocity@...> wrote:
>> Is there a better way to handle optional attributes?
>
> "!$items.getAttributeValue('required')" != ""
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>

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

 « Return to Thread: Best way to handle optional attributes in 1.6.2