Dears,
RF team has added a new hot feature which is push with CDI, but I tried to use it and i faced a troublesome message (Topic 'my topic name' is not configured), my enviroment :
-JBoss AS 6.0 final
-JDK 1.6.0-24
-RichFaces 4.1 Final
Refer to these sources for more information:
RichFaces Component Guide: a4j:push component
Starting with RichFaces Push on Various Servlet Containers
so i asked for TopicContext help to complete my task, here what you need to do to make a4j:push work using CDI :
1-add context parameters to your web.xml :
<context-param> <param-name>org.richfaces.push.jms.disable</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>org.atmosphere.useBlocking</param-name> <param-value>true</param-value> </context-param>
2-find the attached file (atmosphere dependencies.rar), it contains 5 jars for atmosphere push framework, copy them into 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}")//i thought that the topic is initialized with this ?! private Event<String> pushEvent; @Inject public void init() { if(userIdentifier == null) { userIdentifier = UUID.randomUUID().toString().replace("-", ""); } TopicsContext topicsContext = TopicsContext.lookup(); topicsContext.getOrCreateTopic(new TopicKey(CDI_PUSH_TOPIC, userIdentifier));//initialize the topic and make the troublesome message disappears } 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; } }
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