[stringtemplate-interest] selecting a dropdown option

Terence Parr parrt at cs.usfca.edu
Tue May 15 16:26:16 PDT 2007


On May 15, 2007, at 3:59 PM, 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.

Hi Nate,

I'm  afraid that is the common solution at this point.  Can you just  
add the isSelected method to the object itself rather than wrapping?  
that would save you the object creation.

Ter



More information about the stringtemplate-interest mailing list