Problema no livro java para web

Java

03/05/2016

Estou com um problema de um livro de java para web. A mensagem de erro que aparece no navegador: usuario.xhtml @17,86 value="#{usuarioBean.nome}": Target Unreachable, identifier 'usuarioBean' resolved to null. Caso alguém queira que eu mande o projeto sinalize.
Davi Barros

Davi Barros

Curtidas 0

Respostas

Marcos Paulo

Marcos Paulo

03/05/2016

Qual o livro Davi? Explique com detalhes o problema.
GOSTEI 0
Davi Barros

Davi Barros

03/05/2016

O livro é de Java para web da novatec. Preencho o formulario usuario, e depois o mostrausuario não retorna os dados. Aparece o erro que postei ai no post na hora do submit. O projeto está em anexo, se puder olhar agradeço. Caso queira posso te mandar o projeto por e-mail.
GOSTEI 0
Marcos Paulo

Marcos Paulo

03/05/2016

Melhor postar o código, assim vão analisar e ajudar.
GOSTEI 0
Janaina Mendes

Janaina Mendes

03/05/2016

Daví, exponha os códigos, informe a quantidade suficiente de informações.
GOSTEI 0
Janaina Mendes

Janaina Mendes

03/05/2016

Daví, exponha os códigos, informe a quantidade suficiente de informações.
GOSTEI 0
Davi Barros

Davi Barros

03/05/2016

Página usuário:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Cadastro de Usuários</title>
</h:head>

<h:body>
<h1>Cadastro de Usuários</h1>
<hr />
<h:form acceptcharset="UTF-8">
<h:messages />
<h:panelGrid columns="2">
<h:outputLabel value="Nome:" for="nome" />
<h:inputText id="nome" label="Nome" value="#{usuarioBean.nome}" required="true" />
<h:outputLabel value="e-Mail:" for="email" />
<h:inputText id="email" label="e-Mail" value="#{usuarioBean.email}" />
<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>
</html>

Página mostrausuario:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Usuário cadastrado</title>
</h:head>
<h:body>
<h1>Usuário cadastrado</h1>
<hr/>
Nome: <h:outputText value="#{usuarioBean.nome}"/> <br/>
e-Mail: <h:outputLink value="mailto:#{usuarioBean.email}">
<h:outputText value="#{usuarioBean.email}"/>
</h:outputLink><br/>
Senha: <h:outputText value="#{usuarioBean.senha}"/><br/>
<hr/>
<h:form>
<h:commandLink action="index" value="Início"/>
</h:form>
</h:body>
</html>

Classe java:

package br.com.javaparaweb.teste.web;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;


@ManagedBean(name="usuarioBean")
@RequestScoped
public class UsuarioBean {
private String nome;
private String email;
private String senha;
private String confirmaSenha;

public String novo() {
return "usuario";
}
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";
}
// FUTURO - salva o usuário
return "mostrausuario";
}
public String getNome() {return nome;}
public void setNome(String nome) {this.nome = nome;}
public String getEmail() {return email;}
public void setEmail(String email) {this.email = email;}
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; }
}

Erro na tela ao enviar o formulário:

usuario.xhtml @17,86 value="#{usuarioBean.nome}": Target Unreachable, identifier 'usuarioBean' resolved to null

Podem me ajudar?
GOSTEI 0
Davi Barros

Davi Barros

03/05/2016

Página usuário:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Cadastro de Usuários</title>
</h:head>

<h:body>
<h1>Cadastro de Usuários</h1>
<hr />
<h:form acceptcharset="UTF-8">
<h:messages />
<h:panelGrid columns="2">
<h:outputLabel value="Nome:" for="nome" />
<h:inputText id="nome" label="Nome" value="#{usuarioBean.nome}" required="true" />
<h:outputLabel value="e-Mail:" for="email" />
<h:inputText id="email" label="e-Mail" value="#{usuarioBean.email}" />
<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>
</html>

Página mostrausuario:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Usuário cadastrado</title>
</h:head>
<h:body>
<h1>Usuário cadastrado</h1>
<hr/>
Nome: <h:outputText value="#{usuarioBean.nome}"/> <br/>
e-Mail: <h:outputLink value="mailto:#{usuarioBean.email}">
<h:outputText value="#{usuarioBean.email}"/>
</h:outputLink><br/>
Senha: <h:outputText value="#{usuarioBean.senha}"/><br/>
<hr/>
<h:form>
<h:commandLink action="index" value="Início"/>
</h:form>
</h:body>
</html>

Classe java:

package br.com.javaparaweb.teste.web;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;


@ManagedBean(name="usuarioBean")
@RequestScoped
public class UsuarioBean {
private String nome;
private String email;
private String senha;
private String confirmaSenha;

public String novo() {
return "usuario";
}
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";
}
// FUTURO - salva o usuário
return "mostrausuario";
}
public String getNome() {return nome;}
public void setNome(String nome) {this.nome = nome;}
public String getEmail() {return email;}
public void setEmail(String email) {this.email = email;}
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; }
}

Erro na tela ao enviar o formulário:

usuario.xhtml @17,86 value="#{usuarioBean.nome}": Target Unreachable, identifier 'usuarioBean' resolved to null

Podem me ajudar?
GOSTEI 0
Marcos Paulo

Marcos Paulo

03/05/2016

Usa as tags code, esses botões acima da caixa de texto.
GOSTEI 0
Marcos Paulo

Marcos Paulo

03/05/2016

Usa as tags code, esses botões acima da caixa de texto.
GOSTEI 0
Davi Barros

Davi Barros

03/05/2016

Página usuário:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html" 
xmlns:f="http://xmlns.jcp.org/jsf/core"> 
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Cadastro de Usuários</title>
</h:head>

<h:body>
<h1>Cadastro de Usuários</h1>
<hr />
<h:form acceptcharset="UTF-8"> 
<h:messages /> 
<h:panelGrid columns="2"> 
<h:outputLabel value="Nome:" for="nome" /> 
<h:inputText id="nome" label="Nome" value="#{usuarioBean.nome}" required="true" /> 
<h:outputLabel value="e-Mail:" for="email" />
<h:inputText id="email" label="e-Mail" value="#{usuarioBean.email}" />
<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>
</html>



Página mostrausuario:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Usuário cadastrado</title>
</h:head>
<h:body>
<h1>Usuário cadastrado</h1>
<hr/>
Nome:	<h:outputText value="#{usuarioBean.nome}"/> <br/>
e-Mail:	<h:outputLink value="mailto:#{usuarioBean.email}"> 
<h:outputText value="#{usuarioBean.email}"/>
</h:outputLink><br/>
Senha: <h:outputText value="#{usuarioBean.senha}"/><br/>
<hr/>
<h:form>
<h:commandLink action="index" value="Início"/>
</h:form>
</h:body>
</html>



Classe java:

package br.com.javaparaweb.teste.web;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;


@ManagedBean(name="usuarioBean")
@RequestScoped
public class UsuarioBean {
private String nome;
private String email;
private String senha;
private String confirmaSenha;

public String novo() { 
return "usuario";
}
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"; 
}
// FUTURO - salva o usuário
return "mostrausuario"; 
}
public String getNome() {return nome;}
public void setNome(String nome) {this.nome = nome;}
public String getEmail() {return email;}
public void setEmail(String email) {this.email = email;}
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; }
}


Erro na tela ao enviar o formulário:

usuario.xhtml @17,86 value="#{usuarioBean.nome}": Target Unreachable, identifier 'usuarioBean' resolved to null

Podem me ajudar?
GOSTEI 0
POSTAR