Freemarker hash for Struts2 @ s.select tag list property

I am using Freemarker as my templating engine for a Struts 2 application and am having some problems trying to pass the Freemarker hash into the @ s.select tag list value.

I am currently trying to do something like this in my template:

<@s.select name="myDropdown" list={"1":"Foo", "2":"Bar", 3:"Baz"} />

      

The resulting HTML looks like this:

<select name="myDropdown" id="myDropdown">
    <option value="freemarker.ext.beans.HashAdapter$1$1$1@2c9bebb">freemarker.ext.beans.HashAdapter$1$1$1@2c9bebb</option>
    <option value="freemarker.ext.beans.HashAdapter$1$1$1@16ca4a">freemarker.ext.beans.HashAdapter$1$1$1@16ca4a</option>
    <option value="freemarker.ext.beans.HashAdapter$1$1$1@173ee8">freemarker.ext.beans.HashAdapter$1$1$1@173ee8</option>
</select>

      

Based on the documentation, it seems like this should work, but really the only examples are Freemarker lists. Hashes are only mentioned as another option, but I couldn't find any code examples that use them.

Ultimately my question is which Freemarker syntax should I use with the Struts 2 select tag to display the following HTML:

<select name="myDropdown" id="myDropdown">
    <option value="1">Foo</option>
    <option value="2">Bar</option>
    <option value="3">Baz</option>
</select>

      

+2


a source to share


1 answer


Using the listKey and listValue properties of the select tag seems like a trick.

Working code now:



<@s.select name="myDropdown" list={"1":"Foo", "2":"Bar", 3:"Baz"} listKey="key" listValue="value" />

      

It looks like the tag should be handled automatically by the tag, but I couldn't get it to work without explicitly setting these two additional properties.

+2


a source







All Articles