How to make an AJAX call as part of a Spring MVC / WebFlow project

I would like to make an AJAX call to the Spring MVC controller from a view in a SWF thread. I need to do this inside a portlet container, not a servlet sitting outside of a portlet session.

I tried using <portlet:resourceURL id="myAjax"/> and using @ResourceMapping in the Spring Controller class, but this interferes with the SWF FlowHandler when it tries to process the request.

I want to do this? If so, does anyone have any tips on how to do this?

Thanks.

+4
source share
1 answer

In my view-state1 spring web stream, I have this:

 <script type="text/javascript"> function getInfoPersona(tipoSearch) { dojo.require("dojox.widget.Standby"); if(tipoSearch == 'cedula'){ var param = document.getElementById('cedula').value; if(!param){ return alert('Escriba una cédula'); } }else{ var param = document.getElementById('numero').value; if(!param){ return alert('Escriba un número'); } } var url = "/application/personae/info/"+tipoSearch+"/"+param+".json"; var standby = new dojox.widget.Standby({target: "loadingInfo"}); document.body.appendChild(standby.domNode); standby.startup(); standby.show(); dojo.xhrGet({ // URL del recurso en el servidor url: url, handleAs: "json", timeout: 5000, // Time in milliseconds // The LOAD function will be called on a successful response. load: function(response, ioArgs) { // if(response.nombre){ document.getElementById('infoPersona').innerHTML = '<ul>'+ //'<li>Estatus: '+response.estatus+'</li>'+ '<li>Nombre: '+response.nombre+'</li>'+ '<li>Centro: '+response.centro+'</li></ul>'; if(tipoSearch == "cedula"){ if( response.numero > 0){ document.getElementById("numero").value = response.numero; //document.getElementById("numero").readOnly = true; document.getElementById("buttonSearchNumero").disabled = true; }else{ //document.getElementById("numero").value = ''; document.getElementById("numero").readOnly = false; document.getElementById("buttonSearchNumero").disabled = true; } } if(tipoSearch == "numero"){ document.getElementById("cedula").value = response.cedula; document.getElementById("cedula").readOnly = true; document.getElementById("buttonSearchCedula").disabled = true; } if(response.ambito != ''){ document.getElementById('ambito').value = response.ambito; } document.getElementById('twitter').value = response.twitter; document.getElementById('correo').value = response.email; document.getElementById('numeroTelefono').value = response.telefono; if(response.parroquiaId > 0){ seleccionarMunicipioParroquia(response.parroquiaId, response.municipioId); } document.getElementById('infoPersona').style.visibility = 'visible'; document.getElementById('success').disabled = false; }else{ if(tipoSearch == 'cedula'){ document.getElementById('infoPersona').innerHTML = 'No se encontraron datos'; document.getElementById('success').disabled = true; }else{ document.getElementById('infoPersona').innerHTML = 'No se encontraron datos para el número de escrito'; } document.getElementById("buttonSearchCedula").disabled = false; document.getElementById("buttonSearchNumero").disabled = false; } standby.hide(); document.getElementById('infoPersona').style.visibility = 'visible'; }, // The ERROR function will be called in an error case. error: function(response, ioArgs) { // console.error("HTTP STATUS CODE: ", ioArgs.xhr.status); // dojo.byId("infoPersona").innerHTML = 'No se pudo cargar la información básica de la persona'; // standby.hide(); document.getElementById('infoPersona').style.visibility = 'visible'; return response; // } }); } </script> 

and my controller:

 @RequestMapping(value = "/info/cedula/{cedula}.json", method = RequestMethod.GET, produces = "application/json") @ResponseBody public InfoPersona getPersonaAsJson(@PathVariable("cedula") Integer cedula) { InfoPersona te = new InfoPersona(); Persona v = Persona.findPersonaByCedulaEquals(cedula); if(v == null){ return te; } setDataPersona(v.getPersonaId(), te); te.setTipoBusqueda("cedula"); if(!telefonosString.equals("")){ //eliminar la coma final telefonosString = telefonosString.substring(0, telefonosString.length() - 1); te.setAllTelefonos(telefonosString); } te.setTelefonos(numeros); return te; } 
0
source

Source: https://habr.com/ru/post/1485948/


All Articles