0 Replies Latest reply on Oct 26, 2007 6:21 AM by balteo

    Working example of a4j:push for the wiki [HELP]

    balteo

      Hello,

      I am trying to construct a working example of a4j:push that I might post on the wiki/cookbook and here what I came up with:

      The javabean (REQUEST SCOPE)

      package pack;
      
      import java.util.Date;
      import java.util.EventListener;
      import java.util.EventObject;
      import org.ajax4jsf.event.PushEventListener;
      
      
      /**
       *
       * @author Administrator
       */
      public class TheBean {
      
       /** Creates a new instance of TheBean */
       public TheBean() {
      
       }
       private Date date;
       private PushEventListener listener = new MyPushEventListener();
      
       public void addListener(EventListener listener) {
       synchronized (listener) {
       if (this.listener != listener) {
       this.listener = (PushEventListener) listener;
       }
       }
       }
      
       public Date getDate() {
       return new Date();
       }
      
       public void push() {
       synchronized (this.listener) {
       this.listener.onEvent(new EventObject(this));
       }
       }
      
      }
      class MyPushEventListener implements PushEventListener {
      
       public void onEvent(EventObject evt) {
       System.out.println(evt.getSource());
       //DO SOME ACTION IN HERE
       }
      
      
      
      }
      




      and the fist jsp: receiver

       <f:view>
       <a4j:status startText="in progress" stopText="done"/>
      
       <a4j:form>
       <a4j:push reRender="msg" eventProducer="#{theBean.addListener}" interval="100"/>
       <a4j:outputPanel id="msg" ajaxRendered="true">
       <h:outputText value="#{theBean.date}">
       <f:convertDateTime type="time"/>
       </h:outputText>
       </a4j:outputPanel>
       <a4j:log level="ALL" popup="true" hotkey="L"/>
       </a4j:form>
       </f:view>
      
      
      


      The receiver
      <f:view>
       <a4j:status startText="in progress" stopText="done"/>
      
       <h:form>
       <a4j:region>
       <a4j:commandButton value="Push!!" action="#{theBean.push}"/>
       <a4j:log level="ALL" popup="true" hotkey="L"/>
       </a4j:region>
       </h:form>
       </f:view>
      




      My msg is not updated...

      Can anyone help,

      Julien.