简体   繁体   中英

NullPointException in FaceConverter

Im developing using jpa and jsf.I'm not place all the code because is very large I have an NullPointException in a code generated for netebeans 7.2. I think that netbeans is making the error, but i cant fix it.

@FacesConverter(forClass = MaterialEntrada.class)
public static class MaterialEntradaControllerConverter implements Converter {

    public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
        if (value == null || value.length() == 0) {
            return null;
        }
        MaterialEntradaController controller = (MaterialEntradaController) facesContext.getApplication().getELResolver().
                getValue(facesContext.getELContext(), null, "materialEntradaController");
        return controller.ejbFacade.find(getKey(value));
    }

    java.lang.Integer getKey(String value) {
        java.lang.Integer key;
        key = Integer.valueOf(value);
        return key;
    }

    String getStringKey(java.lang.Integer value) {
        StringBuffer sb = new StringBuffer();
        sb.append(value);
        return sb.toString();
    }

    public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
        if (object == null) {
            return null;
        }
        if (object instanceof MaterialEntrada) {
            MaterialEntrada o = (MaterialEntrada) object;
            return getStringKey(o.getId());
        } else {
            throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + MaterialEntrada.class.getName());
        }
    }
}

The error is caused by the line :

return controller.ejbFacade.find(getKey(value));

ejbFacate is null, but controller is not null.

What's happening is that controller is being initialized by jsf but ejbfacade is not. Either add the code necessary to do this to the constructor or create a getter to do it at invocation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM