O framework que estou usando é o Struts.
Vou postar aqui a minha action, o DAO e a JSP aqui para ver se vcs podem me ajudar melhor.
Agradeço desde já,
Vitor
Action:
/**
*
* Inclui um PDV caso o código não esteja preenchido.
* Altera um PDV caso o código esteja preenchido.
* Atualiza o status na tabela de faixas de PDV.
*
* @return cadPDV.jsp.
*/
public ActionForward executaInclusao(ActionMapping actionmapping, ActionForm actionform, HttpServletRequest request, HttpServletResponse httpservletresponse)
throws Exception {
CadPDVDAO pdvDAO = new CadPDVDAO();
CadPDVFaixaDAO pdvFaixaDAO = new CadPDVFaixaDAO();
CadPDVForm pdvForm = (CadPDVForm) actionform;
ActionMessages messages= new ActionMessages();
if ((pdvForm.getCodigo() == null) || (pdvForm.getCodigo().equals(""))){
String novo_sIdAgenteVenda = pdvDAO.incluir(pdvForm);
if (novo_sIdAgenteVenda!= null){
pdvFaixaDAO.alterar(novo_sIdAgenteVenda,1);//Tabela de Faixas
pdvForm.setCodigoHidden(novo_sIdAgenteVenda);
//pdvForm.setCodigo(novo_sIdAgenteVenda);
log.debug("CadPDVAction.executaInclusao.");
log.debug("CadPDVAction.executaInclusao:" + novo_sIdAgenteVenda);
messages.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("msn.gravar"));
} else{
messages.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("errors.gravar"));
}
}
else{
if (pdvDAO.alterar(pdvForm))
messages.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("msn.alterar"));
else
messages.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("errors.gravar.alterar"));
}
executaPesquisa(actionmapping, actionform, request, httpservletresponse);
saveMessages(request.getSession(), messages);
return actionmapping.findForward("success");
}
DAO:
public String incluir(CadPDVForm cadPDVForm){
String retorno = null;
try{
Connection con = getConnection();
UtilitarioDAO utilDAO = new UtilitarioDAO();
pstm = con.prepareStatement("INSERT INTO tblAGENTECANALVENDA (sNomeAgenteVenda, " +
"sUsuarioCadastro , dDataCadastro,bStatus,nIDRegiao,ENDER,BAIRRO, " +
"CIDADE,UF,COD_GR,COD_GC,nidREDE) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");
//pstm.setString(1,retorno);
pstm.setString(1,cadPDVForm.getPdv());
pstm.setString(2,Utilitario.USUARIO);
pstm.setString(3,utilDAO.getdata());
String ativo = cadPDVForm.getAtivo();
if (ativo == null)
ativo = "0";
else
ativo = "1";
pstm.setString(4, ativo);
pstm.setString(5, cadPDVForm.getRegiao());
pstm.setString(6, cadPDVForm.getEndereco());
pstm.setString(7, cadPDVForm.getBairro());
pstm.setString(8, cadPDVForm.getCidade());
pstm.setString(9, cadPDVForm.getUf());
pstm.setString(10, cadPDVForm.getGerenteregional());
pstm.setString(11, cadPDVForm.getGerenteconta());
pstm.setString(12, cadPDVForm.getCodrede());
int linhas = pstm.executeUpdate();
if (linhas > 0){
retorno = getIdAgenteVenda();
}
log.info(util.USUARIO + ":" +
retorno + ";" +
cadPDVForm.getRegiao() + ":" + linhas);
}catch(SQLException sqlException){
log.error("sqlException: "+ sqlException);
sqlException.printStackTrace();
}catch(Exception e){
log.error("Exception: "+ e);
e.printStackTrace();
}finally{
rsClose();
pstmClose();
try{
close(con);
}catch(IOException ioException){
log.error("ioException: "+ ioException);
ioException.printStackTrace();
}
}
return retorno;
}
JSP:
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Cadastro de P.D.V.</title>
<link REL="stylesheet" TYPE="text/css" HREF="<html:rewrite page="/jsp/css/raa.css"/>"/>
<link REL="stylesheet" TYPE="text/css" HREF="<html:rewrite page="/jsp/css/displaytag.css"/>"/>
<script language="javascript">
function submeter(metodo)
{
document.cadPDVForm.action='cadPDV.do?method='+metodo;
document.cadPDVForm.submit();
}
function limpaCampos(){
for (i=0;i<document.cadPDVForm.elements.length;i++)
if(document.cadPDVForm.elements[i].type == "checkbox")
document.cadPDVForm.elements[i].checked=0;
document.cadPDVForm.codigo.value = "";
document.cadPDVForm.pdv.value = "";
document.cadPDVForm.producao.value = "";
document.cadPDVForm.endereco.value = "";
document.cadPDVForm.bairro.value = "";
document.cadPDVForm.cidade.value = "";
document.cadPDVForm.rede.value = "";
document.cadPDVForm.uf.selectedIndex = 0;
document.cadPDVForm.regiao.selectedIndex = 0;
document.cadPDVForm.gerenteconta.selectedIndex = 0;
document.cadPDVForm.gerenteregional.selectedIndex = 0;
document.cadPDVForm.codrede.selectedIndex = 0;
}
function fnRetornarRegistroSelecionadoGrid(codigo,pdv,REGIAO,rede,dataProd,bStatus,ENDER,BAIRRO,CIDADE,UF,GERC,GERR,codrede)
{
document.cadPDVForm.codigo.value = codigo;
document.cadPDVForm.pdv.value = pdv;
document.cadPDVForm.rede.value = rede;
if (bStatus == 0)
document.cadPDVForm.ativo.checked = false;
else
document.cadPDVForm.ativo.checked = true;
document.cadPDVForm.producao.value = dataProd;
document.cadPDVForm.endereco.value = ENDER;
document.cadPDVForm.bairro.value = BAIRRO;
document.cadPDVForm.cidade.value = CIDADE;
document.cadPDVForm.uf.selectedIndex = 0;
for(var i = 0; i < document.cadPDVForm.uf.length; i++){
if ((document.cadPDVForm.uf.options[i].value==UF)) {
document.cadPDVForm.uf.selectedIndex = i;
}
}
document.cadPDVForm.regiao.selectedIndex = 0;
for(var i = 0; i < document.cadPDVForm.regiao.length; i++){
if ((document.cadPDVForm.regiao.options[i].value==REGIAO)) {
document.cadPDVForm.regiao.selectedIndex = i;
}
}
document.cadPDVForm.gerenteconta.selectedIndex = 0;
for(var i = 0; i < document.cadPDVForm.gerenteconta.length; i++){
if ((document.cadPDVForm.gerenteconta.options[i].value==GERC)) {
document.cadPDVForm.gerenteconta.selectedIndex = i;
}
}
document.cadPDVForm.gerenteregional.selectedIndex = 0;
for(var i = 0; i < document.cadPDVForm.gerenteregional.length; i++){
if ((document.cadPDVForm.gerenteregional.options[i].value==GERR)) {
document.cadPDVForm.gerenteregional.selectedIndex = i;
}
}
document.cadPDVForm.codrede.selectedIndex = 0;
for(var i = 0; i < document.cadPDVForm.codrede.length; i++){
if ((document.cadPDVForm.codrede.options[i].value==codrede)) {
document.cadPDVForm.codrede.selectedIndex = i;
}
}
}
function checar(){
//alert(document.getElementById("comissionar").value);
if(document.getElementById("ativo").checked){
document.getElementById("ativo").value="1";
}else{
document.getElementById("ativo").value="0";
}
//alert(document.getElementById("comissionar").value);
}
</script>
</HEAD>
<body vLink="black" aLink="black" link="black" bgColor="#4891c6">
<html:form action="cadPDV.do">
<TABLE STYLE="BORDER-COLLAPSE: COLLAPSE" BORDERCOLOR="#111111" width="735" bgColor="#dceaf5" border="0">
<TBODY>
<TR>
<TD bgColor="#4891c6" colSpan="6" height="15">
<p align="center">
<font face="Verdana" color="#ffffff" size="1">
<b>CADASTRO DE PDV´s</b>
</font>
</p>
</TD>
</TR>
<TR>
<TD width="147" bgColor="#dceaf5" height="11">
<font face="verdana" color="#336699" size="1">Código:</font>
</TD>
<TD width="100" bgColor="#dceaf5" height="11">
<html:hidden property="codigoHidden"/>
<html:text property="codigo"/>
</TD>
<TD width="40" bgColor="#dceaf5" height="11"></TD>
<TD colspan="3">
<font face="verdana" color="#336699" size="1">Ativo: </font>
<html:checkbox property="ativo"/>
</TD>
</TR>
<TR>
<TD bgColor="#dceaf5" height="22">
<font id="PDV" face="verdana" color="#336699" size="1"> P.D.V.:</font>
</TD>
<TD bgColor="#dceaf5" height="22" colspan="2">
<html:text property="pdv" size="60"/>
</TD>
<TD bgColor="#dceaf5" height="22">
<font face="verdana" color="#336699" size="1">Região:</font>
<html:select property="regiao" styleClass="combo">
<html:option value="0">*</html:option>
<c:forEach var="listaregiao" items="${lstRegiao}">
<html:option value="${listaregiao.nidregiao}" >${listaregiao.sdescricaoregiao}</html:option>
</c:forEach>
</html:select>
</TD>
<TD bgColor="#dceaf5" height="22" ></TD>
<TD bgColor="#dceaf5" height="22" ></TD>
</TR>
<TR>
<TD bgColor="#dceaf5" height="20">
<font face="verdana" color="#336699" size="1">Endereço:</font>
</TD>
<TD bgColor="#dceaf5" height="20" colspan="3">
<html:text property="endereco" size="80"/>
</TD>
</TR>
<TR>
<TD bgColor="#dceaf5" height="6">
<font id="lblbairro" face="verdana" color="#336699" size="1">Bairro:</font>
</TD>
<TD bgColor="#dceaf5" height="6">
<html:text property="bairro" size="38"/>
</TD>
<TD bgColor="#dceaf5" height="6">
<font id="lblcidade" face="verdana" color="#336699" size="1">Cidade:</font>
</TD>
<TD bgColor="#dceaf5" height="11">
<html:text property="cidade" size="25"/>
</TD>
<TD>
<font id="lbluf" face="verdana" color="#336699" size="1">UF:</font>
</TD>
<TD>
<html:select property="uf" styleClass="combo">
<html:option value="0">*</html:option>
<c:forEach var="listauf" items="${lstUF}">
<html:option value="${listauf.suf}" >${listauf.suf}</html:option>
</c:forEach>
</html:select>
</TD>
</TR>
<TR>
<TD bgColor="#dceaf5" height="26">
<font id="lblgc" face="verdana" color="#336699" size="1">G. Conta:</font>
</TD>
<TD bgColor="#dceaf5" height="26">
<html:select property="gerenteconta" onchange="javascript:submeter('localizaGR');">
<html:option value="0">-- Selecione o Gerente de Conta ----</html:option>
<c:forEach var="listaGC" items="${lstGC}">
<html:option value="${listaGC.codgc}" >${listaGC.descrgc}</html:option>
</c:forEach>
</html:select>
</TD>
<TD>
<font id="lblgr" face="verdana" color="#336699" size="1">G. Regional:</font>
</TD>
<TD colspan="3">
<html:select property="gerenteregional" styleClass="combo" onchange="javascript:submeter('executaListaGC');">
<html:option value="0">-- Selecione o Gerente Regional ----</html:option>
<c:forEach var="listaGR" items="${lstGR}">
<html:option value="${listaGR.codgr}" >${listaGR.descrgr}</html:option>
</c:forEach>
</html:select>
</TD>
</TR>
<TR>
<TD bgColor="#dceaf5" height="13">
<font id="lblproducao" face="verdana" color="#336699" size="1">Produção em:</font>
</TD>
<TD bgColor="#dceaf5" height="13">
<html:text property="producao" readonly="true" styleClass="desabilitado"/>
</TD>
</TR>
<TR>
<TD bgColor="#dceaf5" height="13">
<font id="lblrede" face="verdana" color="#336699" size="1">Rede:</font>
</TD>
<TD >
<html:text property="rede" size="38"/>
</TD>
<TD>
<a href="javascript:submeter('executaListaRede');">
<bean:message key="botao.pesquisar"/>
</a>
</TD>
<TD colspan="3">
<html:select property="codrede" >
<html:option value="0"> </html:option>
<c:forEach var="listarede" items="${lstRede}">
<html:option value="${listarede.codigo}">${listarede.descrede}</html:option>
</c:forEach>
</html:select>
</TD>
</TR>
<TR>
<TD width="735" bgColor="#4891c6" colSpan="6" height="41">
<TABLE BORDER="0">
<TR>
<TD width="184" align="center" bgColor="#4891c6" height="25">
<a href="javascript:submeter('executaInclusao');">
<bean:message key="botao.gravar"/>
</a>
</TD>
<TD width="183" align="center" bgColor="#4891c6" height="25" >
<a href="javascript:submeter('executaExclusao');">
<bean:message key="botao.excluir"/>
</a>
</TD>
<TD width="183" align="center" bgColor="#4891c6" height="25">
<a href="javascript:limpaCampos();">
<bean:message key="botao.limpar"/>
</a>
</TD>
<TD width="184" align="center">
<a href="javascript:submeter('executaPesquisa');">
<bean:message key="botao.pesquisar"/>
</a>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD align="center" bgColor="#dceaf5" colSpan="6" height="22">
<div id="msg">
<table>
<tr>
<td>
<font face="verdana" size="2" color="red">
<b>
<logic:messagesPresent message="true">
<html:messages id="message" message="true">
<b><bean:write name="message"/></b>
</html:messages>
</logic:messagesPresent>
<logic:messagesPresent message="false">
<html:messages id="error" message="false">
<b><bean:write name="error"/></b>
</html:messages>
</logic:messagesPresent>
</b>
</font>
</td>
</tr>
</table>
</div>
</TD>
</TR>
<TR>
<TD align="center" bgColor="#4891c6" colSpan="6" height="10"></TD>
</TR>
<!-- TABELA -->
<TR>
<TD vAlign="top" colSpan="6">
<display:table id="listaPDV" name="sessionScope.lstPDV" class="table" style="width:625px;" pagesize="5000" export="false" requestURI="cadPDV.do">
<display:setProperty name="export.excel" value="true" />
<display:column titleKey="titulo.cadPDV.sidagentevenda">
<a href="javascript:fnRetornarRegistroSelecionadoGrid('${listaPDV.sidagentevenda}','${listaPDV.snomeagentevenda}','${listaPDV.nidregiao}',
'${listaPDV.srede}',
'${listaPDV.ddataproducao}',
'${listaPDV.bstatus}',
'${listaPDV.sendereco}',
'${listaPDV.sbairro}',
'${listaPDV.scidade}',
'${listaPDV.suf}',
'${listaPDV.scodgc}',
'${listaPDV.scodgr}','${listaPDV.codrede}'
);"/>${listaPDV.sidagentevenda}</a>
</display:column>
<display:column property="snomeagentevenda" titleKey="titulo.cadPDV.snomeagentevenda"/>
<display:column property="nidregiao" titleKey="titulo.cadPDV.nidregiao"/>
<display:column property="srede" titleKey="titulo.cadPDV.srede"/>
<display:column property="ddataproducao" titleKey="titulo.cadPDV.ddataproducao"/>
<display:column property="bstatustexto" titleKey="titulo.cadPDV.bstatustexto"/>
</display:table>
</TD>
</TR>
</TBODY>
</TABLE>
</html:form>
</body>
</HTML>