Thanks for the response David.
I've come up a little bit of code that uses setInterval as well, it submits a form which has an actionURL as the action and the processAction code behind calls the XxxLocalServiceUtil to update the value (caching has been disabled on entity level). Everything appears to work fine.
However, I'm not sure if calling the actionURL via a form submit is the best way to do things. As I've only got this one portlet on my page it's hard to tell what sort of effect it has, I'm worried that by submitting the form it will refresh other portlets.
1
2package com.portlet.test.core;
3
4import java.io.IOException;
5
6import javax.portlet.ActionRequest;
7import javax.portlet.ActionResponse;
8import javax.portlet.PortletConfig;
9import javax.portlet.PortletContext;
10import javax.portlet.PortletException;
11import javax.portlet.PortletRequestDispatcher;
12import javax.portlet.RenderRequest;
13import javax.portlet.RenderResponse;
14
15import com.portlet.test.service.TestLocalServiceUtil;
16import com.liferay.portal.kernel.exception.PortalException;
17import com.liferay.portal.kernel.exception.SystemException;
18import com.liferay.util.bridges.mvc.MVCPortlet;
19
20public class Weather extends MVCPortlet
21{
22 private String payload;
23
24 private PortletContext context;
25
26 @Override
27 public void init(PortletConfig conf) throws PortletException
28 {
29 this.context = conf.getPortletContext();
30 }
31
32 @Override
33 public void render(RenderRequest req, RenderResponse resp) throws PortletException, IOException
34 {
35 PortletRequestDispatcher rd = this.context.getRequestDispatcher("/view.jsp");
36 rd.include(req, resp);
37 }
38
39 @Override
40 public void processAction(ActionRequest req, ActionResponse resp) throws PortletException, IOException
41 {
42 try
43 {
44 this.payload = TestLocalServiceUtil.getTest(1).getName();
45 }
46 catch (PortalException e)
47 {
48 //
49 }
50 catch (SystemException e)
51 {
52 //
53 }
54
55 resp.setRenderParameter("render-param", this.payload);
56 }
57}
1
2<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
3<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
4
5<portlet:defineObjects />
6
7<%
8 String renderParameter = renderRequest.getParameter("render-param");
9
10 renderParameter = (renderParameter != null ? renderParameter : "");
11%>
12
13<portlet:actionURL var="actionUrl" />
14
15<aui:script use='aui-io'>
16AUI().ready(function(A)
17{
18 setInterval(function()
19 {
20 A.one('#<portlet:namespace />form').submit();
21
22 }, 3000);
23
24});
25</aui:script>
26
27<form id='<portlet:namespace/>form' action='<%= actionUrl %>' method='post'></form>
28
29<p id='<portlet:namespace/>data'>Value: <%= renderParameter %></p>
I will have a read about Liferay.fire() to see if that will update the portlet data more subtly.
EW
Please sign in to flag this as inappropriate.