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

    Question about a4j:push - am I missing something?

    Brian Parkinson Newbie


      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:


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

      and part of the model code:


      public void notifyModified()
       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.


      And happy new year!