Retornar valores na combo de uma tabela

0 respostas
R

Boa tarde. Amigos tenho uma tabela na qual estou consultando equipes, quando consulto o resultado da consulta seto nos campos para usar para alteração destes dados. Tenho duas combos sendo populadas pelo banco de dados(cidades e modalidades). Gostaria de preencher as combos com os valores da tabela para poder alterá-los, na verdade seria selecionar os valores da tabela na combo, os outros dados consigo recuperar, apenas os da combo que não estou conseguindo pegar. Aí embaixo vai meu código, agradeço quem possa ajudar. Valeu.

consulta_equipes.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="com.modelo.entidade.Equipes"%>
<%@page import="com.modelo.entidade.Cidades"%>
<%@page import="com.modelo.entidade.Modalidades"%>
<%@page import="java.util.ArrayList"%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0048)http://templates.arcsin.se/wp-demo/dirtylicious/ -->
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD 
profile=http://gmpg.org/xfn/11><TITLE>Campeonato de Equipes</TITLE>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<META content="MSHTML 6.00.3790.1830" name=GENERATOR><!-- leave this for stats -->



<script>
function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function soNumero(v){
    v=v.replace(/\D/g,"")                 
    return v
}


function mtelefone(v){
    v=v.replace(/\D/g,"")                 
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") 
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    
    return v
}

function soTexto(v){
    v=v.toUpperCase()             //Maiúsculas
    v=v.replace(/[^ABCDEFGHIJKLMNOPQRSTUVXZY W]/g,"") 
    return v
}

function maiuscula(v){
    v=v.toUpperCase()             //Maiúsculas
    v=v.replace(/[^ABCDEFGHIJKLMNOPQRSTUVXZY W123456789]/g,"") 
    return v
}






function setDados(id){

	var nome = document.getElementById(id+"_Hnome").value;
	var tecnico = document.getElementById(id+"_Htecnico").value;
	
	var tel = document.getElementById(id+"_Htelefone").value;
	var inscricao = document.getElementById(id+"_Hinscricao").value;
	var modalidade = document.getElementById(id+"_Hmodalidade").value;
	var cidade = document.getElementById(id+"_Hcidade").value;
	
	document.getElementById("inscricao").value = id;
	document.getElementById("tecnico").value = tecnico;

	document.getElementById("telefone").value = tel;
	document.getElementById("nome_1").value = nome;
	
	document.getElementById("modalidade").options[document.frm.modalidade.selectedIndex].text=modalidade;
	document.getElementById("cidade").options[document.frm.cidade.selectedIndex].text=cidade;
	

	
	
	
	
}

function valida_campos(frm){

var s = document.frm.modalidade.options[document.frm.modalidade.selectedIndex].text;
var t = document.frm.cidade.options[document.frm.cidade.selectedIndex].text;

	if(frm.nome1.value == ""){
		alert("Nome vazio!!Digite novamente!!");
		frm.nome1.focus();
		return (false);
	
	}
	if(s == "" || s == null){
		alert("Modalidade vazia!!Informe uma modalidade!!");
		frm.modalidade.focus();
		return (false);
	
	}
	if(t == "" || t == null){
		alert("Cidade vazia!!Informe uma cidade!!");
		frm.cidade.focus();
		return (false);
	
	}
	
	if(frm.telefone.value != "" && frm.telefone.value.length!=14){
		alert("Telefone invalido!!Informe o telefone!!");
		frm.telefone.focus();
		frm.telefone.value="";
		return (false);
	
	}
		return (true);

}



</script>




<LINK media=screen href="import/style.css" type=text/css rel=stylesheet>
</HEAD>
<BODY>
<DIV class=outer-container>
<DIV class=inner-container>
<DIV class=header>
<DIV class=title><SPAN class=sitename><A 
href="#">Cadastro de Equipes</A></SPAN> 
<DIV class=slogan>Interestadual do Rio de Janeiro </DIV></DIV></DIV>
<DIV class=path><A href="../Inicio.do">Home</A>
<UL>
  <LI class="page_item page-item-23"><A title="Cadastro" 
  href='Cidade.do'>Cidades</A> 
        <LI class="page_item page-item-2"><A title="Modalidades" 
  href='Modalidades.do'>Modalidades</A> 
  <LI class="page_item page-item-4"><A title="Equipes" 
  href='Equipes.do'>Equipes</A> </LI></UL></DIV>
<DIV class=main>
<form name="consulta" method="post" id="formconsultar"
	action="ConsultarEquipes.do">

      <table width="521" border="0" cellpadding="0" cellspacing="0">
        <!--DWLayoutTable-->
        <tr> 
          <td height="50" colspan="2" valign="top">Consultar Equipes</td>
        </tr>
        <tr> 
          <td width="242" height="37" valign="middle">Nome: 
            <input type="text" name="nome" onkeydown="mascara(this,maiuscula)"></td>
          <td width="279" align="left" valign="middle"> 
          <input type="submit" name="Submit3" value="Query" class="botao3d"> 
           &nbsp;
          </tr>
      </table>
	  <br>
	  <table width="621" border="2" cellpadding="0" cellspacing="0" class="tabela" id="table">
        <!--DWLayoutTable-->
        <%
		
		try{
			ArrayList<Equipes> equip = (ArrayList<Equipes>)request.getAttribute("equipes");
			 
			if(!equip.isEmpty()){
	
				
			
	%>
        
        <tr> 
          <td width="50" height="21" valign="top">Inscrição</td>
          <td width="150" valign="top">Nome</td>
          <td width="150" valign="top">Tecnico</td>
          <td width="380" valign="top">Telefone</td>
          <td width="175" valign="top">Modalidade</td>
          <td width="380" valign="top">Cidade</td>
          <td width="35" valign="middle">Editar</td>
		<td width="35" valign="middle">Excluir</td>
        </tr>
     <%
		
	for (Equipes e : equip) {
	%>
        <tr> 
         <td height="15" valign="top"><%=e.getInscricao()%><input
			name="<%= e.getInscricao() %>_Hinscricao" type="hidden"
			id="<%= e.getInscricao() %>_Hinscricao" value=""
			value="<%= e.getInscricao() %>" /></td>
			
          <td valign="top"><%=e.getNome()%><input
			name="<%= e.getInscricao() %>_Hnome" type="hidden"
			id="<%= e.getInscricao() %>_Hnome" value="<%= e.getNome() %>" /></td>
          
              
          <td valign="top"><%=e.getTecnico()%><input
			name="<%= e.getInscricao() %>_Htecnico" type="hidden"
			id="<%= e.getInscricao() %>_Htecnico" value="<%= e.getTecnico() %>" /></td>
          
          <td valign="top"><%=e.getTelefone()%><input
			name="<%= e.getInscricao() %>_Htelefone" type="hidden"
			id="<%= e.getInscricao() %>_Htelefone" value="<%= e.getTelefone() %>" /></td>
			
		
		<td valign="top"><%=e.getModalidade().getNome()%><div id="divCombo1" class="divCombo"><select
			name="<%= e.getInscricao() %>_Hmodalidade" 
			id="<%= e.getInscricao() %>_Hmodalidade"> 
			<option value="<%= e.getModalidade().getNome() %>" >"<%= e.getModalidade().getNome() %>"</option>
			</select>
			</div></td>


		<td valign="top"><%=e.getCidade().getNome()%><div id="divCombo2"><select
			name="<%= e.getInscricao() %>_Hcidade"
			id="<%= e.getInscricao() %>_Hcidade" class="divCombo"> 
			<option value="<%= e.getCidade().getNome() %>">"<%= e.getCidade().getNome() %>"</option></select></div></td>  		

			
		<td valign="top"><img src="img/edit.png" alt="Editar" heigth="16"
			width="16" onclick="setDados('<%= e.getInscricao() %>');"></td>
		
		<td valign="top"><a	href="DeletarEquipes.do?inscricao=<%= e.getInscricao() %>"><img
			src="img/del.png" alt="Excluir" heigth="16" width="16"
			></a></td>
        </tr>
        
        <%
		}
	


	}
		
			else {
%>
		<tr>
	    <td class="tabela" colspan="8"><center><b>Não há registros para os parametros dados</b></center></td>  
	  </tr>
<%

}

%>		
<%
		}catch(NullPointerException n){
	System.out.println("ok");
		
	%>	

<%
		}catch(ClassCastException c){
	System.out.println("ok");
		}
		
	%>	
        
        </table>
        <br>
        </form>
        <br>
         
 <form onsubmit="return valida_campos(this)" name="frm" method="get" id="frm" action="AlterarEquipes.do">
  <LINK media=screen href="import/style.css" type=text/css rel=stylesheet>
<table width="50%" border="0" cellspacing="0" cellpadding="0" class="tabela" id="table">
  <tr>
    <td width="23%">C&oacute;digo:</td>
    <td width="77%"><input name="inscricao" type="text" id="inscricao" readonly="readonly" size=30 /></td>
  </tr>
  <tr>
    <td>Nome:</td>
    <td><input name="nome1" type="text" id="nome_1" size=30 onkeydown="mascara(this,maiuscula)"/></td>
  </tr>
  <%
		
  if (request.getAttribute("modalidades") != null)
  {
	ArrayList<Modalidades> mod = (ArrayList<Modalidades>) request.getAttribute("modalidades"); 
				
			
	%>
  
  
  
  <tr>
    <td>Modalidade:</td>
    <td><select name="modalidade" id="modalidade">
   		<option value="1"></option>
   		<%
					 for (Modalidades e : mod) {
					 %>
					 
    	<option value="<%= e.getCodigo() %>"><%= e.getNome() %></option>
    				 <%
  					 }
    				 %>   		
   		</select>
   					<%
  					 }
    				 %>
   	</td>
  </tr>
  
  
<%
		
  if (request.getAttribute("cidades") != null)
  {
	ArrayList<Cidades> cid = (ArrayList<Cidades>) request.getAttribute("cidades"); 
				
			
	%>
<tr>
    <td>Cidade:</td>
    <td><select name="cidade" id="cidade">
    	<option value="1"></option>
    	<%
					 for (Cidades e : cid) {
					 %>
    	<option value="<%= e.getCodigo() %>"><%= e.getNome() %></option>
    				 <%
  					 }
    				 %>
    	</select>
    </td>
    				 <%
      				}
      				%>
  </tr>
  
  
  <tr>
    <td>Tecnico:</td>
    <td><input name="tecnico" type="text" id="tecnico" size=30 onkeydown="mascara(this,soTexto)" /></td>
  </tr>
  <tr>
    <td width="80" height="20">Telefone:</td>
    <td width="80" height="20">
    <input name="telefone" type="text" id="telefone" size=30 onkeydown="mascara(this,mtelefone)" maxlength="14"/></td>
    <td width="80" height="20"><input type="submit" name="alterar" value="Alterar" class="botao3d" align="left" ></td>
  </tr>
</table>
 
</form>

</DIV>
<DIV class=footer>
<DIV class=left>© 2008 <A 
href="http://templates.arcsin.se/wp-demo/">Dirtylicious</A></DIV>
<DIV class=right><A href="http://templates.arcsin.se/">Wordpress Theme</A> by <A 
href="http://arcsin.se/">Arcsin</A></DIV>
<DIV class=clearer><SPAN></SPAN></DIV></DIV></DIV></DIV></BODY></HTML>
Criado 28 de maio de 2008
Respostas 0
Participantes 1