Wednesday, June 12, 2013

Vaadin - Ajax call - vaadin.forceSync()

We can send the request to handelRenderRequest by passing the friendly url in the ajax
    $.ajax(
            {
                type : "POST",
                url  :"Friendly URL of the portlet",
                data : {"CHART_VALUE": JSON.stringify(chart.series.name)},
                dataType : "json"
            }
    ).done(function(responseData)
            {
        console.log("Success#");
        console.log(responseData);
        vaadin.forceSync();
            }
    ).fail(function(responseData)
            {
        console.log("failed-->");
        console.log(responseData);
        vaadin.forceSync();
            });
 
We can get the value in the renderrequest by using request.getParameter("CHART_VALUE");
private class LiferayPortletListener implements PortletListener
{
        public void handleRenderRequest(RenderRequest request, RenderResponse response, Window window)
        {
             system.out.println(request.getParameter("CHART_VALUE"));
        }
}

Then, you can call vaadin.forceSync() to make a server request, which sends all pending variable changes (changes to client-side widgets) and syncs updates from server.

Reference:

http://stackoverflow.com/questions/13861103/vaadin-with-ajax
https://vaadin.com/forum/#!/thread/751447

0 comments:

Post a Comment