s.select标记呈现空下拉列表

时间:2011-02-22 15:59:19

标签: java struts2 freemarker

我正在使用struts2和freemarker,我想创建一个简单的下拉列表,它应该显示在值对象中找到的值。

<td><@s.select name="operationalKey" list="key.operationalColumns" theme="simple" id="input.taskForm.operationalKey" /> </td>

问题在于,虽然我的列表中有值(如果我通过key.operationalColumns进行迭代,我可以看到它们),下拉列表呈现为空。

getOperationalColumns方法返回一个     列表

调用操作方法的同样的事情(例如,如果操作将返回List,那么它正在工作)。

我不明白?!?这个OGNL的东西只适用于动作吗?它不应该看对象吗? 我做错了什么?

非常感谢任何帮助 感谢

1 个答案:

答案 0 :(得分:1)

我使用spring.ftl:

* This file consists of a collection of FreeMarker macros aimed at easing
* some of the common requirements of web applications - in particular
* handling of forms.
*
* Spring's FreeMarker support will automatically make this file and therefore
* all macros within it available to any application using Spring's
* FreeMarkerConfigurer.) but I image struts would have something similar.

以下是用例:

<#assign someOptions = ["oneday","twoday", "week", "month"]>
<@spring.formSingleSelect "item.delivery", someOptions, " "/>

或者你可以在这里创建自己的宏来自spring.ftl:

<#--
* formSingleSelect
*
* Show a selectbox (Dropdown) input element allowing a single value to be chosen
* from a list of options.
*
* @param path the name of the field to bind to
* @param options a map (value=label) of all the available options
* @param attributes any additional attributes for the element (such as class
*    or CSS styles or size
-->
<#macro formSingleSelect path options attributes="">
<@bind path/>
<select id="${status.expression}" name="${status.expression}" ${attributes}>
    <#list options?keys as value>
    <option value="${value?html}"<@checkSelected value/>>${options[value]?html}</option>
    </#list>
</select>
</#macro>