Forums

Home » Alloy UI » English

Combination View Flat View Tree View
Threads [ Previous | Next ]
David H Nebinger
RE: Display and Refresh Values from the DB
November 16, 2012 6:05 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7153

Join Date: September 1, 2006

Recent Posts

Oops, didn't see this was in the AUI thread, sorry.

Actually I have been thinking about this too. I currently have a timer in place using window.setInterval(), but I'm digging into the AUI code to see if there is a corresponding AUI way to do it.

In the method passed to setInterval(), I'm just calling Liferay.fire() to kick off an event that will trace through to my Vaadin backend code, but I'm betting you could at least trigger the ajax call to the back end either to a service facade that calls XxxLocalServiceUtil or if you have remote services enabled you can call it directly.

Note that if the database is being changed directly, you're going to want to disable caching at the entity level so the service doesn't return stale data.
David H Nebinger
RE: Display and Refresh Values from the DB
November 16, 2012 9:56 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7153

Join Date: September 1, 2006

Recent Posts

Liferay.fire() and Liferay.on() are just browser-side IPC mechanisms. With Vaadin, however, the browser side IPC notification gets automagically handled as a server side event (pretty cool, IMHO).

But I don't think this will help w/ your AJAX-based issue. I'd first solve the AJAX request/response process and, once you have that going, add in the timed refresh.
Hitoshi Ozawa
RE: Display and Refresh Values from the DB
November 16, 2012 10:03 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

If you're going to need near realtime values, saving values into database tables and **LocalServiceUtil may not be a good option. Better to save values in beans to write you own service interface to retrieve values.
Mohamed Rizwanuzaman
RE: Display and Refresh Values from the DB
December 10, 2012 3:09 AM
Answer

Mohamed Rizwanuzaman

Rank: New Member

Posts: 18

Join Date: December 16, 2009

Recent Posts

Hi Eric,
Instead of using action / render method, You can use serveResource method for Ajax call using

<portlet:resourceURL var="ajaxUrl"/>

and you can get the response in in success function of ajax call
 1
 2 A.io.request('<%=renderResponse.encodeURL(ajaxUrl.toString())%>', {
 3          method: 'post',
 4          dataType: 'json',
 5          data: {
 6             groupId: groupId
 7               },
 8          on: { 
 9              success: function() {
10              container.empty()
11                
12                 var url =this.get('responseData').userPhotoUrl ;
13                   var title= this.get('responseData').userFullname;
14                 var dispUrl = this.get('responseData').userdisplayUrl;
15                A.Node.create("<a href='"+dispUrl+"'><img class='picture' src='"+url+"' title='"+title+"'></a>").appendTo(container);
16            
17                 }
18           }
19      });

In action class
1
2    public void serveResource(ResourceRequest resourceRequest,
3            ResourceResponse resourceResponse) throws IOException,
4            PortletException {
5             //logic for getting thevalue from db using XXXLocalServiceUtil.java
6}


after getting the response back you can replace the div to show the latest content from the DB.

Regards,
Rizwan