Error trying to insert data via JSF form- BEAN error

1

I'm starting to create a WEB application using JSF, however I try to insert some data through a form and the error below is displayed:

  

/usuario.xhtml @ 19.72 value="# {BlueEmail user"): Target   Unreachable, identifier 'userBean' resolved to null

My save method:

public String salvar(){
        FacesContext context = FacesContext.getCurrentInstance();
        if(!this.senha.equalsIgnoreCase(this.confirmaSenha)){
            context.addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR,"Senha confirmada incorretamente",""));
            return "usuario";
        }
        //salva usuario
        return "sucesso";           
    }

Xhtml Page

         User registration

    

User Registration

    
    <h:outputLabel value="e-Mail:" for="email" />
    <h:inputText id="email" label="email" value="#{usuarioBean.email}" />

    <h:outputLabel value="CPF:" for="cpf" />
    <h:inputText id="cpf" label="cpf" value="#{usuarioBean.cpf}" />

    <h:outputLabel value="Senha:" for="senha" />
    <h:inputSecret id="senha" label="Senha" value="#{usuarioBean.senha}" required="true"/>

    <h:outputLabel value="Confirmar Senha:" for="confirmarsenha" />
    <h:inputSecret id="confirmarSenha" label="Confirmar Senha" value="#{usuarioBean.confirmaSenha}" required="true" />

    <h:outputText/>
    <h:commandButton action="#{usuarioBean.salvar}" value="Salvar" />
 </h:panelGrid>
</h:form>
<hr />
</h:body>

My Bean Class:

@ManagedBean (name="UserBean") @RequestScoped public class UserBean {

private String nome;
private String cpf;
private String senha;
private String confirmaSenha;

@ManagedProperty(value="#{param}")
private Map<String,String> parametros;

//Método de Operação
public String operacao(){
    //executa a operação
    return "resultado";

}

public String novo(){
    return "usuario";
}

//Getters e Setters
public void setNome(String nome) {
    this.nome = nome;
}
public String getNome() {
    return nome;
}   
public String getCpf() {
    return cpf;
}
public void setEmail(String cpf) {
    this.cpf= cpf;
}
public String getSenha() {
    return senha;
}
public void setSenha(String senha) {
    this.senha = senha;
}
public String getConfirmaSenha() {
    return confirmaSenha;
}
public void setConfirmaSenha(String confirmaSenha) {
    this.confirmaSenha = confirmaSenha;
}

public String salvar(){
    FacesContext context = FacesContext.getCurrentInstance();
    if(!this.senha.equalsIgnoreCase(this.confirmaSenha)){
        context.addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR,"Senha confirmada incorretamente",""));
        return "usuario";
    }
    //salva usuario
    return "sucesso";           
}

}

Lib:

Can anyone help me?

    
asked by anonymous 24.09.2016 / 03:25

1 answer

2

The problem is here:

@ManagedBean(name="UsuarioBean") 

By default, the mbeans name is the name of the class with the lowercase initial, but you overwritten it by entering the initial capital letter. As you are calling "userBean" on your page, the mbean is not found because it has been named "UserBean". Modifies the name to "userBean" and the mbean will be accessible on the xhtml page.

    
24.09.2016 / 04:59