0 Replies Latest reply on May 3, 2012 3:14 PM by Hauke Gulich

    Push with Richfaces 4.2.1 comming from Richfaces 4.0.0-Final

    Hauke Gulich Newbie

      Hello everyone,


      I was so glad finally to get the push function to work with richfaces 4.0.0-Final (thanks to this board).

      Last week I tried to add a context-menu to a graphic and I noticed that within 4.0.0-Final no <rich:contextMenu> was shipped.

      So I upgraded to 4.2.1-Final (with maven) and the context-menu is working.


      But the push function isn't working anymore.


      What I did with the 'old' release was the following:


      1) added this to faces-config.xml








      2) added the the mentioned class above (TopicsInitializer.java)



      public class TopicsInitializer extends SessionBeanBase implements SystemEventListener, MessageListener {


          private static final Logger LOG = Logger.getLogger(TopicsInitializer.class);


          private transient TopicsContext topicsContext;


          private transient Context ctx;


          public static enum SubTopic {





          private static final Map<SubTopic, String> subTopicMapping = new HashMap<SubTopic, String>() {{

              put(SubTopic.LIGHT, "light");

              put(SubTopic.TEMPERATUR, "temperature");



          public TopicsInitializer() {




          private void init() {


              LOG.info("Der Client hoert auf Die Queue toClient : " + ConfigurationHelper.CONFIGKEY_JMS_QUEUE_TOCLIENT);

              try {

                  // Queuenamen aus der Datenbank auslesen

                  String queueName = getInterfaceHelper().getConfigurationHelper().getValue(ConfigurationHelper.CONFIGKEY_JMS_QUEUE_TOCLIENT);



                  QueueConnectionFactory connectionFactory = (QueueConnectionFactory) getInitialContext().lookup("java:/ConnectionFactory");


                  QueueConnection connection = connectionFactory.createQueueConnection();

                  Queue queue = (Queue) getInitialContext().lookup(queueName);


                  QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);




                  // Diese Klasse als Listener registrieren




              } catch (Exception e) {





          public void processEvent(SystemEvent event) throws AbortProcessingException {


              LOG.info("TopicsInitializer - ProcessEvent wurde aufgerufen - SubTopics werden konfiguriert");



              topicsContext = TopicsContext.lookup();


              // Jedes SubTopic erzeugen aus der Enumeration

              for (SubTopic subTopic : SubTopic.values()) {

                  Topic topic = topicsContext.getOrCreateTopic(new TopicKey("notify", subTopicMapping.get(subTopic)));



                  topic.addTopicListener(new SessionTopicListener() {



                      public void processPreSubscriptionEvent(SessionPreSubscriptionEvent event) throws EventAbortedException {




                      public void processSubscriptionEvent(SessionSubscriptionEvent event) throws EventAbortedException {




                      public void processUnsubscriptionEvent(SessionUnsubscriptionEvent event) throws EventAbortedException {








          public boolean isListenerForSource(Object source) {

              return true;



           private Context getInitialContext() {

              try {

                  if (ctx == null) {

                      ctx = new InitialContext();


              } catch (NamingException e) {



              return ctx;





          public void onMessage(Message message) {

              TextMessage tm = (TextMessage) message;


              try {

                  LOG.info("Client hat eine Nachricht empfangen : " + tm.getText());


                  HomematicDeviceName device = HomematicDeviceName.valueOf(tm.getText());


                  if (device == null) {

                      LOG.error("Unbekannte Nachricht!!!");





                   if (device.name().startsWith("LICHT")) {


                  }  else if (device.name().startsWith("TEMP")) {




              } catch (Exception e) {






          private void notifyClient(SubTopic subTopic) throws MessageException {

              LOG.info("Sende Nachricht an das SubTopic : " + subTopicMapping.get(subTopic));

              org.richfaces.application.push.TopicKey topicKey = new org.richfaces.application.push.TopicKey("notify", subTopicMapping.get(subTopic));

              topicsContext.publish(topicKey, " ");




      I removed some comments and some other not useful stuff here.



      Since 4.2.1 some classes are deprecated like SessionTopicListener, EventAbortedException, EventAbortedException and EventAbortedException



      Like I said, it was kind of hard to get this working so it might be a little bit confusing my code but unfortunately the examples of push aren't very easy to understand inside the download of richfaces. There are > 10 classes and interfaces.

      Hopefully someday there is something much more easier example :-)





      PS.: I don't get any exception. It's only not working. No refreshes comming up.