开发者

Spring-portlet POST ajax xmlHttpRequest

Could please anybody who has experiences with processing post xmlHttpRequests with Spring DispatcherPortlet, tell me what is the best way to do it ? I'm using YUI io module and Jackson Object Mapper as 开发者_JAVA技巧an example :

@ResourceMapping(value="stuff")
public void method(ResourceResponse response){
   Person person = new Person();
   person.setWeight(150);
   ObjectMapper mapper = new ObjectMapper();
   try{
      mapper.writeValue(response.getWriter(), person);
      }
   ...
  }

Ajax:

function() {

   var A = AUI();

   A.io("<portlet:resourceURL id="stuff" />", {
      method: 'POST',
      data: {
        description: 'value'
      }
   });
     }

This is the issue where you can vote up that spring-portlet environment will have the same support that common spring-mvc has. Which is @ResponseBody, data conversion to JSON etc. Now AFAIK one has to do it manually...

EDITED: Figured out the solution

PLEASE: Take a look at this issue which is better formulated https://stackoverflow.com/questions/4782971/handling-ajax-requests-with-spring-portlet


How do you construct the URL? I think you're creating a Action URL, perhaps it should be an render URL. It means, instead of <portlet:actionURL/> you should be using <portlet:renderURL/>.

Hope it helps.


I suppose the best way to respond to ajax requests in spring portlets is described in this blog post Marshal Json data using Jackson in Spring MVC with Jaxb Annotations

This also helpful Create JSON response for AJAX request in spring 3.0

Unfortunately it is not so fancy as it would be in spring-web-mvc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜