简体   繁体   中英

JSF SelectOneMenu Tag

I am getting an error while trying to choose item from drop down list in 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>

the error thrown in the web browser is cannot convert currency@323536 java.lang.String to type ....CurrencyDto

is there somting wrong with this, I used the same thing in a previous project and is worked fine.

Thanks for help

When you use java class as converter in h:selectOneMenu , then this class (CurrencyDto in your case) must implements Converter interface, in other words this class should have to contain following methods:

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

In your case currenccyRatesModel.mainCurrency is not compatible with object which is expected as parameter in converter method(s).

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM