I want to create selectOneMenu
component with panel like the showcase here (the last list named "Content with Filter").
My goal is to show flags and associated locales.
My code is this one :
<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>
And my locale
bean :
@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;
}
}
With this code, my selectOneMenu
contains fr
and en
values whereas I want flag image and locale.
When I set itemLabel
attribute of selectItems
tag to foo
I have only foo
values so it seems that my p:column
are never used/read.
Where can be my error please ?
Ok so I found the solution in primefaces forum.
Actually, when iterator is type of String
columns render are not rendered.
So I have to create custom object and encapsulate my String
inside it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.