1. java
  2. android
  3. c#
  4. .net
  5. javascript
  6. php
  7. jquery
  8. html
  9. sql

java.lang.NullPointerException

sei que é um erro em algum lugar , alguém me ajuda pra identificar onde não estou inicializando esse objeto?

a stack do erro :

java.lang.NullPointerException
    at br.com.financeiro.bean.ContaBean.getLista(ContaBean.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:97)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:167)
    at org.apache.el.parser.AstEmpty.getValue(AstEmpty.java:46)
    at org.apache.el.parser.AstNot.getValue(AstNot.java:43)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:457)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1850)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at br.com.financeiro.dao.ConexaoHibernateFilter.doFilter(ConexaoHibernateFilter.java:41)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

stack do tomcat

26-Mar-2015 09:23:36.150 FATAL [http-nio-8080-exec-16] com.sun.faces.context.ExceptionHandlerImpl.log JSF1073: javax.el.ELException obtido durante o processamento de RENDER_RESPONSE 6: UIComponent-ClientId=, Message=/restrito/conta.xhtml @35,103 rendered="#{!empty contaBean.lista}": Error reading 'lista' on type br.com.financeiro.bean.ContaBean
26-Mar-2015 09:23:36.150 FATAL [http-nio-8080-exec-16] com.sun.faces.context.ExceptionHandlerImpl.log /restrito/conta.xhtml @35,103 rendered="#{!empty contaBean.lista}": Error reading 'lista' on type br.com.financeiro.bean.ContaBean
 javax.el.ELException: /restrito/conta.xhtml @35,103 rendered="#{!empty contaBean.lista}": Error reading 'lista' on type br.com.financeiro.bean.ContaBean
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:457)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1850)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at br.com.financeiro.dao.ConexaoHibernateFilter.doFilter(ConexaoHibernateFilter.java:41)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.ELException: Error reading 'lista' on type br.com.financeiro.bean.ContaBean
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:101)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:167)
    at org.apache.el.parser.AstEmpty.getValue(AstEmpty.java:46)
    at org.apache.el.parser.AstNot.getValue(AstNot.java:43)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    ... 66 more
Caused by: java.lang.NullPointerException
    at br.com.financeiro.bean.ContaBean.getLista(ContaBean.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:97)
    ... 73 more

ContaBean

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.financeiro.bean;

import br.com.financeiro.pojo.Conta;
import br.com.financeiro.rn.ContaRN;
import br.com.financeiro.util.ContextoUtil;
import java.util.LinkedList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;


/**
 *
 * @date 
 * @author Eliel
 * @email eliel.floyd@bol.com.br
 *
 */
@ManagedBean(name= "contaBean")
@RequestScoped
public class ContaBean {
    private Conta selecionada = new Conta();
    private List<Conta> lista = null;

    public ContaBean(){

    }

    public void salvar(){
        ContextoBean contextoBean = ContextoUtil.getContextBean();
        this.selecionada.setUsuario(contextoBean.getUsuarioLogado());
        ContaRN contaRN = new ContaRN();
        contaRN.salvar(this.selecionada);
        this.selecionada = new Conta();
        this.lista = null;
    }

    public void editar(){

    }

    public void excluir(){
        ContaRN contaRN = new ContaRN();
        contaRN.excluir(this.selecionada);
        this.selecionada = new Conta();
        this.lista = null;
    }

    public void tornarFavorita(){
        ContaRN contaRN = new ContaRN();
        contaRN.tornarFavorita(this.selecionada);
        this.selecionada = new Conta();
    }

    public Conta getSelecionada() {
        return selecionada;
    }

    public void setSelecionada(Conta selecionada) {
        this.selecionada = selecionada;
    }

    public List<Conta> getLista() {
        if(this.lista == null) {
            ContextoBean contextoBean = ContextoUtil.getContextBean();

            ContaRN contaRN = new ContaRN();
            this.lista = contaRN.listar(contextoBean.getUsuarioLogado());
        }
        return this.lista;
    }



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



}

contaDAO

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.financeiro.dao;

import br.com.financeiro.pojo.Conta;
import br.com.financeiro.pojo.Usuario;
import java.util.List;


/**
 *
 * @date 
 * @author Eliel
 * @email eliel.floyd@bol.com.br
 *
 */

public interface ContaDAO {

    public void salvar(Conta conta);
    public void excluir(Conta conta);
    public Conta carregar(Integer conta);
    public List<Conta> listar(Usuario usuario);
    public Conta buscarFavorita(Usuario usuario);
}

ContaDAOHibernate

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.financeiro.dao;

import br.com.financeiro.pojo.Conta;
import br.com.financeiro.pojo.Usuario;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;


/**
 *
 * @date 
 * @author Eliel
 * @email eliel.floyd@bol.com.br
 *
 */

public class ContaDAOHibernate implements ContaDAO{

    private Session session;

    public void setSession(Session session) {
        this.session = session;
    }

    public ContaDAOHibernate(){

    }

    @Override
    public void salvar(Conta conta) {
        this.session.saveOrUpdate(conta);
    }

    @Override
    public void excluir(Conta conta) {
        this.session.delete(conta);
    }

    @Override
    public Conta carregar(Integer conta) {
        return (Conta) this.session.get(Conta.class, conta);
    }

    @Override
    public List<Conta> listar(Usuario usuario) {
        Criteria criteria = this.session.createCriteria(Conta.class);
        criteria.add(Restrictions.eq("usuario" , usuario));
        return criteria.list();
    }

    @Override
    public Conta buscarFavorita(Usuario usuario) {
        Criteria criteria = this.session.createCriteria(Conta.class);
        criteria.add(Restrictions.eq("usuario", usuario));
        criteria.add(Restrictions.eq("favorita", true));
        return (Conta) criteria.uniqueResult();
    }
}

ContaRN

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.financeiro.rn;

import br.com.financeiro.dao.ContaDAO;
import br.com.financeiro.dao.DAOFactory;
import br.com.financeiro.pojo.Conta;
import br.com.financeiro.pojo.Usuario;
import java.util.Date;
import java.util.List;


/**
 *
 * @date 
 * @author Eliel
 * @email eliel.floyd@bol.com.br
 *
 */

public class ContaRN {

    private ContaDAO contaDAO;

    public ContaRN(){
        this.contaDAO = DAOFactory.criarContaDAO();
    }

    public List<Conta> listar(Usuario usuario) {
        return this.contaDAO.listar(usuario);
    }

    public Conta carregar(Integer conta) {
        return this.contaDAO.carregar(conta);
    }

    public void salvar(Conta conta) {
        conta.setDataCadastro(new Date());
        this.contaDAO.salvar(conta);
    }

    public void excluir(Conta conta) {
        this.contaDAO.excluir(conta);
    }

    public void tornarFavorita(Conta contaFavorita) {
        Conta conta = this.buscarFavorita(contaFavorita.getUsuario());
        if(conta != null) {
            conta.setFavorita(false);
            this.contaDAO.salvar(conta);
        }
        contaFavorita.setFavorita(true);
        this.contaDAO.salvar(contaFavorita);
    }

    public Conta buscarFavorita(Usuario usuario) {
        return this.contaDAO.buscarFavorita(usuario);
    }
}

Conta

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.financeiro.pojo;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;



/**
 *
 * @date 
 * @author Eliel
 * @email eliel.floyd@bol.com.br
 *
 */
@Entity
@Table(name="conta_bancaria")
public class Conta implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="cod_conta")
    private Integer conta;

    @ManyToOne
    @OnDelete(action=OnDeleteAction.CASCADE)
    @JoinColumn(name="cod_usuario" , nullable = false)
    private Usuario usuario;

    @Column(name = "des_conta")
    private String descricao;

    @Column(name="dat_cadastro" , nullable = false , updatable = false)
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataCadastro;

    @Column(name="saldo_inicial")
    private float saldoInicial;

    @Column(name="favorita")
    private boolean favorita;

    public Conta(){

    }

    public Integer getConta() {
        return conta;
    }

    public void setConta(Integer conta) {
        this.conta = conta;
    }

    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 Date getDataCadastro() {
        return dataCadastro;
    }

    public void setDataCadastro(Date dataCadastro) {
        this.dataCadastro = dataCadastro;
    }

    public float getSaldoInicial() {
        return saldoInicial;
    }

    public void setSaldoInicial(float saldoInicial) {
        this.saldoInicial = saldoInicial;
    }

    public boolean isFavorita() {
        return favorita;
    }

    public void setFavorita(boolean favorita) {
        this.favorita = favorita;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 43 * hash + Objects.hashCode(this.conta);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Conta other = (Conta) obj;
        if (!Objects.equals(this.conta, other.conta)) {
            return false;
        }
        return true;
    }


}

conta.xhtml

<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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>Cadastro de Contas</title>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    </h:head>
    <h:body>
        <h1>Cadastro de Contas</h1>

        <h:form id="edicao" >
            <h:messages/>
            <h:inputHidden value="#{contaBean.selecionada.conta}" />
            <h:inputHidden value="#{contaBean.selecionada.favorita}" />

            <h:panelGrid columns="2">
                <h:outputLabel value="Descrição :" for="descricao" />
                <h:inputText id="descricao" value="#{contaBean.selecionada.descricao}" required="true"
                             maxlength="45" />

                <h:outputLabel value="Saldo Incial :" for="saldoInicial" />
                <h:inputText id="saldoInicial" value="#{contaBean.selecionada.saldoInicial}" size="10" >
                       <f:convertNumber minFractionDigits="2" />
                </h:inputText>

                <h:commandButton value="Salvar" action="#{contaBean.salvar}" >
                    <f:ajax execute="@form" render=":edicao :listagem" />
                </h:commandButton>
            </h:panelGrid>
        </h:form>

        <h:form id="listagem">
            <h:dataTable value="#{contaBean.lista}" var="conta" rendered="#{!empty contaBean.lista}" >
                <h:column>
                    <f:facet name="header">Descrição</f:facet>
                    #{conta.descricao}
                </h:column>

                <h:column>
                    <f:facet name="header">Data Cadastro</f:facet>
                    <h:outputText value="#{conta.dataCadastro}">
                        <f:convertDateTime dateStyle="medium" />
                    </h:outputText>
                </h:column>

                <h:column>
                    <f:facet name="header">Saldo Inicial</f:facet>
                    <h:outputText value="#{conta.saldoInicial}" style="text-align: right; display: block;" >
                        <f:convertNumber minFractionDigits="2" />
                    </h:outputText>
                </h:column>

                <h:column>
                    <h:commandLink action="#{contaBean.tornarFavorita}" >
                        <f:ajax execute="@this" render=":listagem" />
                        <h:graphicImage library="imagens" name="favorita16_#{conta.favorita}.png" />
                        <f:setPropertyActionListener target="#{contaBean.selecionada}" value="#{conta}" />
                    </h:commandLink>
                </h:column>

                <h:column>
                    <h:commandLink>
                        <f:ajax execute="@this" render=":edicao" />
                        <h:graphicImage library="imagens" name="editar16.png" />
                        <f:setPropertyActionListener target="#{contaBean.selecionada}" value="#{conta}" />
                    </h:commandLink>
                </h:column>

                <h:column>
                    <h:commandLink action="#{contaBean.excluir}" >
                        <f:ajax execute="@this" render=":listagem" />
                        <h:graphicImage library="imagens" name="excluir16.png" />
                        <f:setPropertyActionListener target="#{contaBean.selecionada}" value="#{conta}" />
                    </h:commandLink>
                </h:column>

            </h:dataTable>
        </h:form>
    </h:body>
</html>
  1. Você vai ver essas setas em qualquer página de pergunta. Com elas, você pode dizer se uma pergunta ou uma resposta foram relevantes ou não.
  2. Edite sua pergunta ou resposta caso queira alterar ou adicionar detalhes.
  3. Caso haja alguma dúvida sobre a pergunta, adicione um comentário. O espaço de respostas deve ser utilizado apenas para responder a pergunta.
  4. Se o autor da pergunta marcar uma resposta como solucionada, esta marca aparecerá.
  5. Clique aqui para mais detalhes sobre o funcionamento do GUJ!

3 respostas

Não é a resposta que estava procurando? Procure outras perguntas com as tags java java-ee jsf hibernate ou faça a sua própria pergunta.