Foros del Web » Programación para mayores de 30 ;) » Java »

combos dependientes DWR

Estas en el tema de combos dependientes DWR en el foro de Java en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 22/11/2011, 16:06
 
Fecha de Ingreso: mayo-2010
Mensajes: 99
Antigüedad: 14 años
Puntos: 5
combos dependientes DWR

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" >

 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.
  #2 (permalink)  
Antiguo 23/11/2011, 18:28
 
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
  #3 (permalink)  
Antiguo 19/03/2012, 08:10
 
Fecha de Ingreso: marzo-2009
Mensajes: 31
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: combos dependientes DWR

Hola como estas, te hago una consulta, como seria para usar dos combos, uno para pais y otro para ciudades, y llamar al action que carga las ciudades para paises? tenes algun ejemplo de esto con struts 2? gracias.
  #4 (permalink)  
Antiguo 19/03/2012, 11:10
Avatar de Fuzzylog  
Fecha de Ingreso: agosto-2008
Ubicación: En internet
Mensajes: 2.511
Antigüedad: 15 años, 8 meses
Puntos: 188
Respuesta: combos dependientes DWR

Bueno, antes de nada decir que este es el subforo de java, no de javascript.

En cuanto a tu método

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

Que es esa ¿c? ¿Se supone que es algún componente de la aplicación?

Si consultas la documentación, resulta que DWRUtil.removeAllOptions(id); funciona para un id de objeto, igual el problema lo tienes por poner comillas dobles, que te lo está detectando como variable string en vez de como parámetro, y no es capaz de relacionarlo con la ID.

Si el código que tienes está bien

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

Eso debería funcionar
__________________
if (fuzzy && smooth) {
fuzzylog = "c00l";
return true;
}

Etiquetas: combos, dependientes, struts, aplicaciones
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:02.