1
votes

I'm currently using datatable in liferay portlet and i have to make ajax call and return a Json.

So in my controller i wrote :

@RenderMapping(params = "action=doAjaxSearch")
    public String ajaxSearch(RenderRequest request, RenderResponse response, @RequestParam int iDisplayStart,
            @RequestParam int iDisplayLength, @RequestParam String sEcho, Model model) {

        model.addAttribute("sEcho", sEcho);
        model.addAttribute("count", 20);

        return AJAX_RESULT;
    }

Where AJAX_RESULT is the view's name used to create my Json :

{ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

"sEcho": , "iTotalRecords": ${count}, "iTotalDisplayRecords": ${count}, "aaData": [] }

Everything works fine but the response returned contains the json + liferay theme. I would like to just retrieve the jsp content.

Thanks in advance for your help guys.

1
You should use ResourceMapping instead of RenderMapping. And write your json content into aResourceResponse.getWriter().write(JSON)Pankaj Kathiriya
Hi Pankaj, i don't want use ResourceMapping because my json contains lot of extra code (html) that's why i prefer use a jsp file instead of writing all the code in the java part.Denis Cucchietti

1 Answers

1
votes

While creating the URL, you add to mention the window state of your URL as Exclusive. eg.

<portlet:renderURL windowState="exclusive">
    <portlet:param name="action" value="doAjaxSearch" />
</portlet:renderURL>