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

    Question about ajax design

    parki

      Hello -

      Getting into rich faces - kudos all - this is really great. I have a design question - hoping someone can chime in on the "best way".

      I have a tree model object which is serving up an o.r.m.TreeNode object and the tree is displaying loverly. The actual tree data can change by a back end process at any time, so I'd like to be able rerender the tree component when this happens.

      My idea was to use a4j:poll to force an ajax call to the server, and then block in the method until there is a change to the underlying model, at which point the blocked thread continues, and allows the rerender from the client. Something like:

      <rich:tree id="thermostat" .... />

      <a4j:region>
      <h:form>
      <a4j:poll id="poll" interval="500"
      actionListener="#{thermostatModel.processAjax}"
      reRender="poll,thermostat"/>
      </h:form>
      </a4j:region>

      but I so far haven't been able to make this work - the processAjax method doesn't get called.

      Then I started to think that this is perhaps not the right way to do this - is it time to delve deeper into the event model in JSF?

      Any help on the preferred design would be great - suspect using a4j:poll is not the best thing here.

      Thanks, and happy holidays.

      parki...

        • 1. Re: Question about ajax design
          parki

          Aha - can I use <a4j:push> ?

          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">
          </rich:tree>
          
          <a4j:push reRender="thermostat" eventProducer="#{thermostatAdaptor.addListener}" interval="1000"/>


          and part of the model 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?

          Any 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.

          parki...






          • 2. Re: Question about ajax design
            parki

            Doesn't work in FireFox - see:

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

            I was using FireFox. 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.

            parki...