如何在JSF中使用List <objects>创建selectOneMenu?

时间:2015-12-04 11:31:56

标签: jsf selectonemenu

我尝试使用自定义对象创建<h:selectOneMenu

<h:selectOneMenu value="#{OperatorsReportBean.languagesList}" style="width:100%"
                                     converter="#{langListConverter}">
                        <f:selectItems value="#{OperatorsReportBean.languages}" var="langList"
                                       itemLabel="#{langList.languageName}" itemValue="#{langList}"/>
                    </h:selectOneMenu>

我收到错误:

Conversion Error setting value 'reports.entety.LanguagesList@7ea21f4f' for 'null Converter'. Conversion Error setting value 'reports.entety.LanguagesList@7ea21f4f' for 'null Converter'.

在googling faund建议和创建转换器之后:

@ManagedBean(name = "langListConverter")
public class LangListConverter implements Converter {
    private OracleDBReportOperatorsDao reportsDAO = new OracleDBReportOperatorsDao();

    @Override
    public LanguagesList getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) {
        return reportsDAO.getLanguages(s);
    }

    @Override
    public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o) {
        return ((LanguagesList) o).getLanguageName();
    }
}

但现在我又得到了另一个错误:

j_idt21:j_idt46: Validation Error: Value is not validj_idt21:j_idt46: Validation Error: Value is not valid

这是我的代码:

languagesList = new LanguagesList();
public LanguagesList getLanguagesList() {
        return languagesList;
    }
languages = reportBll.getLanguages();
public List<LanguagesList> getLanguages() {
        return languages;
    }

0 个答案:

没有答案