小编Ale*_*ond的帖子

JSF-2 f:带有Map的selectItems不显示itemLabel

当我使用f:selectItems来显示Map中的项目时,我无法显示Map项的值,只显示键.f:selectItems根本不使用itemLabel.当我使用List而不是工作.

以下确实使用itemLabel来显示List中项目的"描述":

<h:selectOneMenu>
  <f:selectItems value="#{testBB.testList}" var="s"
    itemLabel="TEST #{s.description}" itemValue="#{TEST s.name}" />
</h:
selectOneMenu>
Run Code Online (Sandbox Code Playgroud)

以下尝试在Map中显示项目的值不起作用.它显示项目的键,但不使用itemLabel属性,因为可以通过缺少"TEST"文本的输出来识别.

<rich:select>
  <f:selectItems value="#{testBB.testMap}" var="s"
    itemLabel="TEST #{s.value}" itemValue="TEST #{s.key}" />
</rich:select>
Run Code Online (Sandbox Code Playgroud)

使用的简单支持bean如下:

public class TestBB {
  private Map<String, String> testMap;
  private List<TestItem> testList;

  public TestBB() {
    testMap = new HashMap<String, String>();
    testMap.put("1_key", "Item One");
    testMap.put("2_key", "Item Two");
    testMap.put("3_key", "Item Three");

    testList = new ArrayList<TestItem>();
    testList.add( new TestItem("name_1", "description_1") );
    testList.add( new TestItem("name_2", "description_2") );
    testList.add( new TestItem("name_3", "description_3") );
  }

  public Map<String, String> getTestMap() {
    return testMap; …
Run Code Online (Sandbox Code Playgroud)

jsf el map jsf-2

16
推荐指数
1
解决办法
3万
查看次数

标签 统计

el ×1

jsf ×1

jsf-2 ×1

map ×1