robsonsan 1 de ago. de 2008
robsonsan:
galera tenho uma jsp que faço uma pesquisa quero colocar uma condição que quando o usuário fazer uma busca pelo código de um cliente se não houver nenhum cliente cadastrada com esse código retorne uma mensagem que esta cadastrada no application resource na própria tela de pesquisa
aqui está minha Action
public ActionForward pesquisaClientes ( ActionMapping mapping ,
ActionForm form , HttpServletRequest req , HttpServletResponse res )
throws Exception {
ActionMessages messages = new ActionMessages () ;
ClientesDAO clientesDAO = new ClientesDAO () ;
ClienteForm clienteForm = ( ClienteForm ) form ;
ClienteTO clienteTO = clienteForm .getCliente () ;
List clientList = clientesDAO .selecionaClientes ( clienteTO ) ;
clienteForm .setListaClientes ( clientList ) ;
if ( clienteTO .getCodigocli () .equals ( clientList )) {
if ( clienteTO .getCpf () .equals ( clientList )) {
return mapping .findForward ( "sucesso" ) ;
}
} else {
messages .add ( "error.pesquisa" , new ActionMessage ( "error.pesquisa" )) ;
saveMessages ( req , messages ) ;
}
return null ;
}
Aqui minha JSP
<% @ taglib uri = "/WEB-INF/struts-html.tld" prefix = "html" %>
<% @ taglib uri = "/WEB-INF/struts-logic.tld" prefix = "logic" %>
<% @ taglib uri = "/WEB-INF/struts-bean.tld" prefix = "bean" %>
<html>
<head>
<title> :: Listar Clientes ::</title>
<SCRIPT type= "text/javascript" >
function enviar(pControl) {
var form = pControl.form;
form.action = "cliente.do";
form.operacao.value = "pesquisaClientes";
form.submit();
}
function editarDetalhes(pControl, id) {
var form = pControl.form;
form.action = "cliente.do";
form.operacao.value = "detalhesCliente";
form.itemSelecionado.value = id;
form.submit();
}
function excluirCliente(pControl, id) {
var form = pControl.form;
form.action = "cliente.do";
form.operacao.value = "excluirCliente";
form.itemSelecionado.value = id;
form.submit();
}
</SCRIPT>
</head>
<body bgcolor= "lightblue" >
<html:form method= "post" action= "/cliente" >
<html:hidden property= "operacao" />
<html:hidden property= "itemSelecionado" />
<table border= "1" align= "left" >
<H3 align= "left" > Escolha a Opção de Busca</H3>
<tr>
<td> CPF</td>
<td colspan= "2" ><INPUT type= "text" name= "cliente.cpf" size= "15" ></td>
</tr>
<tr>
<td> Codigo do Cliente</td>
<td colspan= "2" ><INPUT type= "text" name= "cliente.codigocli" size= "8" ></td>
</tr>
<br>
<br>
<div align= "left" >
<td><INPUT type= "submit" value= "Buscar"
onclick= "javascript:enviar(this); return false;" > <input type= button
value= "Voltar"
onclick= "window.location='<html:rewrite page=" /botaoVoltaListaClientes.do" /> '" /></td>
</div>
</div>
</table>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<table border= "1" >
<logic:present property= "listaClientes" name= "ClienteForm" >
<logic:notEmpty property= "listaClientes" name= "ClienteForm" >
<tr>
<td align= "center" > Codigo</td>
<td align= "center" > Nome</td>
<td align= "center" > Endereço</td>
<td align= "center" > RG</td>
<td align= "center" > CPF</td>
<td align= "center" > Telefone</td>
<td align= "center" > Celular</td>
<td align= "center" > Bairro</td>
<td align= "center" > Data de Nascimento</td>
<td align= "center" > Numero</td>
<td align= "center" > Complemento</td>
<td align= "center" > Email</td>
<TD colspan= "2" ></TD>
</tr>
<logic:iterate id= "clienteTO" property= "listaClientes"
name= "ClienteForm" >
<tr>
<td><bean:write name= "clienteTO" property= "codigocli" /></td>
<td><bean:write name= "clienteTO" property= "nome" /></td>
<td><bean:write name= "clienteTO" property= "endereco" /></td>
<td><bean:write name= "clienteTO" property= "rg" /></td>
<td><bean:write name= "clienteTO" property= "cpf" /></td>
<td><bean:write name= "clienteTO" property= "telfixo" /></td>
<td><bean:write name= "clienteTO" property= "cel" /></td>
<td><bean:write name= "clienteTO" property= "bairro" /></td>
<td><bean:write name= "clienteTO" property= "datanascimento" /></td>
<td><bean:write name= "clienteTO" property= "numero" /></td>
<td><bean:write name= "clienteTO" property= "complemento" /></td>
<td><bean:write name= "clienteTO" property= "email" /></td>
<td><input type= "image"
src= "<html:rewrite page=" /imagens/visualizar.gif" /> "
onclick="javascript:editarDetalhes(this, '<bean:write name= "clienteTO" property= "codigocli" /> '); return false;" /></td>
<td><input type= "image"
src= "<html:rewrite page=" /imagens/excluir.gif" /> "
onclick="javascript:excluirCliente(this, '<bean:write name= "clienteTO" property= "codigocli" /> '); return false;" /></td>
</tr>
</logic:iterate>
</logic:notEmpty>
</logic:present>
</table>
</html:form>
</body>
</html>
No aplication resource
error.pesquisa=Não existe cliente cadastrado para o parâmetro passado