2010-12-21 105 views
0

可以請任何有經驗的人與Spring DispatcherPortlet處理後xmlHttpRequests,告訴我什麼是最好的方式來做到這一點?我使用YUI IO模塊和傑克遜對象映射器爲例:Spring-portlet POST ajax xmlHttpRequest

@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); 
     } 
    ... 
    } 

阿賈克斯:

function() { 

    var A = AUI(); 

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

This在這裏你可以投票了春天的portlet環境將具有相同的支持問題那個普通的spring-mvc有。這@ResponseBody是,數據轉換成JSON等,現在據我所知一個人做手工......

編輯:想出解決方案

請:看看這個問題,這是更好地制定https://stackoverflow.com/questions/4782971/handling-ajax-requests-with-spring-portlet

+1

http://stackoverflow.com/questions/4782971/handling-ajax-requests-with-spring-portlet似乎不再存在 – Eric 2011-02-08 18:08:14

回答

0

你如何構建URL?我認爲你正在創建一個Action URL,也許它應該是一個渲染URL。這意味着,而不是<portlet:actionURL/>你應該使用<portlet:renderURL/>

希望它有幫助。

+0

它必須是這是jsr 283規範的一部分。它主要是爲了ajax請求而創建的。正確的註解是@ResourceMapping(value =「sample」)...但是Spring的Portlet不適合處理Ajax請求,沒有內置的JSON響應支持,人們必須手動執行它...有這個問題,如果你喜歡portlet和spring,請投票支持:https://jira.springframework.org/browse/SPR-7344 – lisak 2010-12-21 23:35:53

+0

謝謝@lisak,我將明確地投票贊成這個不錯的功能。 – 2010-12-22 00:04:24