Help with NullPointerException in jsf?

0

I have a combo that shows a list of a catalog that is in the database

<h:outputText value="#{datospersonalesmsgs['datospersonales.descuento.title']}:" />
<p:selectOneMenu id="catBeneficio" value="#{DatosPersonalesComponent.solicitudeses.sysBeneficios.idSysBeneficio}" required="false" valueChangeListener="#{DatosPersonalesComponent.obtenerDescuento}">
  <p:ajax event="change" update="catBeneficio,dialogBeneficio,dialogDiscapacidad, dialogAgricola" />
  <f:selectItem itemLabel="Seleccione" />
  <f:selectItems value="#{SysBeneficiosComponent.listSysBeneficioss()}" var="descuentos" itemValue="#{descuentos.idSysBeneficio}" itemLabel="#{descuentos.descripcion}">
  </f:selectItems>
</p:selectOneMenu>

And send a call to a method with the Valuelistener, what I want you to do is that if in the combo you select option 5 or 10 that is the id of the catalog, the boolean is true and send me a dialog depending on the option, that dialogue I'm calling in the ajax with the update, but NullPointer tells me in the if and I do not know why it is?

 public void obtenerDescuento(ValueChangeEvent event) {
    System.out.println("ENTRA A OBTENER DESCUENTO");

    if (solicitudeses.getSysBeneficios() != null) {

        if (solicitudeses.getSysBeneficios().getIdSysBeneficio().equals(5)) {
            System.out.println("ES PERSONA CON DISCAPACIDAD");
            msjdiscapacitado = true;

        }
        if (solicitudeses.getSysBeneficios().getIdSysBeneficio().equals(10)) {
            System.out.println("ES TRABAJADOR AGRICOLA");
            msjtrabajadoraagricola = true;
        }
    }

}
    
asked by Root93 30.11.2017 в 20:48
source

1 answer

0

If the exception is where it is coming from:

if (solicitudeses.getSysBeneficios() != null) { //NullPointerException
}

It must be because solicitudeses is an object that you are not initializing in your component before using it. Since there you would be doing:

null.getSysBeneficios()

And null is not an object that has that method, that's why the exception. First validate that solicitudeses is not null before trying to access its methods.

if (solicitudeses != null) {
    if (solicitudeses.getSysBeneficios() != null) {
    }
}
    
answered by 01.12.2017 в 18:34