Question

i'm facing a problem with a Converter. In my xhtml file, i have a selectOneMenu with a list of object and i want to set an object in my managedBean.

If my managedBean has @SessionScoped, the object in the managedbean is filled but if the managedeban has @ViewScoped, the converter is never use and my object is null.

how to fix this problem ?

Xhtml :

<p:selectOneMenu value="#{rechercheBean.role}" converter="#{typConverter}">
    <f:selectItems id="item" value="#{typBean.roles}" var="r" itemLabel="#{r.valeur}" itemValue="#{r}" />
</p:selectOneMenu>

typConverter :

public class TypConverter implements Converter{
    @EJB
    private TypFacadeLocal  TypBean;

    public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) {
        if (submittedValue.trim().equals("")) {
            return null;
        }
        else {
            try {
                Integer id = Integer.parseInt(submittedValue);
                Typ typ = new Typ();
                typ = TypBean.find(id);
                return typ;
            }
            catch (NumberFormatException exception) {
                throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Typ non valide"));
            }
        }
    }

    public String getAsString(FacesContext facesContext, UIComponent component, Object value) {
        if (value == null || value.equals("")) {
            return "";
        }
        else {
            return String.valueOf(((Typ) value).getId());
        }
    }
}

Tx a lot

Was it helpful?

Solution

The problem is the component c:when. With the attribut renderer of the component , there is no problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top