多个Ajax调用liferay portlet

Dan*_*ish 5 portlet liferay

我有liferay portlet,我需要在很大程度上依赖于AJAX调用.所以我需要多次调用serveResource方法.一种方法是我可以使用URL传递参数,然后根据该参数区分请求.

但在我的情况下,我必须多次调用serveResource,因为该方法很难维护.有没有这样做的框架?使用哪些代码变得可维护.

Pri*_*hah 2

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

在jsp中尝试以下代码

<portlet:resourceURL var="loadContents" id="loadContents"></portlet:resourceURL>
<portlet:resourceURL var="loadCategories" id="loadCategories"></portlet:resourceURL>
Run Code Online (Sandbox Code Playgroud)

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();
                });
        });
Run Code Online (Sandbox Code Playgroud)

在控制器/ 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
    }
Run Code Online (Sandbox Code Playgroud)

希望上面的代码片段对您有所帮助,并且您会得到您想要的东西!