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
}
}
<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>
<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>