estou fazendo um sistema para uma corretor de seguro, mas estou sem saber como resolver os problemas que estao aparecendo.
addcliente,
addcorretor,
venda nao estou sabendo fazer.
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Palm Trees by Free CSS Templates</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href=".../style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="header">
<div id="menu">
<ul>
<li class="current_page_item"><a href="#">Homepage</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
<!-- end #menu -->
<div id="logo">
<h1><a href="#">Palm Trees </a></h1>
<h2>template design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a></h2>
</div>
<hr />
</div>
<!-- end #header -->
<!-- end #header-wrapper -->
<!-- end #logo -->
<div id="page">
<div id="page-bgtop">
<div id="page-bgbtm"></div>
<!-- end #content -->
<div style="clear: both;">
<f:view>
<h:form id="formulario">
<h:panelGrid >
<h:outputText value="Nome"/> <h:inputText value="#{ClienteFace.selectedCliente.nome}"/>
<h:outputText value="Endereço:"/> <h:inputText id="end" value="#{ClienteFace.selectedCliente.endereco}"/>
<h:outputText value="Telefone:"/> <h:inputText id="tel" value="#{ClienteFace.selectedCliente.telefone}"/>
<h:outputText value="CPFCNPJ:" /> <h:inputText id="cpfCnpj" value="#{ClienteFace.selectedCliente.cpfCnpj}"/>
<h:outputText value="TipodePessoa" /> <h:inputText id="TipoPessoa" value="#{ClienteFace.selectedCliente.tipoPessoa}"/>
<h:outputText value="Email" /> <h:inputText id="Email" value="#{ClienteFace.selectedCliente.email}"/>
<h:commandButton action="gotoCancelarCliente" value="Cancelar" />
<h:commandButton action="#{ClienteFace.startAddNovoCliente}"value="Gravar"/>
</h:panelGrid>
</h:form>
</f:view>
</div>
</div>
<!-- end #page -->
</div>
<div id="footer-bgcontent">
<div id="footer">
<p>Copyright (c) 2008 Sitename.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
</div>
<!-- end #footer -->
</div>
</body>
</html>
Erro quando executa ClienteFace.selectedCliente.nome = null;
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Palm Trees by Free CSS Templates</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href=".../style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="header">
<div id="menu">
<ul>
<li class="current_page_item"><a href="#">Homepage</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
<!-- end #menu -->
<div id="logo">
<h1><a href="#">Palm Trees </a></h1>
<h2>template design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a></h2>
</div>
<hr />
</div>
<!-- end #header -->
<!-- end #header-wrapper -->
<!-- end #logo -->
<div id="page">
<div id="page-bgtop">
<div id="page-bgbtm"></div>
<!-- end #content -->
<div style="clear: both;">
<f:view>
<h:form id="formulario">
<h:panelGrid >
<h:outputText value="Nome"/> <h:inputText value="#{CorretorFace.selectedCorretor.nome}"/>
<h:outputText value="Endereço:"/> <h:inputText id="end" value="#{CorretorFace.selectedCorretor.endereco}"/>
<h:outputText value="Telefone:"/> <h:inputText id="tel" value="#{CorretorFace.selectedCorretor.telefone}"/>
<h:outputText value="CPFCNPJ:" /> <h:inputText id="cpfCnpj" value="#{CorretorFace.selectedCorretor.cpfCnpj}"/>
<h:outputText value="TipodePessoa" /> <h:inputText id="TipoPessoa" value="#{CorretorFace.selectedCorretor.tipoPessoa}"/>
<h:outputText value="Email" /> <h:inputText id="Email" value="#{CorretorFace.selectedCorretor.email}"/>
<h:commandButton action="gotoCancelarCorretor" value="Cancelar" />
<h:commandButton action="#{CorretorFace.finishAddNovoCorretor}"value="Gravar"/>
</h:panelGrid>
</h:form>
</f:view>
</div>
</div>
<!-- end #page -->
</div>
<div id="footer-bgcontent">
<div id="footer">
<p>Copyright (c) 2008 Sitename.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
</div>
<!-- end #footer -->
</div>
</body>
</html>
Erro quando executa ClienteFace.selectedCliente.nome = null;
Venda
<%--
Document : login
Created on : 20/04/2011, 11:40:49
Author : Brunno
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Sistema Para Corretores de Seguro</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="file:///C|/Users/Brunno/Downloads/ProjetoJSF/ProjetoJSF/style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="header">
<div id="menu">
<ul>
<li class="current_page_item"><a href="#">Sistema</a></li>
</ul>
</div>
<!-- end #menu -->
<div id="logo">
<h1><a href="#">Sistema para Corretores de Seguros</a></h1>
</div>
<hr />
</div>
<div id="page">
<f:view>
<h1>Venda</h1>
<h:form>
<h:dataTable var="1" var="item" value="#{VendaFace.seguro}">
<f:facet name="beader">
<h:outputText value="Cod"/>
</f:facet>
<h:outputText value="#{VendaFace.code}"/>
<h:outputText value="#{VendaFace.cliente}"/>
<h:outputText value="#{VendaFace.corretor}"/>
<h:outputText value="#{VendaFace.seguro}"/>
</h:dataTable>
</h:form>
</f:view>
</div>
</body>
</html>
venda.dao
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package model.dao;
import model.bean.Venda;
import controller.conexao.DatabaseUtil;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
/**
*
* @author Brunno
*/
public class VendaDAO extends DatabaseUtil{
private static VendaDAO instanciaUnica = null;
private SeguroDAO seguro = SeguroDAO.getInstancia();
private ClienteDAO cliente = ClienteDAO.getInstancia();
private CorretorDAO corretor = CorretorDAO.getInstancia();
private VendaDAO() {
super();
}
public static VendaDAO getInstancia() {
if (instanciaUnica == null) {
instanciaUnica = new VendaDAO();
}
return instanciaUnica;
}
public boolean inserirVenda(Venda venda) {
try {
PreparedStatement ps = (PreparedStatement) getPreparedStatement("insert into Venda (CodCliente,CodSeguro,CodCorretor,DataCadastro,FormaPagamento,QtdParcela) values (?,?,?,?,?,?) ");
ps.setInt( 1, venda.getCliente().getCodigo());
ps.setInt( 2, venda.getSeguro().getCodSeguro());
ps.setInt( 3, venda.getCorretor().getCodigo());
ps.setDate(4, venda.getDataCadastro());
ps.setInt( 5, venda.getFormaPagamento());
ps.setInt( 6, venda.getQtdParcela());
ps.executeQuery();
} catch (Exception e) {
System.err.println("Erro:" + e.getMessage());
return false;
}
return true;
}
public List<Venda> retornaListaVenda() {
List<Venda> lista = new LinkedList<Venda>();
try {
PreparedStatement ps = (PreparedStatement) getPreparedStatement("SELECT Venda.* from Venda");
ResultSet rs = (ResultSet) ps.executeQuery();
while (rs.next()) {
Venda v = new Venda();
preencheVenda(v, rs);
lista.add(v);
}
} catch (Exception e) {
System.out.println(e);
}
return lista;
}
public List retornaListaSeguroPorCliente(int codCliente) {
List<Venda> lista = new LinkedList<Venda>();
try {
PreparedStatement ps = (PreparedStatement) getPreparedStatement("SELECT Venda.* from Venda where CodCliente=?");
ps.setInt(1, codCliente);
ResultSet rs = (ResultSet) ps.executeQuery();
while (rs.next()) {
Venda v = new Venda();
preencheVenda(v, rs);
lista.add(v);
}
} catch (Exception e) {
System.out.println(e);
}
return lista;
}
public boolean cancelarVenda(int codVenda) {
try {
PreparedStatement ps = (PreparedStatement) getPreparedStatement("Update Venda set Situacao=1 where CodVenda=?");
ps.setInt(1, codVenda);//prepara para o comando
ps.executeUpdate();//envia comandos
} catch (Exception e) {
System.err.println("Erro:" + e.getMessage());
return false;
}
return true;
}
public Venda consultarVenda(int codVenda) {
Venda v = new Venda();
try {
PreparedStatement ps = (PreparedStatement) getPreparedStatement("SELECT Venda.* from Venda where CodVenda=? ");
ps.setInt(1, codVenda);
ResultSet rs = (ResultSet) ps.executeQuery();
if (rs.next()) {
preencheVenda(v, rs);
}
} catch (Exception e) {
System.err.println(e.getMessage());
v = null;
}
return v;
}
public void preencheVenda(Venda v, ResultSet rs) throws SQLException{
v.setCodVenda(rs.getInt("CodVenda"));
v.setCliente(cliente.consultarCliente(rs.getInt("CodSeguro")));
v.setCorretor(corretor.consultarCorretor(rs.getInt("CodCorretor")));
v.setSeguro(seguro.consultarSeguro(rs.getInt("CodSeguro")));
v.setDataCadastro(rs.getDate("DataCadastro"));
v.setFormaPagamento(rs.getInt("FormaPagamento"));
v.setQtdParcela(rs.getInt("QtdParcela"));
v.setSituacao(rs.getInt("Situacao"));
}
}
[code]
[b]cliente.dao[/b]
[code]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package model.dao;
import model.bean.Corretor;
import controller.conexao.ConexaoBD;
import controller.conexao.DatabaseUtil;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
/**
*
* @author Brunno
*/
public class CorretorDAO extends DatabaseUtil{
private static CorretorDAO instanciaUnica = null;
private CorretorDAO () {
}
public static CorretorDAO getInstancia() {
if (instanciaUnica == null) {
instanciaUnica = new CorretorDAO();
}
return instanciaUnica;
}
public List<Corretor> retornaListaCorretor() {
List<Corretor> lista = new LinkedList<Corretor>();
try {
PreparedStatement ps = (PreparedStatement) getPreparedStatement("SELECT corretor.CR,pessoa.* from corretor inner join Pessoa on (Pessoa.codigo = Corretor.codCorretor)");
ResultSet rs = (ResultSet) ps.executeQuery();
while (rs.next()) {
Corretor c = new Corretor();
preencheCorretor(c, rs);
lista.add(c);
}
} catch (Exception e) {
System.out.println(e);
}
return lista;
}
public boolean inserirCorretor(Corretor corretor) {
try {
PreparedStatement ps = (PreparedStatement) getPreparedStatement("insert into Pessoa (nome,cpfCnpj,telefone,endereco,email,tipoPessoa) values (?,?,?,?,?,?) Select MAX(codigo) as codPessoa From Pessoa");
ps.setString(1, corretor.getNome());
ps.setString(2, corretor.getCpfCnpj());
ps.setString(3, corretor.getTelefone());
ps.setString(4, corretor.getEndereco());
ps.setString(5, corretor.getEmail());
ps.setInt( 6, corretor.getTipoPessoa());
ResultSet rs = (ResultSet) ps.executeQuery();
int i = 0;
if (rs.next()) {
i = rs.getInt("codCorretor");
}
ps = (PreparedStatement) getPreparedStatement("insert into Corretor (codPessoa,cr) values (?,?)");
ps.setInt(1, i);
ps.setInt(2, corretor.getCr());
ps.executeQuery();
} catch (Exception e) {
System.err.println("Erro:" + e.getMessage());
return false;
}
return true;
}
public boolean excluirCorretor(int codCorretor) {
try {
PreparedStatement ps = (PreparedStatement) ConexaoBD.conexao().prepareStatement("delete from Pessoa where CodPessoa=?");
ps.setInt(1, codCorretor);//prepara para o comando
ps.executeUpdate();//envia comandos
} catch (Exception e) {
System.err.println("Erro:" + e.getMessage());
return false;
}
return true;
}
public Corretor consultarCorretor(int codCorretor) {
Corretor c = new Corretor();
try {
PreparedStatement ps = (PreparedStatement) ConexaoBD.conexao().prepareStatement("SELECT Corretor.*,Pessoa.* from Corretor inner join Pessoa on (Pessoa.codigo = Corretor.CodCorretor) where codCorretor? ");
ps.setInt(1, codCorretor);
ResultSet rs = (ResultSet) ps.executeQuery();
if (rs.next()) {
preencheCorretor(c, rs);
}
} catch (Exception e) {
System.err.println(e.getMessage());
c = null;
}
return c;
}
public boolean alterarCorretor(Corretor corretor) {
try {
PreparedStatement ps = (PreparedStatement) getPreparedStatement("update Corretor set cr=? where codPessoa=?");
ps.setInt(1, corretor.getCr());
ps.setInt(2, corretor.getCodigo());
ps.executeUpdate();
ps = (PreparedStatement) ConexaoBD.conexao().prepareStatement("update Pessoa set nome=?,cpfCnpj=?,endereco=?,telefone=?,email=?,TipoPessoa=? where codigo=?");
ps.setString(1, corretor.getNome());
ps.setString(2, corretor.getCpfCnpj());
ps.setString(3, corretor.getEndereco());
ps.setString(4, corretor.getTelefone());
ps.setString(5, corretor.getEmail());
ps.setInt(6, corretor.getTipoPessoa());
ps.setInt(7, corretor.getCodigo());
ps.executeUpdate();
} catch (Exception e) {
System.err.println("Erro:" + e.getMessage());
return false;
}
return true;
}
public void preencheCorretor(Corretor c, ResultSet rs) throws SQLException{
c.setCodigo(rs.getInt("codPessoa"));
c.setNome(rs.getString("nome"));
c.setCpfCnpj(rs.getString("cpfCnpj"));
c.setEmail(rs.getString("email"));
c.setTelefone(rs.getString("telefone"));
c.setTipoPessoa(rs.getInt("TipoPessoa"));
c.setCr(rs.getInt("cr"));
}
}