0

I want to auto update datatable (on client) when user is idle. I'm using Primefaces 3.5 with glassfish and my idea was following:

I've boolean autoUpdate variable in bean. And user can turn on/off the auto update.

I created two components: p:poll and p:idleMonitor.

The idleMonitor has two events, which trigger the update

<p:ajax event="idle" oncomplete="myPoll.start();" />
<p:ajax event="active" oncomplete="myPoll.stop();" />

This part is ok. The problem is, how to disable idleMonitor when autoUpdate is set to False? When I do

<h:panelGroup id="updatePanel" rendered="#{cc.attrs.bean.autoUpdate}">
....
</h:panelGroup>

it works only if I start with autoUpdate = false and I can switch the mode only once. Once it's rendered it can't be changed. I've also tried

<p:ajax event="idle" oncomplete="#{cc.attrs.bean.autoUpdate ? 'myPoll.start();' : ''}" />

but it didn't work neither. The #{cc.attrs.bean.autoUpdate} is never changed. Even I'm calling upadte on it and I can see the variable changed on another place.

So, my question is: Is there any way how to disable idleMonitor, after it was rendered? Or what is the better solution for optional periodical update for idle's user?

tvazac
  • 536
  • 2
  • 7
  • 21
  • So you want Idle monitor but for only once? You don't want that option when second time user goes idle? – Kishor Prakash Jul 25 '13 at 18:21
  • No, I want Idle monitor each time when user goes idle. But only if he has the `autoUpdate` sets to `True`. It means, he can switch between `True` and `False` during a session without reloading a page. – tvazac Jul 26 '13 at 05:57
  • Hmm, have you tried p:outputPanel instead of h:panelGroup? First one harmonies better is my subjective perception. – Markus Schulte Aug 06 '13 at 19:34

1 Answers1

0

Your autoUpdate variable is evaluated only at render time. (at page load)

#{cc.attrs.bean.autoUpdate}

That's why js doesn't know about its modifications.

Solution 1, rerender a js code:

<p:ajax event="idle" update="afterIdle" />
<h:panelGroup id="afterIdle">
 <h:outputScript>
  if ('#{cc.attrs.bean.autoUpdate}' == 'true') 
   myPoll.start();
 </h:outputScript>
</h:panelGroup>

Solution 2: keep a js variable updated on autoUpdate (somehow, for example with remoteCommand):

<p:ajax event="idle" oncomplete="myFunction()" />
<script type="text/javascript">
 function myFunction(){
  if (jsAutoUpdate) myPoll.start();
 }
</script>

Solution 3: primefaces idleMonitor widget has a stop() function, which stops idle monitoring.

steve
  • 615
  • 6
  • 14