<p:ajax> not firing when choosing null value

861 Views Asked by At

I have the following p:selectOneMenu :

<p:selectOneMenu widgetVar="selectELclUpdateLcl" style="font-size:11px;"
                    value="#{tabparam.selectedDataEntite}"  appendTo="@this" 
                    id="selectedDataEntite" required="true" requiredMessage="Entité obligatoire" 
                    converter="entiteConverter">

                    <p:ajax event="change" listener="#{tabparam.enableBloc}" update="sBloc sTLocal sEtage" />   

                    <f:selectItem noSelectionOption="true" itemLabel="-- Entités --" value="#{null}"></f:selectItem>
                      <f:selectItems  value="#{tabparam.listDataEntite}" var ="e" 
                      itemLabel="#{e.nom}" itemValue="#{e}" ></f:selectItems>
                    </p:selectOneMenu>

When I select an item different from null, the ajax event is fired correctly. But if I choose the null one (Select "-- Entités --" ), the ajax event is not fired.

Below is my converter class:

@FacesConverter(value = "entiteConverter")
public class EntiteConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
        Data_Entite ret = null;
        UIComponent src = arg1;
        if (src != null) {
            List<UIComponent> childs = src.getChildren();
            UISelectItems itens = null;
            if (childs != null) {
                for (UIComponent ui : childs) {
                    if (ui instanceof UISelectItems) {
                        itens = (UISelectItems) ui;
                        break;
                    } else if (ui instanceof UISelectItem) {
                        UISelectItem item = (UISelectItem) ui;
                        try {
                            Data_Entite val = (Data_Entite) item.getItemValue();
                            if (arg2.equals("" + val.getId())) {
                                ret = val;
                                break;
                            }
                        } catch (Exception e) {
                        }
                    }
                }
            }

            if (itens != null) {
                List<Data_Entite> values = (List<Data_Entite>) itens.getValue();
                if (values != null) {
                    for (Data_Entite val : values) {
                        if (arg2.equals("" + val.getId())) {
                            ret = val;
                            break;
                        }
                    }
                }
            }
        }
        return ret;
    }

    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
        String ret = "";
        if (arg2 != null && arg2 instanceof Data_Entite) {
            Data_Entite m = (Data_Entite) arg2;
            if (m != null) {
                int id = m.getId();
                if (id != 0) {
                    ret = Integer.toString(id);
                }
            }
        }
        return ret;
    }

}

Any idea please ? I am using PF 5.1 Thanks.

0

There are 0 best solutions below