-
Type:
Bug
-
Status: Resolved (View Workflow)
-
Priority:
Major
-
Resolution: Done
-
Affects Version/s: None
-
Fix Version/s: 4.2.1.CR1
-
Component/s: component-push/poll
-
Labels:None
-
Affects:Documentation (Ref Guide, User Guide, etc.)
-
Workaround:Workaround Exists
-
Workaround Description:
Event can be lost if produced while a response is being prepared. I've attached an example where a push event is used to refresh a count whenever an event is fired. It's using Thread.sleep to simulate an event being produced while the response is being prepared. Note, if the sleep just before returning the count is removed it all works fine, and the page is refreshed every 5 seconds, but with the sleep in place the event is lost.
View:
<?xml version="1.0" encoding="utf-8"?>
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB" lang="en-GB"
|
xmlns:f="http://java.sun.com/jsf/core"
|
xmlns:h="http://java.sun.com/jsf/html"
|
xmlns:a4j="http://richfaces.org/a4j"
|
xmlns:rich="http://richfaces.org/rich">
|
<h:head>
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
</h:head>
|
<h:body>
|
<h:form id="myForm">
|
<a4j:push address="chat">
|
<a4j:ajax event="dataavailable" render="count" />
|
</a4j:push>
|
<h:outputText value="#{myBean.count}" id="count" />
|
</h:form>
|
</h:body>
|
</html>
|
Bean:
|
package com.example;
|
|
import java.io.Serializable;
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import javax.enterprise.context.SessionScoped;
|
import javax.inject.Named;
|
|
import org.richfaces.application.push.TopicKey;
|
import org.richfaces.application.push.TopicsContext;
|
|
@Named
|
@SessionScoped
|
public class MyBean implements Serializable
|
{
|
private AtomicInteger count = new AtomicInteger();
|
|
public int getCount()
|
{
|
int c = count.get();
|
|
new Thread()
|
{
|
public void run()
|
{
|
try
|
{
|
Thread.sleep(5000);
|
|
count.incrementAndGet();
|
|
TopicKey topicKey = new TopicKey("chat");
|
TopicsContext topicsContext = TopicsContext.lookup();
|
topicsContext.publish(topicKey, "");
|
}
|
catch (Exception e)
|
{
|
e.printStackTrace();
|
}
|
|
};
|
}.start();
|
|
try
|
{
|
Thread.sleep(10000);
|
}
|
catch (InterruptedException e)
|
{
|
}
|
|
return c;
|
}
|
}
|
- incorporates
-
RFPL-2142 Documentation for a4j:push onsubscribed event
-
- Resolved
-