Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/11/2011, 18:28
abulon81
 
Fecha de Ingreso: mayo-2010
Mensajes: 99
Antigüedad: 14 años
Puntos: 5
Respuesta: combos dependientes DWR

Cita:
Iniciado por abulon81 Ver Mensaje
wenas estoy haciendo una pequeña aplicacion en struts 1.3.x , y estoy usando DWR , mi duda es que tengo dos combos el segundo es dependiente del primero, entonces cuando le doy al primero, me arroja una ventana warning sobre los metodos

function CallBackFillCombo(c) {
DWRUtil.removeAllOptions("centrales");
DWRUtil.addOptions("centrales", c, 'idcentral','central');
}


diciendome este mensaje :

removeOptions can only be used with select, ol and ul elements, Attemp use object.
addOptions can only be used with select, ol and ul elements, Attemp use object.

Sin llenar los combos.

El codigo es el siguiente:
Código:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charsetutf-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> 
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>


    <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/TestAjax.js'></script>                                    
    <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
    <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script> 
    <script type='text/javascript' src='<%=request.getContextPath()%>/js/funciones.js'></script>
    
<script type="text/javascript" src="/js/jquery.min.js" ></script>
<script type="text/javascript" >

weno aqui le puse el slash de la ruta faltanta y funciono :porra:

 jQuery(document).ready 
        ( function() 
            { //1
          
  jQuery('#select').change(function ()
  {
    window.location = jQuery('#select').val();
  });  
  
 
                     
        jQuery('a[name=Exportar]').click( 
            function() 
            { 
                alert('hola');
               // jQuery('#forma').attr("action",jQuery(this).val()); 
                jQuery('#forma').attr("action",'<%=request.getContextPath()%>/prueba.do?action=metodo');
               // jQuery('#forma').attr("action",'<%=request.getContextPath()%>/muestra.do');
                jQuery( '#forma').submit();
            }); 
                    
                    
        jQuery('a[name=Ir]').click(
            function()
            {
             alert('Ir a manda');
             jQuery('#forma').attr("action",'<%=request.getContextPath()%>/prueba.do?action=probando');
             jQuery('#forma').submit();
            });
            
    } //1
            
); 
</script>


<style type="text/css">

input{
margin-left:26px;
}
input.name{
margin-left:26px;
}
input.phone{
margin-left:25px;
}
input.email{
margin-left:30px;
}

.grid11_6 {width: 925px;}
.picon {padding-left: 25px;}
</style>

<html>

  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
    <title>test</title>
   
  </head>
  
  <body>
  <%  
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Expires", "Thu, 29 Oct 2000 17:04:19 GMT");
    response.setContentType("text/html; charset=utf-8");
    
%>
  <html:errors /> 
 

  hola
  <bean:message key="testForm.nombre"/>:<bean:write name="testForm" property="name"/>
  <br>
  <bean:message key="testForm.lastname"/>:<bean:write name="testForm" property="lastname"/>
  <br>
  <bean:message key="testForm.city"/>:<bean:write name="testForm" property="idcity"/>
  <div class="grid11_6" >
  <fieldset><legend title="hola">hola</legend>
  <div class="picon" >
  <html:form action="/prueba.do?action=enviar" styleId="forma" >
  
  
    User :<html:text property="name" styleId="nombre" styleClass="name"/>
    <br>
    Lastname:<html:text property="lastname"  styleId="lastname" styleClass="phone"  />
    <br>
   <div id="selec" > 
    <html:select property="lastname" styleId="select">
    <html:option value="#">-- None --</html:option>
	<html:option value="prueba.do?action=metodo">1980</html:option>
	<html:option value="prueba.do?action=metodo">1981</html:option>
	<html:option value="prueba.do?action=metodo">1982</html:option>
	<html:option value="prueba.do?action=metodo">1983</html:option>
	<html:option value="prueba.do?action=metodo">1984</html:option>
	<html:option value="prueba.do?action=metodo">1985</html:option>
    </html:select>
   </div>
    
<p>
    <html:select property="idcity" name="testForm" styleId="idCity" onchange="cities(this.value);" >
        <html:option value="-1"><bean:message key="seleccion.one"/></html:option>
        <html:options collection="listaCity" labelProperty="city" property="idcity"/>
    </html:select>
</p>

<p>
    <html:select styleId="centrales" name="testForm" property="idcity"  >
          <html:options collection="colCities" labelProperty="city" property="idcity" />
    </html:select>
                        
<select id="combo" name="combo">
          <option value="" >Select...</option>
        </select>
</p>

   <html:submit ><bean:message key="boton.envia" /></html:submit>
   </html:form>
   </div>
   
   <p>
   <html:link href="#" styleId="dame"> Vinculo </html:link>
   <a  name="Exportar" id="exportar">vinculo</a>
   <a class="reportesBtn boton-rojo" href="#" id="reporteBTN" onclick="javascript:location.href='<%=request.getContextPath()%>/prueba.do?action=metodo';return false;"><bean:message key='boton.envia'/></a>
   <a name="Ir" id="manda">Manda</a>
   </p>
</fieldset>
</div>


  </body>
</html>
El contenido de funciones.js es
Código:
function cities(valor)
{
var id = valor;
alert(id);
TestAjax.getCatalogo(CallBackFillCombo,id);
}

function CallBackFillCombo(c) {
	  DWRUtil.removeAllOptions("centrales");
          DWRUtil.addOptions("centrales", c, 'idcentral','central');
	}
Y el TestAjax.java es :
Código:
import com.prueba.bean.TestBean;

import java.util.ArrayList;


public class TestAjaxDwr {
    public TestAjaxDwr() {
    }
    
    
    public ArrayList getCatalogo(int number){
        ArrayList array =  new ArrayList();
        TestBean bean  = new TestBean();
        if( number > 0){
            for(int i = 0; i <= number;i++){
                bean =  new TestBean();
                bean.setIdCentral(i + "");
                bean.setCentral("opcion "  + i);
                array.add(bean);
            }
            
        }else{
            bean.setIdCentral("0");
            bean.setCentral("Nada");
            array.add(bean);
        }
        
        return array;                    
    }
    
    
    
    
}

La demas configuracion de los xml esta bien , ademas que probe el dwr los metodos definidos en la clase y funcionan bien.

Agradezco me ayuden a ver que esta pasando. Saludos. Gracias.
Espero sirva a alguien