Author: lfryc(a)redhat.com
Date: 2010-07-10 15:29:35 -0400 (Sat, 10 Jul 2010)
New Revision: 17849
Added:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/A4JPushEventProcuder.java
root/tests/metamer/trunk/src/main/webapp/components/a4jPush/event-producer.xhtml
Modified:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/A4JPushBean.java
root/tests/metamer/trunk/src/main/webapp/components/a4jPush/list.xhtml
root/tests/metamer/trunk/src/main/webapp/components/a4jPush/simple.xhtml
Log:
Modified a4j:push sample to can trigger events externally using GET URL
Modified:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/A4JPushBean.java
===================================================================
---
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/A4JPushBean.java 2010-07-10
19:28:48 UTC (rev 17848)
+++
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/A4JPushBean.java 2010-07-10
19:29:35 UTC (rev 17849)
@@ -25,10 +25,10 @@
import java.io.Serializable;
import java.util.Date;
import java.util.EventListener;
-import java.util.EventObject;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
+import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import org.ajax4jsf.event.PushEventListener;
@@ -54,6 +54,17 @@
private int counter = 0;
private transient volatile PushEventListener listener;
+ @ManagedProperty(value = "#{a4jPushEventProcuder}")
+ private transient A4JPushEventProcuder pushEventProducer;
+
+ public A4JPushEventProcuder getPushEventProducer() {
+ return pushEventProducer;
+ }
+
+ public void setPushEventProducer(A4JPushEventProcuder pushEventProducer) {
+ this.pushEventProducer = pushEventProducer;
+ }
+
/**
* Initializes the managed bean.
*/
@@ -91,15 +102,12 @@
public void setAttributes(Attributes attributes) {
this.attributes = attributes;
}
-
+
public void setListener(EventListener listener) {
this.listener = (PushEventListener) listener;
+ pushEventProducer.registerListener(this.listener);
}
- public void generateEvent() {
- listener.onEvent(new EventObject(this));
- }
-
public int getCounter() {
return counter;
}
Added:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/A4JPushEventProcuder.java
===================================================================
---
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/A4JPushEventProcuder.java
(rev 0)
+++
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/A4JPushEventProcuder.java 2010-07-10
19:29:35 UTC (rev 17849)
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+
+package org.richfaces.testapp.bean;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.EventObject;
+import java.util.HashSet;
+import java.util.LinkedList;
+
+import javax.annotation.PostConstruct;
+import javax.faces.bean.ApplicationScoped;
+import javax.faces.bean.ManagedBean;
+
+import org.ajax4jsf.event.PushEventListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Managed bean for a4j:push.
+ *
+ * @author Nick Belaevski, <a href="mailto:ppitonak@redhat.com">Pavol
Pitonak</a>
+ * @version $Revision$
+ */
+@ManagedBean(name = "a4jPushEventProcuder")
+@ApplicationScoped
+public class A4JPushEventProcuder implements Serializable {
+
+ private static final long serialVersionUID = 4532283098337277878L;
+ private Logger logger;
+ private Collection<PushEventListener> registeredListeners = new
HashSet<PushEventListener>();
+
+ @PostConstruct
+ public void init() {
+ logger = LoggerFactory.getLogger(getClass());
+ }
+
+ public void registerListener(PushEventListener listener) {
+ synchronized (registeredListeners) {
+ registeredListeners.add(listener);
+ }
+ }
+
+ public void produceEvent(Boolean enabled) {
+ logger.info("enabled: " + enabled);
+ if (enabled) {
+ Collection<PushEventListener> listeners;
+ synchronized (registeredListeners) {
+ listeners = new
LinkedList<PushEventListener>(registeredListeners);
+ }
+ for (PushEventListener listener : listeners) {
+ listener.onEvent(new EventObject(A4JPushBean.class));
+ }
+ logger.info("push event (listeners: " + listeners.size() +
")");
+ }
+ }
+}
Added: root/tests/metamer/trunk/src/main/webapp/components/a4jPush/event-producer.xhtml
===================================================================
--- root/tests/metamer/trunk/src/main/webapp/components/a4jPush/event-producer.xhtml
(rev 0)
+++
root/tests/metamer/trunk/src/main/webapp/components/a4jPush/event-producer.xhtml 2010-07-10
19:29:35 UTC (rev 17849)
@@ -0,0 +1,32 @@
+<!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:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:ta="http://java.sun.com/jsf/composite/testapp">
+
+<ui:composition template="/templates/template.xhtml">
+
+ <f:metadata>
+ <f:viewParam name="pushEnabled" value="#{pushEnabled}" />
+ <f:event type="preRenderView"
listener="#{a4jPushEventProcuder.produceEvent(pushEnabled)}" />
+ </f:metadata>
+
+ <ui:define name="head">
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ </ui:define>
+
+ <ui:define name="component">
+ <h:button value="Generate push event">
+ <f:param name="pushEnabled" value="true" />
+ </h:button>
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ </ui:define>
+
+</ui:composition>
+</html>
\ No newline at end of file
Modified: root/tests/metamer/trunk/src/main/webapp/components/a4jPush/list.xhtml
===================================================================
--- root/tests/metamer/trunk/src/main/webapp/components/a4jPush/list.xhtml 2010-07-10
19:28:48 UTC (rev 17848)
+++ root/tests/metamer/trunk/src/main/webapp/components/a4jPush/list.xhtml 2010-07-10
19:29:35 UTC (rev 17849)
@@ -12,6 +12,9 @@
<h:link outcome="simple" value="Simple"
styleClass="link"/>
<div class="description">Simple page that contains
<b>a4j:push</b> and input boxes for all its attributes.</div>
+
+ <h:link outcome="event-producer" value="Event Producer"
styleClass="link"/>
+ <div class="description">Page that is bind to application bean
producing events catched by a4j:push.</div>
</h:body>
</html>
\ No newline at end of file
Modified: root/tests/metamer/trunk/src/main/webapp/components/a4jPush/simple.xhtml
===================================================================
--- root/tests/metamer/trunk/src/main/webapp/components/a4jPush/simple.xhtml 2010-07-10
19:28:48 UTC (rev 17848)
+++ root/tests/metamer/trunk/src/main/webapp/components/a4jPush/simple.xhtml 2010-07-10
19:29:35 UTC (rev 17849)
@@ -43,12 +43,6 @@
<f:param name="testParam" value="testValue" />
<f:param name="testParam1" value="testValue1"
/>
</a4j:push>
-
- <br/>
-
- <h:commandLink value="Generate push event"
action="#{a4jPushBean.generateEvent}">
- <f:ajax render="@none" />
- </h:commandLink>
</ui:define>
<ui:define name="outOfTemplateAfter">