简体   繁体   English

Struts2-如何用字符串列表填充选择标记?

[英]Struts2 - How to populate a select tag with a list of String?

I have a select that has to populate its options with a list of String. 我有一个选择,必须用字符串列表填充其选项。 The option value and text are to be equals. 选项值和文本应相等。

I know that I'm sending the list correctly because the select render a number of elements equals to the size of the list. 我知道我正确地发送了列表,因为select呈现的元素数量等于列表的大小。

<s:select name="status" list="status" headerKey="" headerValue="-- Select --" id="status" listKey="" listValue="" />

What happens is that the options are rendered without value and text because I don't have a clue about what I should refer to in listKey and listValue attributes of the select tag of Struts2 taglib. 发生的情况是,选项呈现时没有值和文本,因为我不知道应该在Struts2 taglib的select标签的listKeylistValue属性中引用什么。

The method in the action: 动作中的方法:

public List<String> getStatus() {
    return Arrays.asList("Active", "Inactive");
}

If you omit the lisKey and listValue attributes, then Struts2 will use the string text as the key and the value. 如果省略lisKeylistValue属性,则Struts2将使用字符串文本作为键和值。

Try: 尝试:

<s:select name="status" list="status" headerKey="" headerValue="-- Select --" id="status" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM