jsf - Primefaces Validation error with converter and equals working -


i got problem p:selectonemenu of primefaces in jsf. read lot of questions asked same problem nothing helped me.

when set component same way used wherever in project, if try select 1 of items of selectonemenu, error appears :

validation error: value not valid

lot of people resolve correcting converter class or equals() methods, nothing wrong in mines.

converter

@requestscoped public class baremeconverter implements converter {      @ejb     private baremebean baremebean;      @override     public object getasobject(facescontext fc, uicomponent uic, string value) {         if(value != null && value.trim().length() > 0) {             try {                 return baremebean.loadbyid(integer.parseint(value));             } catch(numberformatexception e) {                 return null;             }         }         else {             return null;         }     }      @override     public string getasstring(facescontext fc, uicomponent uic, object object) {         if(object != null) {             return string.valueof(((bareme) object).getid());         }         else {             return null;         }     }     } 

baremebean entitybean of class loading data fine. workspace full of converters except if miss in one, should work here.

equals() method of class bareme

@override public boolean equals(object object) {     if (!(object instanceof bareme)) {         return false;     }     bareme other = (bareme) object;     return !((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))); } 

this equals() method generates netbeans , nothing looks wrong here too.

finally, give code of component use, , same thing previous ones, same code works others classes got.

<h:outputlabel for="forfaitbareme" value="barème" /> <p:selectonemenu id="forfaitbareme" class="print-w100p-lab" value="#{transportfacturationbean.forfait.bareme}" converter="#{baremeconverter}" >       <f:selectitem itemlabel="" itemvalue="#{null}" />     <f:selectitems value="#{transportfacturationbean.baremesforfait}" var="b" itemlabel="#{b.id}" itemvalue="#{b}" />     <p:ajax event="change" update=":centralpanel" process="@form" />  </p:selectonemenu>   

transportfacturationbean.baremesforfait java.util.list contains few bareme.

you should know code below working using custom object of project. camion implemented same way bareme, converters similar, , equals() method both ones generated netbeans.

<h:outputlabel for="forfaitcamion" value="camion" /> <p:selectonemenu id="forfaitcamion" class="print-w100p-lab" value="#{transportfacturationbean.forfait.camion}" converter="#{camionconverter}" >       <f:selectitem itemlabel="" itemvalue="#{null}" />     <f:selectitems value="#{transportfacturationbean.camions}" var="c" itemlabel="#{c.type}" itemvalue="#{c}" />     <p:ajax event="change" update=":centralpanel" process="@form" />  </p:selectonemenu> 

any appreciated ! in advance !

solved ! biggest smallest mistake imagine !

return baremebean.loadbyid(integer.parseint(value)); 

my loadbyid method returning list instead of simple object.... sorry guys !


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -