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.
[code]<%@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”%>
</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>
[/code]
Erro quando executa ClienteFace.selectedCliente.nome = null;
[code]<%@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”%>
</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>
[/code]
Erro quando executa ClienteFace.selectedCliente.nome = null;
Venda
[code]<%–
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”%>
<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>
[/code]
venda.dao
[code]/*
- 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 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]
cliente.dao
/*
* 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"));
}
}