hi there,
I've posted lately this article about configuring RichFaces 4.1 CDI/Topic context push with non-maven based projects, this article is for applying the new changes for RF 4.2 push which is :
1-Topic context is no longer needed to initialize a CDI push topic.
2-org.richfaces.push.jms.disable context parameter is no longer needed to disable JMS push since it is disabled by default.
3-atmoshpere library updated (PFA).
kindly add this to your project :
1-in your web.xml
<context-param> <param-name>org.atmosphere.useBlocking</param-name> <param-value>true</param-value> </context-param>
2-find the attached file for atmosphere libraries, extract it and copy these files to your WEB-INF/lib directory :
3-PushBean java code :
@Named
@SessionScoped
public class PushBean implements Serializable {
private static final long serialVersionUID = 1L;
private static final String CDI_PUSH_TOPIC = "pushCdi";
private String userIdentifier;
private String message;
@Inject
@Push(topic=CDI_PUSH_TOPIC, subtopic="#{pushBean.userIdentifier}")//now Topic getting initialized with this.
private Event<String> pushEvent;
@Inject
public void init() {
if(userIdentifier == null) {
userIdentifier = UUID.randomUUID().toString().replace("-", "");
}
}
public void sendMessage() throws MessageException {
pushEvent.fire(message);
}
public String getUserIdentifier() {
return userIdentifier;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
xthml files has no changes they are same as before.
4-producer.xhtml source code:
<h:form id="prodForm">
<h:panelGrid>
<h:outputText id="uid" value="uid: #{pushBean.userIdentifier}" />
<h:inputText id="msg" value="#{pushBean.message}" />
<a4j:commandButton id="sendMsg"
execute="@form"
value="send"
action="#{pushBean.sendMessage}"
oncomplete="#{rich:element('msg')}.value=''"/>
</h:panelGrid>
</h:form>
important:use uid as a parameter to invoke consumer.xhtml page, ex :http://localhost:8080/rf4/faces/consumer.xhtml?uid=c59d249427544df286782765379c4647
this will ensure that each user has his own topic.
5-consumer.xhtml code:
<h:form id="conForm">
<rich:panel style="width:150px" header="messages">
<a4j:push id="consumer"
address="#{param['uid']}@pushCdi"
onerror="alert(event.rf.data)"
ondataavailable="jQuery('<li />').prependTo('#messages').text(event.rf.data)"/>
<ul id="messages"/>
</rich:panel>
</h:form>
try it out .
regards,
iabughosh.
Comments