-1

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

Rachid
  • 165
  • 2
  • 5
  • 16

1 Answers1

0

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).

Vasil Lukach
  • 3,658
  • 3
  • 31
  • 40