Hi every body I'm working on Primfaces pages and I have to make a selectOneMenu wich get items from dataBase so I tried to make it this way but I still have problem's with the converter
so my source Codes are the folowing :
selectOneMenu :
<p:selectOneMenu id="devises" required="true" value="#{pret.devise}" effect="fade" converter="devise">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{devise.listDevise()}" var="devise" itemLabel="#{devise.nomDevise}" itemValue="#{devise}"/>
</p:selectOneMenu>
converter code:
@FacesConverter(value = "devise")
public class DeviseConverter implements Converter{
public static List<Devise> devises = Devise.listDevise();
public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) {
if (submittedValue.trim().equals("")) {
return null;
} else {
try {
int idDevise = Integer.parseInt(submittedValue);
for (Devise p : devises) {
if (p.getIdDevise()== idDevise) {
return p;
}
}
} catch(NumberFormatException exception) {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid Devise"));
}
}
return null;
}
public String getAsString(FacesContext facesContext, UIComponent component, Object value) {
if (value == null || value.equals("")) {
return "";
} else {
return String.valueOf(((Devise) value).getIdDevise());
}
}
}
the error Code is : "devises: Validation Error: Value is not valid"