I'm using Freemarker as the templating engine for a Struts 2 application and having some problems trying to pass a Freemarker hash to the @s.select tag's li开发者_Go百科st value.
Currently I'm trying something like this in my template:
<@s.select name="myDropdown" list={"1":"Foo", "2":"Bar", 3:"Baz"} />
The resulting HTML that's rendered is 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 of using Freemarker lists. Hashes are only mentioned as another option, but I haven't been able to find any code examples that use them.
Ultimately my question is, what Freemarker syntax should I use with the Struts 2 select tag in order to render the following HTML?
<select name="myDropdown" id="myDropdown">
<option value="1">Foo</option>
<option value="2">Bar</option>
<option value="3">Baz</option>
</select>
Using the listKey and listValue properties of the select tag seems to do the trick.
The working code is now:
<@s.select name="myDropdown" list={"1":"Foo", "2":"Bar", 3:"Baz"} listKey="key" listValue="value" />
Seems like that should be taken care of automatically by the tag, but I was not able to get it to work without explicitly setting those two additional properties.
精彩评论