Error trying to insert data via JSF-Bean Error

Asked

Viewed 279 times

1

I’m starting to create a web application using JSF, but I try to insert some data through a form and it displays the error below:

/usuario.xhtml @19,72 value="#{usuarioBean.email}": Target Unreachable, Identifier 'usuarioBean' 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

Registration of Users

Registration of Users


    <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="User") @Requestscoped public class Usuariobean {

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:

inserir a descrição da imagem aqui

Someone can help me?

  • Next time I’ll do it with text. Thanks for the brother help.

  • Uses CDI bean, JSF bean ? created get/set for properties ? leverages and puts all manageBean.

  • Dilnei, use JSF bean

  • Use Maven? or add libs to the app’s classpath? can you add the information? @Request Scope comes from this import? import javax.faces.bean.RequestScoped;&#xA;

  • Dilnei, I don’t use Maven. I added libs to the classpath. I added lib img to the question. ’s annotation comes from this import: import javax.faces.bean.Requestscoped;

  • Worse than I’m not even able to debug, to check if he’s getting into the method. I’m a beginner, and I’m developing this application through an example from the book.

  • Sorry so many questions but if necessary, you have configured web.xml? and created the faces, faces-config.xml configuration file?

Show 2 more comments

1 answer

2

The problem is here:

@ManagedBean(name="UsuarioBean") 

By default, the name of the mbeans is the name of the class with the lowercase initial, but you have overridden it by indicating the uppercase initial. As you are calling "usuarioBean" on your page, mbean is not found as it has been named "Usuariobean". Change the name to "usuarioBean" and mbean will be accessible on the xhtml page.

  • I changed the bean, but gave the error below: Could not create the user managed bean. The following problems have been found: The parameter property for the user managed bean does not exist.

  • Giuliana I changed the name of the bean, and removed the snippet @Managedproperty(value="#{param}") private Map<String,String> parameters; , so thanks for the help.

  • Great! Mark as answered :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.