【问题标题】:get elements from an array in the jsf selectonemenu从 jsf selectonemenu 中的数组中获取元素
【发布时间】:2013-11-08 07:15:33
【问题描述】:

如何从 JSF selectOneMenu 中的数组中获取打印元素, 我在一个 bean 类中有一个数组作为

String[] leaveTypeArray;

对此有何建议?

【问题讨论】:

  • 你不迭代,你使用<f:selectItems>(注意标签组件名称末尾的s)。
  • 你能给我一个示例代码吗
  • 您可以在添加标签的 wiki (info) 页面上找到许多入门代码示例。
  • 还有,你可以在网上搜索<f:selectItems>...
  • 我无法理解在 itemlabel 和 itemvalue 中放入什么

标签: jsf jsf-2 selectonemenu


【解决方案1】:

正如luiggi-mendoza 所说,<f:selectItems> 会很好。

你可以用 List 做到这一点,只需在 bean 类中添加 List 或 String[] 中的项目

Bean(通过列表):

List listValue=new ArrayList[];

static
{
  listValue.add("First");
  listValue.add("Second");
  listValue.add("Third");
}
//Create getters and setters for listValue

Bean(通过数组):

String[] listValue={"First", "Second", "Third"};

//Create getters and setters for listValue

JSF 页面

<p:selectOneMenu value="#{result value}">
  <f:selectItems value="#{bean.listValue}"/>
</p:selectOneMenu> 

参考:Primefaces showcase

【讨论】:

  • 但是我们不能直接在 selectonemenu 中访问数组本身。而不是再次创建一个新列表并添加字符串对象..只是想知道..
猜你喜欢
  • 2011-10-10
  • 1970-01-01
  • 2010-11-02
  • 2014-12-19
  • 1970-01-01
  • 2011-02-01
  • 2019-12-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多