[stringtemplate-interest] selecting a dropdown option

Nate misc at n4te.com
Tue May 15 16:02:52 PDT 2007


Sorry for the back to back mails, but I came up with another workaround. 
It is kind of nasty, but I could use a HashMap...

<select name="location">
$locations:{location|
<option $if(selected.(location.id))$selected$endif$>$location.name$</option>
}$
</select>

Any better ideas?

-Nate


Nate wrote:
> I have a template similar to this where I want to select one of the
> locations...
>
> <select name="location">
> $locations:{location|
> <option $if(location.name ==
> selectedLocation)$selected$endif$>$location.name$</option>
> }$
> </select>
>
> Obviously that isn't valid ST and would break separation. The location
> objects are part of an object model I don't have access to, otherwise I
> could add an "isSelected" method and use a template like this...
>
> <select name="location">
> $locations:{location|
> <option $if(location.selected)$selected$endif$>$location.name$</option>
> }$
> </select>
>
> Is there any other way than to wrap the location objects in my own class
> and have a whole slew of delegate methods? This is a common scenario in
> my webapp.
>
> -Nate


More information about the stringtemplate-interest mailing list