This content has been marked as final.
Show 4 replies
-
1. Re: Working example of a4j:push [Please help Ilya]
fmarwede Oct 26, 2007 6:03 AM (in response to balteo)I can't help but I'm (and many others in this forum, too, I think) very interested in that.
-
2. fmarwede
balteo Oct 26, 2007 8:26 AM (in response to balteo)Hello fmarwede,
I am glad you too are interested in a4j:push.
Have you tried a4j:push personally or do you have code you could share?
I will definitely post info if and when I get information on my side.
Julien. -
3. Re: Working example of a4j:push [Please help Ilya]
ilya_shaikovsky Oct 26, 2007 8:30 AM (in response to balteo)using just your code for bean and next page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:a4j="https://ajax4jsf.dev.java.net/ajax" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.ajax4jsf.org/rich" xmlns:ui="http://java.sun.com/jsf/facelets"> <ui:composition template="/templates/common.xhtml"> <ui:define name="body"> <a4j:status startText="in progress" stopText="done"/> <a4j:form> <a4j:push reRender="msg" eventProducer="#{pushBean.addListener}" interval="100"/> <a4j:outputPanel id="msg" > <h:outputText value="#{pushBean.date}"> <f:convertDateTime type="time"/> </h:outputText> </a4j:outputPanel> <a4j:commandButton value="Push!!" action="#{pushBean.push}" ajaxSingle="true"/> <a4j:log popup="false"/> </a4j:form> </ui:define> </ui:composition> </html>
I'm able to see that push working. Checked with enabled setted to false - button doesn't change anything and setting to true - time updated after button clicked. -
4. Re: Working example of a4j:push [Please help Ilya]
balteo Oct 26, 2007 8:50 AM (in response to balteo)Thanks a lot for you reply Ilya.
I forgot to mention that the two JSP fragments go into separate JSP pages. I reworked the example and came up with something more complex and that make sense but that does not work.
from faces-config.xml<managed-bean> <managed-bean-name>theBean</managed-bean-name> <managed-bean-class>pack.TheBean</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <managed-bean> <managed-bean-name>myApplicationBean</managed-bean-name> <managed-bean-class>pack.MyApplicationBean</managed-bean-class> <managed-bean-scope>application</managed-bean-scope> </managed-bean>
TheBean.javapackage pack; import java.util.Date; import java.util.EventListener; import java.util.EventObject; import javax.faces.context.FacesContext; /** * * @author Administrator */ public class TheBean { private Date date; private MyPushEventListener listener; public TheBean() { MyApplicationBean app_bean = (MyApplicationBean) FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("myApplicationBean"); this.listener = app_bean.getListener(); } public void addListener(EventListener listener) { synchronized (listener) { if (this.listener != listener) { MyApplicationBean app_bean = (MyApplicationBean) FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("myApplicationBean"); this.listener = app_bean.getListener(); } } } public Date getDate() { return new Date(); } public void push() { synchronized (this.listener) { MyApplicationBean app_bean = (MyApplicationBean) FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("myApplicationBean"); this.listener = app_bean.getListener(); this.listener.onEvent(new EventObject(this)); } } }
the application-scoped bean:package pack; /** * * @author jumartin */ public class MyApplicationBean { private MyPushEventListener listener; public MyApplicationBean() { listener = new MyPushEventListener(); } public MyPushEventListener getListener() { return listener; } }
in a jsp page invoked before other pages<% application.setAttribute("myApplicationBean", new pack.MyApplicationBean()); %>
the push event listenerpackage 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()); System.out.println(this); //DO SOME ACTION IN HERE } }
the TWO jsps (fragments)receiver.jsp <a4j:form> <rich:message for="date" passedLabel="ok" ajaxRendered="true" showDetail="true"/> <a4j:push reRender="date" immediate="true" eventProducer="#{theBean.addListener}" interval="100"/> <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> ************** Pusher.jsp <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>
I have spent a good part of the afternoon working on this and I am still not able to make it work.
Any clue? I changed to ajaxSingle=true
Julien.