JSF SelectOneMenu标签

时间:2014-04-13 13:54:03

标签: java jsf-2 jboss7.x selectonemenu

尝试从jsf中的下拉列表中选择项目时出错

<h:form id="form">

    <h:selectOneMenu value="#{currenccyRatesModel.mainCurrency}" converter="currencyDto"
        valueChangeListener="#{currencyRatesController.loadCurrencyRates}">

        <f:selectItems value="#{currenccyRatesModel.bankCurrencies}"
            var="selectedCurrency" itemValue="#{selectedCurrency}"
            itemLabel="#{selectedCurrency.curLabe}" />
        <f:ajax render="currencyRatesTable" event="change" />
    </h:selectOneMenu>

    <h:dataTable id="currencyRatesTable" var="currencyRate"
        value="#{currenccyRatesModel.currencyRates}">
        <h:column>
            <h:outputText value="#{currencyRate.targetCurrency}" />
        </h:column>
        <h:column>
            <h:outputText value="#{currencyRate.ccrRate}" />
        </h:column>

    </h:dataTable>


</h:form>

网页浏览器中抛出的错误无法将货币@ 323536 java.lang.String转换为类型.... CurrencyDto

这有什么问题,我在之前的项目中使用了相同的东西并且工作正常。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

当您在h:selectOneMenu中使用java类作为转换器时,此类(在您的情况下为CurrencyDto)必须实现Converter接口,换句话说,此类应包含以下方法:

public Object getAsObject(FacesContext context, UIComponent component, String value)
public String getAsString(FacesContext context, UIComponent component, Object value)

在您的情况下,currenccyRatesModel.mainCurrency与转换器方法中预期作为参数的对象不兼容。