Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/06/2011, 21:52
ISHTAR86
 
Fecha de Ingreso: diciembre-2010
Mensajes: 5
Antigüedad: 13 años, 4 meses
Puntos: 0
Pregunta No llena select con Struts2 usando jquery ajax

Hola, estoy tratando de llenar un combo box a partir de la seleccion de otro combo box anterior y con información de la base de datos utilizando struts2 y ajax con jquery, el problema es que al momento de devolver el json a la función de jquery me retorna null, pero en el action realiza la busqueda y llena el hashmap correctamente. Ya estoy desesperada llevo 1 semana tratando de ver el error y de verdad que no se como resolver esto, agradecería de antemano cualquier ayuda... Gracias

FUNCION JQUERY:

$('#selectVersion').change(function(e){
$("#selectVersion option:selected").each(function () {
var chose=$(this).val();
$.ajax({type: "POST",
url: "jsonAction.action",
data: {vid:chose},
dataType: "json",
success: function(data) {
$("#selectLocation").show();
$("#listLocation").get(0).options.length = 0;
$("#listLocation").get(0).options[0] = new Option("SelectLocation", "-1");

$.each(data.items, function(key, value) {
$("#listLocation").get(0).options[$("#listLocation").get(0).options.length]
= new Option(key, value);


});

}
});


});
});




STRUTS.XML

<package name="catalog" extends="struts-default">
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
</result-types>
<action name="*">
<result>/pages/{1}.jsp</result>
</action>
<action name="jsonAction" class="Catalogue.actions.JsonAction">
<result type="json"><param name="root">json</param></result>
</action>
</package>





PAGINA.JSP

<tr>
<td align="right" valign="top">Version:</td>
<td colspan="5">
<s:select name='selectV' id="selectVersion" list="versionsList" listKey="id" listValue="name" headerKey="0" headerValue="Select Version" name="vid" value="%{vid}"/></td>
</tr>
<tr id="selectLocation" style="display: none" >
<td align="right" valign="top">Location:</td>
<td colspan="5" ><select id="listLocation"></select></td>
</tr>





ACTION JsonAction.java

@SuppressWarnings("unchecked")

public class JsonAction extends ActionSupport {

private Integer vid;

private LocationSvc officeSvc;

private List officesVersion;

private static final Logger log = Logger.getLogger(JsonAction.class);

private static final long serialVersionUID = -7279248753453329694L;

public String execute() {

officesVersion = officeSvc.findByVersion(vid);
HashMap json =new LinkedHashMap<String, Object>();

Iterator ite = officesVersion.iterator();
while (ite.hasNext())
{
Office of= (Office) ite.next();
json.put("id",of.getId());
json.put("name",of.getName());
}


return SUCCESS;
}


public void setVid(Integer vid) {
this.vid = vid;
}


public Integer getVid() {
return vid;
}

public void setOffices(List officesVersion) {
this.officesVersion = officesVersion;
}


public List getOffices() {
return officesVersion;
}


public void setOfficeSvc(LocationSvc officeSvc) {
this.officeSvc = officeSvc;
}


public LocationSvc getOfficeSvc() {
return officeSvc;
}

}

Espero que esta información le sirva, gracias, espero sus sugerencias :D