Please help with the a4j:push component
balteo Dec 18, 2007 6:01 AMHello,
I tried to reproduce the example given for the a4j:push without success. Here is my code:
The managed bean (request-scoped):
package pack; import java.util.Date; import java.util.EventListener; import java.util.EventObject; import org.ajax4jsf.event.PushEventListener; /** * * @author Administrator */ public class TheBean { private Date date; private PushEventListener listener= new MyPushEventListener(); public TheBean() { } 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)); } } }
The push event listener:
package pack; import java.util.EventObject; import org.ajax4jsf.event.PushEventListener; public class MyPushEventListener implements PushEventListener { public void onEvent(EventObject evt) { System.out.println(evt.getSource()); TheBean b = (TheBean) evt.getSource(); b.getDate(); System.out.println(b.getDate()); } }
The jsp that pushes:
<f:view> <a4j:status startText="in progress" stopText="done"/> <h:form> <a4j:region> <a4j:commandButton value="Push!!" action="#{theBean.push}" ajaxSingle="true"/> <a4j:log level="ALL" popup="false" hotkey="L"/> </a4j:region> </h:form> </f:view>
The receiver with the a4j:push:
<f:view> <a4j:status startText="in progress" stopText="done"/> <a4j:form> <rich:message for="date" passedLabel="ok" ajaxRendered="true" showDetail="true"/> <a4j:region> <a4j:push reRender="date" eventProducer="#{theBean.addListener}" interval="100"/> </a4j:region> <a4j:outputPanel id="date" ajaxRendered="true"> <h:outputText value="#{theBean.date}"> <f:convertDateTime type="time"/> </h:outputText> </a4j:outputPanel> <a4j:log level="ALL" popup="false" hotkey="L"/> </a4j:form> </f:view>
Here is the behavior that I have: When I press the pusher button the onEvent method does get called but the date is not reRendered. Can anyone please tell me why?
What I am getting wrong?
Thanks in advance,
Julien.