2 Replies Latest reply on Jan 1, 2008 1:15 PM by parki

    Question about a4j:push - am I missing something?

    parki

      Hello!

      I kinda posted this at RichFaces developers ("Question about ajax design") but thought this might be a better place.

      I am trying to use <a4j:push> to solve a problem - I'm not 100% sure that a4j:push is the right approach (if not, please advise on what I should be using). I'm pretty new to Rich Faces and loving it so far - need to learn more about events though.

      So, I have a tree backed by a model session scoped bean which serves up the tree - this is all working fine. The problem - the tree may change due to another process, and so when this happens, I'd like the GUI to change immediately (ie. re-render the tree). I'd prefer to not poll - would be nicer to have an ajax call block on the server until the change event, and then re-render.

      I'm assuming that this is what a4j:push is for.

      Here's part of the xhtml page:

      Code:

      <rich:tree id="thermostat" style="width:300px" nodeSelectListener="#{thermostatAdaptor.processSelection}"
       reRender="province" ajaxSubmitSelection="true" switchType="client"
       value="#{thermostatAdaptor.treeNode}" var="item">
      </rich:tree>
      
      <a4j:push reRender="thermostat" eventProducer="#{thermostatAdaptor.addListener}" interval="1000"/>


      and part of the model code:

      Code:

      public void notifyModified()
      {
       loadThermostat();
      
       if(listener_ != null)
       {
       listener_.onEvent(new EventObject(this));
       }
      }
      
      public void addListener(EventListener listener)
      {
       synchronized (listener)
       {
       if(listener_ != listener) listener_ = (PushEventsCounter) listener;
       }
      }



      When I try this, addListener gets called (with a PushEventsCounter). When the tree data is updated (by another process), the notifyModified method is called, but the thermostat is not rerendered.

      Methinks something is missing?

      I'm wondering if instead of calling 'onEvent' with an EventObject, I need to call with a specific event (ie. some derived class), but I'm unsure here.

      Aside question - why is there a polling interval on push - is this the time delay between calls to the server?

      Any help is appreciated - the demo doesn't have example code I can steal.

      Thanks.

      And happy new year!

      parki...


        • 1. Re: Question about a4j:push - am I missing something?

          Happy new year!

          Which browser do you use? When it is FF you have to wait for a bugfix anyway:

          http://jira.jboss.org/jira/browse/RF-1753


          So please test your code in IE and post when there it is not working too.

          • 2. Re: Question about a4j:push - am I missing something?
            parki

            Ohmigod - thanks!

            I was using FireFox - thanks for info on the bug. In the bug report, alexsmirnox reports "this exception does not occur if the FireBug extension is enabled" which I can confirm - when running FireFox with Firebug, the <a4j:push> element works fine.

            Off to check on IE on Windows.

            Thanks - this is extremely cool to have working!

            parki...