Erro no jsf

9 respostas
rdgms

Aew eu tenho um formulario html aonde eu quero cadastrar uma pessoa so que eu quero acadastrar a pessoa atraves de uma classe DAO
mas ou menos assim:

<f:view>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h:form>
            <h:inputText value="#{DAOPessoa.pessoa.nome}" />
            <h:commandButton value="Cadastrar" action="#{DAOPessoa.cadastrar}" />
        </h:form>
    </body>
</html>
</f:view>

Minha classe pessoa

public class Pessoa {

    private String nome;

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }
    
}

MInha dao:

public class DAOPessoa {

   
  Pessoa pessoa;

  
    
    public void cadastrar()
    {
      System.out.println("O nome é "+ pessoa.getNome());
    }

}

E o XML:

<navigation-rule>
      <from-view-id>/welcomeJSF.jsp</from-view-id>
  </navigation-rule>

  <managed-bean>
      <managed-bean-name>DAOPessoa</managed-bean-name>
      <managed-bean-class>br.projeto.DAOPessoa</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
  </managed-bean>

E esta aparecendo o seguinte erro:

javax.servlet.ServletException: The class ‘br.projeto.DAOPessoa’ does not have the property ‘pessoa’.

9 Respostas

furutani

Acho que você se esqueceu de criar os get/set do atributo Pessoa da classe DAOPessoa

rdgms

Sim… mas mesmo se eu colocar o get/set para a pessoa ele nao consegue setar o nome.

javax.servlet.ServletException: Target Unreachable, ‘pessoa’ returned null

foxpv

agora vc tah conseguindo acessar o objeto pessoa, mas ele está nulo, e por isso n consegue acessar os atributos…

rdgms

Isso eu sei , eu gostaria de saber se eu preciso configurar alguma coisa tipo faces-config.xml…
Porque ja é estranho eu colocar o get/set
para a Pessoa ja que na classe pessoa ja possui os get/set .

VLW AJUDA!!..

furutani

rdgms:
Isso eu sei , eu gostaria de saber se eu preciso configurar alguma coisa tipo faces-config.xml…
Porque ja é estranho eu colocar o get/set
para a Pessoa ja que na classe pessoa ja possui os get/set .

VLW AJUDA!!..


Pelo que eu entendi do seu código, só existia get/set para os atributos da classe Pessoa, na classe PessoaDAO tinha que ter para os atributos dela.

rdgms

Mas para pessoa ja possuo get/set eu terei que fazer outro get/set para os atributos da pessoa como nome ???

alexberia

Oi… sem querer ser chato… masss…

se vc estanciar a classe pessoa dentro da sua DAO… e criar os gets/sets para tal…

Eu… acho q funfa a bagaça :stuck_out_tongue:

creiu eu q o erro q estava dando era por isso… pq diferentemente do java… q tudo eh objeto… o jsf nao reconheceu a pessoa como tal… sem estanciar.

depois me fala se deu certo :roll:

flw

rdgms

Opa… voce acredita que antes de entrar eu fiz isso é funcionou kkkk
mas vlw brother pela ajuda…

FLW :smiley:

R

Ola estou começando tb e estou com esse mesmo problema nao sei como resolver…alguem poderia por gentileza dar uma força?

erro:
javax.servlet.ServletException: javax.servlet.ServletException: /publico/projeto.xhtml @34,99 value="#{projetoBean.projeto.detalhamento}": The class ‘financeiro.projeto.Projeto’ does not have the property ‘detalhamento’.

ProjetoBean

package financeiro.web;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import financeiro.projeto.Projeto;

import financeiro.projeto.ProjetoRN;

import financeiro.util.ContextoUtil;
@ManagedBean(name=projetoBean)

@RequestScoped

public class ProjetoBean {
private Projeto projeto	= new Projeto();
private List<Projeto> lista = null;
private String destinoSalvar;


public void salvar() {
	ContextoBean contextobean = ContextoUtil.getContextoBean();
	this.projeto.setUsuario(contextobean.getUsuarioLogado());
	ProjetoRN projetoRN = new ProjetoRN();
	projetoRN.salvar(this.projeto);
	this.projeto = new Projeto();
	this.lista = null;
}

public String excluir(){
	ProjetoRN projetoRN = new ProjetoRN();
	projetoRN.excluir(this.projeto);
	this.lista = null;
	return null;
}

public List<Projeto> getLista() {
	if(this.lista == null){
		ProjetoRN projetoRN = new ProjetoRN();
		this.lista = projetoRN.listar();
	}
	return this.lista;
}

public void setLista(List<Projeto> lista) {
	this.lista = lista;
}

public Projeto getProjeto() {
	return this.projeto;
}

public void setProjeto(Projeto projeto) {
	this.projeto = projeto;
}

public String getDestinoSalvar() {
	return destinoSalvar;
}

public void setDestinoSalvar(String destinoSalvar) {
	this.destinoSalvar = destinoSalvar;
}

}

Projeto:

package financeiro.projeto;

import <a href="http://java.io">java.io</a>.<em>;

import java.util.</em>;

import javax.persistence.*;

import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import financeiro.usuario.Usuario;

@Entity
public class Projeto implements Serializable{

@Id
@GeneratedValue
@org.hibernate.annotations.NaturalId
private Integer codigo;

@ManyToOne
@OnDelete(action=OnDeleteAction.CASCADE)
@JoinColumn(name = "codSolicitante", nullable = true)
private Usuario usuario;
private String descricao;
private String status;
@Column(name="dtCadastro", nullable = true, updatable = false)
private Date dtCadastro;



private String detalhamento;
/*private String receberproposta;
private String orcamento;
private String prazo;
private String tecnologia;
private String plataforma;
private String linguagem;*/



public Integer getCodigo() {
	return codigo;
}



public void setCodigo(Integer codigo) {
	this.codigo = codigo;
}



public Usuario getUsuario() {
	return usuario;
}



public void setUsuario(Usuario usuario) {
	this.usuario = usuario;
}



public String getDescricao() {
	return descricao;
}



public void setDescricao(String descricao) {
	this.descricao = descricao;
}



public String getStatus() {
	return status;
}



public void setStatus(String status) {
	this.status = status;
}



public Date getDtCadastro() {
	return dtCadastro;
}



public void setDtCadastro(Date dtCadastro) {
	this.dtCadastro = dtCadastro;
}



public String getDetalhamento() {
	return detalhamento;
}



public void setDetalhamento(String detalhamento) {
	this.detalhamento = detalhamento;
}



@Override
public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + ((codigo == null) ? 0 : codigo.hashCode());
	result = prime * result
			+ ((descricao == null) ? 0 : descricao.hashCode());
	result = prime * result
			+ ((detalhamento == null) ? 0 : detalhamento.hashCode());
	result = prime * result
			+ ((dtCadastro == null) ? 0 : dtCadastro.hashCode());
	result = prime * result + ((status == null) ? 0 : status.hashCode());
	result = prime * result + ((usuario == null) ? 0 : usuario.hashCode());
	return result;
}



@Override
public boolean equals(Object obj) {
	if (this == obj)
		return true;
	if (obj == null)
		return false;
	if (getClass() != obj.getClass())
		return false;
	Projeto other = (Projeto) obj;
	if (codigo == null) {
		if (other.codigo != null)
			return false;
	} else if (!codigo.equals(other.codigo))
		return false;
	if (descricao == null) {
		if (other.descricao != null)
			return false;
	} else if (!descricao.equals(other.descricao))
		return false;
	if (detalhamento == null) {
		if (other.detalhamento != null)
			return false;
	} else if (!detalhamento.equals(other.detalhamento))
		return false;
	if (dtCadastro == null) {
		if (other.dtCadastro != null)
			return false;
	} else if (!dtCadastro.equals(other.dtCadastro))
		return false;
	if (status == null) {
		if (other.status != null)
			return false;
	} else if (!status.equals(other.status))
		return false;
	if (usuario == null) {
		if (other.usuario != null)
			return false;
	} else if (!usuario.equals(other.usuario))
		return false;
	return true;
}

}

XHTML

<h:outputLabel value="Detalhamento do Projeto:" for="detalhamento"/>	
			<h:inputTextarea id="textArea" rows="4" cols="23" value="#{projetoBean.projeto.detalhamento}">
			</h:inputTextarea>
Criado 15 de janeiro de 2009
Ultima resposta 31 de ago. de 2011
Respostas 9
Participantes 5