0

I have a exception on Usuario usuario = gestionUsuario.hacerLogin(nombre, clave); and I want capture the exception and show its in a context message. I implemented the next code, but the application show an alert message: serverError: class javax.faces.el.EvaluationException

public String iniciarSesion() throws IOException {
    try{
    GestionUsuario gestionUsuario = new GestionUsuario();
    Usuario usuario = gestionUsuario.hacerLogin(nombre, clave);
    }catch(EvaluationException ex){
        FacesMessage message = new FacesMessage(ex.toString());
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(btnLogin.getClientId(context), message);
        return null;
    }
    FacesContext.getCurrentInstance().getExternalContext().redirect("inicio.xhtml");
    return "inicio";
}

XHTML. (The action of button call iniciarSesion)

 <h:form id = "loginForm">

    <h:outputLabel id = "txtUsuario" for = "inputUsuario" value = "#{msgs['loginForm.usuario']}"/>
    <b:inputText id = "inputUsuario" required = "true" value = "#{logBean.nombre}" class = "inputText"/>
    <br/>

    <h:outputLabel id = "txtClave" for = "inputClave"  value = "#{msgs['loginForm.clave']}"/>
    <b:inputSecret id = "inputClave" required = "true" value = "#{logBean.clave}" class = "inputPassword"/>
    <br/>

    <div class="row-fluid">
        <div class="span10 text-center">
            <h:message for="btnLogin" class = "text-danger"/>
        </div>
    </div>
    <br/>

    <b:commandButton id = "btnLogin" class = "btn btn-success center-block" value = "#{msgs['loginForm.boton']}" action = "#{logBean.iniciarSesion}" update = "@form"/>

</h:form>

I discovered: context is Null.

context = FacesContext.getCurrentInstance();

Output exception:

Caused by: java.lang.NullPointerException
at beans.backing.LogBean.iniciarSesion(LogBean.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 36 more
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Juan C
  • 29
  • 3
  • Can you also show the related JSF XHTML code? – mjn Jun 05 '16 at 09:48
  • Which operation calls iniciarSesion()? I guess it will not work if the form has not yet been posted. – mjn Jun 05 '16 at 10:04
  • can you please share the evaluation exception that you are getting. – Aman Chhabra Jun 05 '16 at 10:12
  • I would actually look at `context` value. – Germann Arlington Jun 05 '16 at 10:30
  • Exactly, is context = FacesContext.getCurrentInstance(); What can I do? – Juan C Jun 05 '16 at 10:52
  • My application worked very good on context in a past version. I review and I discovered the solution: My button don't has binding="#{logBean.btnLogin}" , but I don't understand why it is the solution. Still my application show the alert, but it will be another question. Thanks to all. – Juan C Jun 05 '16 at 11:41

0 Answers0