2013-06-13 31 views
4

我想从SWF流中的视图对Spring MVC控制器进行AJAX调用。我需要在portlet容器内执行此操作,而不是位于portlet会话外部的servlet。如何在Spring MVC/WebFlow项目中进行AJAX调用

我已经尝试在Spring Controller类中使用<portlet:resourceURL id="myAjax"/>并使用@ResourceMapping,但这会在尝试处理请求时干扰SWF FlowHandler。

是我想做的可能吗?如果有的话,任何人有任何建议如何做到这一点?

谢谢。

回答

0

在我看来,状态1 Spring Web Flow的我有这样的:

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

和我的控制器:

@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; 
    } 
相关问题