<h:form id="fragment-group-form">
<p:messages id="promo-messages" escape="false" globalOnly="false" showDetail="true" closable="true"/>
<p:poll widgetVar="poll" interval="5" autoStart="true" onstart="onStartPoll();" listener="#{pollController.test}" update="promo-messages" />
...
</h:form>
Last active
January 17, 2017 10:17
-
-
Save suewonjp/d86683378051a520f4e0488d0f149b06 to your computer and use it in GitHub Desktop.
Properly using Primefaces p:poll saving network traffic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onStartPoll() { | |
if ($("#fragment-group-form\\:promo-messages .ui-messages-info").is(":visible")) { | |
// Suspend polling while the promotion message appears (to save network traffic) | |
PF("poll").stop(); | |
var timer = setInterval(function() { | |
if (! $("#fragment-group-form\\:promo-messages .ui-messages-info").is(":visible")) { | |
// The promotion message is closed; Restart polling | |
PF("poll").start(); | |
clearInterval(timer); | |
} | |
}, 2000); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.civilizer.web.controller; | |
import javax.faces.bean.ManagedBean; | |
import javax.faces.bean.ViewScoped; | |
import com.civilizer.web.view.*; | |
@ManagedBean | |
@ViewScoped | |
public final class PollController { | |
private static final String PROMOTION_MESSAGE_CLIENT_ID = "fragment-group-form:promo-messages"; | |
public void test() { | |
ViewUtil.addMessage(PROMOTION_MESSAGE_CLIENT_ID, "Testing...", "hello", null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.primefaces.org/docs/vdl/6.0/core/primefaces-p/poll.html