我想创建selectOneMenu
带有面板的组件,例如此处的展示(最后一个列表名为“带有过滤器的内容”)。
我的目标是显示标志和相关的语言环境。
我的代码是这个:
<p:selectOneMenu value="#{locale.selectedLanguage}" var="selected">
<f:selectItems value="#{locale.languages}" var="language" itemValue="#{language}"/>
<p:column>
<p:graphicImage value="resources/images/flags/flag_#{selected}.png" width="40" height="50" />
</p:column>
<p:column>
#{selected}
</p:column>
</p:selectOneMenu>
还有我的locale
豆子:
@ManagedBean(name="locale")
@SessionScoped
public class LocaleBean {
private static Logger logger = Logger.getLogger(LocaleBean.class);
private String locale;
private List<String> languages;
private String selectedLanguage;
public LocaleBean() {
super();
languages = new ArrayList<String>();
languages.add("fr");
languages.add("en");
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(locale));
this.locale = locale;
}
public List<String> getLanguages() {
return languages;
}
public void setLanguages(List<String> languages) {
this.languages = languages;
}
public String getSelectedLanguage() {
return selectedLanguage;
}
public void setSelectedLanguage(String selectedLanguage) {
this.selectedLanguage = selectedLanguage;
}
}
使用此代码,我的selectOneMenu
包含fr
和en
值,而我想要标志图像和语言环境。
当我将标签的itemLabel
属性设置为我只有值时,似乎我从未使用/读取过。selectItems
foo
foo
p:column
请问我的错误在哪里?