5

I am having liferay portlet and I need to heavily depend upon the AJAX calls. So I need to make multiple calls to serveResource method. One way to do the same is that I can pass a parameter with the URL and then differentiate the request according to that parameter.

But in my case I have to call serveResource so many times due to which the method will be difficult to maintain. Is there any framework to do so? Using which the code becomes maintainable.

4

2 回答 2

2

使用 Spring MVC 框架并根据控制器中的业务逻辑/用户操作调用不同的方法,

在jsp中尝试以下代码

<portlet:resourceURL var="loadContents" id="loadContents"></portlet:resourceURL>
<portlet:resourceURL var="loadCategories" id="loadCategories"></portlet:resourceURL>

jsp中的ajax调用

AUI().ready(
        function(A) {            
            A.use('aui-io-request', 
                    function(aui) {
                    A.io.request("<%=loadContents%>", {
                        autoLoad : false,
                        cache : false,
                        dataType : 'json',
                        data:{},
                        method:'POST',
                        on : {
                            success : function(event, id, xhr) {
                                var response = this.get('responseData');
                                 // add logic here after response
                            }
                        }
                    }).start();
                });
        });

在控制器/ java 类中

    @ResourceMapping("loadCategories")
    public void loadCategories(final ResourceRequest resourceRequest, final ResourceResponse resourceResponse)
    {
         // your business logic goes here
    }

    @ResourceMapping("loadContents")
    public void loadContents(final ResourceRequest resourceRequest, final ResourceResponse resourceResponse)
    {
         // your business logic goes here
    }

希望上面的代码片段能帮助你,你得到你想要的!!!

于 2013-06-24T05:17:32.767 回答
2

在此添加更多。我们不能使用serveResource像这样的方法processAction。单个liferay portlet(不是spring mvc portlet)中可以有多个processAction,而在它的情况下serveReource它将是单个的。

serveResource主要用于ajax调用。我们可以serveResource通过resource Id区分调用,在方法中处理多个ajax请求。

resourceRequest.getResourceID()将返回我们在 jsp 中使用以下代码定义的 Id。

<portlet:resourceURL var="demoUrl" id="demoUrl"></portlet:resourceURL>
于 2015-05-28T11:04:36.810 回答