0

I'm getting the error:

com.sun.faces.mgbean.ManagedBeanCreationException: No se puede crear el bean administrado loginBean.  
Se han encontrado los problemas siguientes:- No se encuentra el bean o la clase de propiedad com.pf.mbean.loginBean para el bean administrado loginBean.

In english it would be something like:

Cannot create management bean loginBean there are found following troubles: Cannot find bean or property class com.pf.mbean.loginBean for the managment bean loginBean

My bean is the following:

    package com.pf.mbean;
import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.http.HttpSession;
import org.primefaces.context.RequestContext;

@ManagedBean(name="loginBean")
public class loginBean implements Serializable 
{
    private static final long serialVersionUID = -2152389656664659476L;
    private String nombre;
    private String clave;
    private boolean logeado = false;

    public boolean estaLogeado() 
    {
        return logeado;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getClave() {
        return clave;
    }

    public void setClave(String clave) {
        this.clave = clave;
    }

    public boolean isLogeado() {
        return logeado;
    }

    public void setLogeado(boolean logeado) {
        this.logeado = logeado;
    }

    public void login(ActionEvent actionEvent) 
    {
        RequestContext context = RequestContext.getCurrentInstance();
        FacesMessage msg = null;
        if (nombre != null && nombre.equals("admin") && clave != null && clave.equals("admin")) 
        {
            logeado = true;
            msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Bienvenido: ", nombre);
        } 
        else 
        {
            logeado = false;
            msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error","Credenciales no válidas");
        }
        FacesContext.getCurrentInstance().addMessage(null, msg);
        context.addCallbackParam("estaLogeado", logeado);
        if (logeado)
            context.addCallbackParam("view", "gauge.xhtml");
    } 

    public void logout() 
    {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        session.invalidate();
        logeado = false;
    }
}

And my faces-config.xml I have set the following configuration:

<managed-bean>
    <managed-bean-name>loginBean</managed-bean-name>
    <managed-bean-class>com.pf.mbean.loginBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope> </managed-bean>

In my login.xhtml I'm refer to the bean at this way:

<p:inputText value="#{loginBean.nombre}" id="username"
                         required="true" label="username" />
                      <h:outputLabel for="password" value="Clave:" />
                    <p:password value="#{loginBean.clave}" id="password" required="true"
                       label="password" />

But I have no idea why the class has not been found, any idea?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
angelreyes17
  • 81
  • 1
  • 1
  • 5
  • Classes should always be capitalized (just the class name, not the managed bean name) – Jaqen H'ghar Dec 04 '16 at 21:05
  • You should use annotations ^ faces-config but not both. Add `@SessionScoped` to your MB and remove the `` element from faces-config. see: http://stackoverflow.com/a/5090914/2940051 Also, be careful with naming conventions: http://www.oracle.com/technetwork/java/codeconventions-135099.html Try changing your CLASS to LoginBean, and fix the ` – Esteban Rincon Dec 04 '16 at 22:47

0 Answers0