Ola pessoal…
Estou fazendo uma página que retorna duas tabelas…departamentos e empregados…existe um relacionamento entre essas tabelas que eh pelo numero do departamento… o que eu quero eh que quando o usuario selecione um departamento a tabela de funcionarios seja atualizada…
Por favor me ajudem…eu fiz um eskema parecido só que sem ajax…e tbm naum deu certo…vou postar em outro topico…muito obrigado…
Olhem o codigo:
<%@ page contentType=“text/html;charset=windows-1252”%>
<%@ taglib uri=“<a href="http://java.sun.com/jsf/html">http://java.sun.com/jsf/html</a>” prefix=“h”%>
<%@ taglib uri=“<a href="http://java.sun.com/jsf/core">http://java.sun.com/jsf/core</a>” prefix=“f”%>
<%@ page import=“conexao.Conexao”%>
<%@ page import=“java.sql.*”%>
function xmlhttpChange()
{
if(xmlHttp.readyState == 4){
if (xmlHttp.status == 200){
if(xmlHttp.responseXML.getElementsByTagName("idDepto").length > 0){
var string = "<table cellspacing=\"0\" border=\"1\" width=\"700\" align=\"center\">" +
"<caption>FUNCIONARIOS</caption> " +
" <tr> " +
" <th scope=\"col\">SELECIONAR</th> " +
" <th scope=\"col\">MATRICULA</th> " +
" <th scope=\"col\">NOME</th> " +
" <th scope=\"col\">SOBRENOME</th> " +
" <th scope=\"col\">EMAIL</th> " +
" <th scope=\"col\">TELEFONE</th> " +
" <th scope=\"col\">SALARIO</th> " +
" <th scope=\"col\">IDENTIIFCAÇÃO DO GERENTE</th> " +
" <th scope=\"col\">DEPTO Nº</th> " +
" </tr> " +
" <tr class='alt''> ";
var count = xmlHttp.responseXML.getElementsByTagName("id").length;
for( i=0; i>count; i++ ) {
var id = xmlHttp.responseXML.getElementsByTagName("id")[i].firstChild.nodeValue;
var nome = xmlHttp.responseXML.getElementsByTagName("nome")[i].firstChild.nodeValue;
var sobrenome = xmlHttp.responseXML.getElementsByTagName("sobrenome")[i].firstChild.nodeValue;
var email = xmlHttp.responseXML.getElementsByTagName("email")[i].firstChild.nodeValue;
var telefone = xmlHttp.responseXML.getElementsByTagName("telefone")[i].firstChild.nodeValue;
var salario = xmlHttp.responseXML.getElementsByTagName("telefone")[i].firstChild.nodeValue;
var gerente = xmlHttp.responseXML.getElementsByTagName("gerente")[i].firstChild.nodeValue;
var dept_id = xmlHttp.responseXML.getElementsByTagName("dept_id")[i].firstChild.nodeValue;
string += "<td width='8%' align='center' border='1'> <input type='radio' name='idDepto' value='" + id + "' onclick='getFuncinario( this.value );' > </td></font> " +
"<td width='12%'align='center' border='1''>" + id + "</td></font> " +
"<td width='12%'align='center' border='1''>" + nome + "</td></font> " +
"<td width='10%'align='center' border='1''> " + sobrenome + "</td></font> " +
"<td width='12%'align='center' border='1''>" + email + "</td></font> " +
"<td width='12%'align='center' border='1''>" + telefone + "</td></font> " +
"<td width='12%'align='center' border='1''>" + salario + "</td></font> " +
"<td width='12%'align='center' border='1''>" + gerente + "</td></font> " +
"<td width='12%'align='center' border='1''>" + dept_id + "</td></font> ";
}
string += "</tr> " +
"</table> ";
document.getElementById( "tbFuncionario" ).innerHTML = string;
}
}
else alert("Erro ao carregar a ajax");
}
}
</script>
</head>
<body>
<table cellspacing="0" border="1" width="700" align="center">
<caption>DEPARTAMENTOS</caption>
<tr>
<th scope="col">SELECIONAR</th>
<th scope="col">DEPTO Nº</th>
<th scope="col">DEPARTAMENTO</th>
<th scope="col">INDETIFICAÇÃO DO GERENTE</th>
</tr>
<%
int contador = 0;
int quantidade = 0;
Conexao conexao = new Conexao();
String cod;
String query = "select * from departamentos WHERE dept_id is not null ";
if( request.getParameter("idDepto") != null )
query += " and dept_id = " + request.getParameter("idDepto");
query += " order by id";
ResultSet rs = conexao.execSelect( query );
rs.next();
while (contador <= quantidade && (!rs.isAfterLast())) {
out.println("<tr class=‘alt’’>
out.println("
out.println("<td width='12%‘align=‘center’ border=‘1’’>" + rs.getObject(“dept_name”) + “</font)”);
out.println("<td width='10%‘align=‘center’ border=‘1’’> " + rs.getObject(“dept_mgr”) + “</font)”);
rs.next();
}
%>
|