another jsf <f:selectItems> itemValue and message bundle question

杀马特。学长 韩版系。学妹 提交于 2019-12-10 10:55:40

问题


i have a selectOneMenu with selectitems. if i use

<f:selectItem itemValue="3" itemLabel="#{hrBundle['phoneType3']}"/>

it works well, displaying the localized label. i have more options inside a List and when i use f:selectItems, it stops working. this code:

<f:selectItems value="#{values}" var="item" itemLabel="#{hrBundle[item.label]}" itemValue="item.value"/>

shows the key('phoneType3') as label, and even

<f:selectItems value="#{values}" var="item" itemLabel="#{hrBundle['phoneType3']}" itemValue="item.value"/>

('hardcoded' as the single f:selectItem above) displays the key ('phoneType3') instead of the localized label.

any idea what i am doing wrong?


回答1:


It depends on what the key in your bundle file is. If the key in your bundle ist the content of item.value, do the following:

<f:selectItems value="#{myBean.values}" 
 var="item" 
 itemLabel="#{hrBundle[item.value]}" 
 itemValue="#{item.value}"/>

I don't know, if this is your original code. If yes, notice the following:

  1. You have to reference a backing bean in your value attribute (as shown above: replace myBean with your beans name).
  2. The itemValue attribute needs an el expression as well: itemValue= "#{item.value}"


来源:https://stackoverflow.com/questions/5363382/another-jsf-fselectitems-itemvalue-and-message-bundle-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!