Author: ilya_shaikovsky
Date: 2008-04-18 11:12:07 -0400 (Fri, 18 Apr 2008)
New Revision: 7939
Added:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/push/
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/push/PushBean.java
trunk/samples/richfaces-demo/src/main/webapp/richfaces/push/examples/
trunk/samples/richfaces-demo/src/main/webapp/richfaces/push/examples/push.xhtml
Modified:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/push/usage.xhtml
Log:
Push example added
Added: trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/push/PushBean.java
===================================================================
--- trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/push/PushBean.java
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/push/PushBean.java 2008-04-18
15:12:07 UTC (rev 7939)
@@ -0,0 +1,104 @@
+/**
+ *
+ */
+package org.richfaces.demo.push;
+
+import java.util.Date;
+import java.util.EventListener;
+import java.util.EventObject;
+import java.util.UUID;
+
+import org.ajax4jsf.event.PushEventListener;
+
+/**
+ * @author Ilya Shaikovsky
+ *
+ */
+
+public class PushBean implements Runnable {
+
+ private String uuid = "";
+
+ private boolean enabled = false;
+
+ private Date startDate;
+
+ PushEventListener listener;
+
+ private Thread thread;
+
+ // private int eventsFired counter;
+
+ public void addListener(EventListener listener) {
+ synchronized (listener) {
+ System.out.println("PushBean.addListener()");
+ if (this.listener != listener) {
+ this.listener = (PushEventListener) listener;
+ }
+ }
+ }
+
+ public void run() {
+ System.out.println("PushBean.run() executed");
+ while (thread != null) {
+ try {
+ System.out.println(((new Date()).getTime()-startDate.getTime())>=60000);
+ if (((new Date()).getTime()-startDate.getTime())>=20000) {
+ stop();
+ }
+ uuid = UUID.randomUUID().toString();
+ listener.onEvent(new EventObject(this));
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ // e.printStackTrace();
+ }
+ }
+ }
+
+ public String getUuid() {
+ System.out.println(uuid + "returned");
+ return uuid;
+ }
+
+ public void start() {
+ if (thread == null) {
+ thread = new Thread(this);
+ thread.setDaemon(true);
+ thread.start();
+ System.out.println("PushBean.start()");
+ setStartDate(new Date());
+ setEnabled(true);
+ System.out.println("thread started");
+ }
+ }
+
+ public void stop() {
+ if (thread != null) {
+ //thread.stop();
+ setStartDate(null);
+ setEnabled(false);
+ thread = null;
+ }
+ }
+
+ public Thread getThread() {
+ return thread;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public Date getStartDate() {
+ return startDate;
+ }
+
+ public void setStartDate(Date startDate) {
+ this.startDate = startDate;
+ }
+}
Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/push/examples/push.xhtml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/push/examples/push.xhtml
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/push/examples/push.xhtml 2008-04-18
15:12:07 UTC (rev 7939)
@@ -0,0 +1,30 @@
+<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich">
+
+ <h:form>
+ <a4j:push interval="1000" eventProducer="#{push.addListener}"
+ reRender="push,out" enabled="#{push.enabled}"
id="push"/>
+ <rich:panel>
+ <f:facet name="header">
+ <h:outputText value="Push Example"/>
+ </f:facet>
+ <h:panelGrid columns="1" id="out">
+ <h:outputText rendered="#{!push.enabled}" value="Press Start to run
push example"/>
+ <h:panelGroup rendered="#{push.enabled}">
+ <h:outputText value="Generated UUID:"/>
+ <h:outputText value="#{push.uuid}"/>
+ </h:panelGroup>
+ <h:panelGroup>
+ <a4j:commandButton value="Start" action="#{push.start}"
+ ajaxSingle="true" rendered="#{!push.enabled}"
reRender="push"/>
+ <a4j:commandButton value="Stop" action="#{push.stop}"
+ ajaxSingle="true" rendered="#{push.enabled}"
reRender="push"/>
+ </h:panelGroup>
+ </h:panelGrid>
+ </rich:panel>
+ </h:form>
+</ui:composition>
\ No newline at end of file
Modified: trunk/samples/richfaces-demo/src/main/webapp/richfaces/push/usage.xhtml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/push/usage.xhtml 2008-04-18
15:11:33 UTC (rev 7938)
+++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/push/usage.xhtml 2008-04-18
15:12:07 UTC (rev 7939)
@@ -1,79 +1,77 @@
-<!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:ui="http://java.sun.com/jsf/facelets"
-
xmlns:h="http://java.sun.com/jsf/html"
-
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:a4j="http://richfaces.org/a4j"
-
xmlns:rich="http://richfaces.org/rich">
- <ui:composition template="/templates/component-sample.xhtml">
- <ui:define name="sample">
- <style>
- .viewsourcepanel {
- padding:10px;
- width:100%;
- overflow:auto;
- border-width:0;
- background-color:#FFFFFF;
- }
- .viewsourcebody {
- padding:0;
- }
-
- </style>
- <p>
- The <a4j:push> periodically perform AJAX request to server, to simulate
'push' data.
- </p>
- <p>
- The main difference between <a4j:push> and <a4j:poll>
components
- is that <a4j:push> makes request to minimal code only (not to JSF
tree)
- in order to check the presence of messages in the queue. If the message exists
- the complete request will be performed. The component doesn't poll registered
- beans but registers EventListener which receives messages about events.
- </p>
- <p>
- Attribute 'interval' is used as for poll component. It specifies the interval
in ms.
- for call push request. Simple example of usage:
- </p>
+<!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:ui="http://java.sun.com/jsf/facelets"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich">
+<ui:composition template="/templates/component-sample.xhtml">
+ <ui:define name="sample">
+ <style>
+.viewsourcepanel {
+ padding: 10px;
+ width: 100%;
+ overflow: auto;
+ border-width: 0;
+ background-color: #FFFFFF;
+}
+
+.viewsourcebody {
+ padding: 0;
+}
+</style>
+ <p>The <a4j:push> periodically perform AJAX request to
+ server, to simulate 'push' data.</p>
+ <p>The main difference between <a4j:push> and
+ <a4j:poll> components is that <a4j:push> makes request to
+ minimal code only (not to JSF tree) in order to check the presence of
+ messages in the queue. If the message exists the complete request will
+ be performed. The component doesn't poll registered beans but
+ registers EventListener which receives messages about events.</p>
+ <p>Attribute 'interval' is used as for poll component. It
+ specifies the interval in ms. for call push request. Simple example of
+ usage:</p>
<p>
- <fieldset class="demo_fieldset">
- <legend class="demo_legend">Page code:</legend>
- <rich:panel styleClass="viewsourcepanel"
bodyClass="viewsourcebody">
- <rich:insert highlight="xhtml"
src="/richfaces/push/snippets/page.xhtml"/>
- </rich:panel>
- </fieldset>
- </p>
+ <fieldset class="demo_fieldset"><legend
class="demo_legend">Page
+ code:</legend> <rich:panel styleClass="viewsourcepanel"
+ bodyClass="viewsourcebody">
+ <rich:insert highlight="xhtml"
+ src="/richfaces/push/snippets/page.xhtml" />
+ </rich:panel></fieldset>
+ </p>
<p>
- <fieldset class="demo_fieldset">
- <legend class="demo_legend">Code for registration of
listener:</legend>
- <rich:panel styleClass="viewsourcepanel"
bodyClass="viewsourcebody">
- <rich:insert highlight="java"
src="/richfaces/push/snippets/listenerReg.java"/>
- </rich:panel>
- </fieldset>
- </p>
+ <fieldset class="demo_fieldset"><legend
class="demo_legend">Code
+ for registration of listener:</legend> <rich:panel
styleClass="viewsourcepanel"
+ bodyClass="viewsourcebody">
+ <rich:insert highlight="java"
+ src="/richfaces/push/snippets/listenerReg.java" />
+ </rich:panel></fieldset>
+ </p>
<p>
- <fieldset class="demo_fieldset">
- <legend class="demo_legend">Component can get message using current
code:</legend>
- <rich:panel styleClass="viewsourcepanel"
bodyClass="viewsourcebody">
- <rich:insert highlight="java"
src="/richfaces/push/snippets/listenermessage.java"/>
- </rich:panel>
- </fieldset>
- </p>
- <p>
- Thus, component 'push' uses asynchronous model instead of polls.
- </p>
- <ui:remove>
- <fieldset class="demo_fieldset">
- <legend class="demo_legend">Push Demo</legend>
- <div class="sample-container">
- <ui:include src="/richfaces/push/examples/push.xhtml"/>
- <ui:include src="/templates/include/sourceview.xhtml">
- <ui:param name="sourcepath"
value="/richfaces/push/examples/push.xhtml"/>
- <ui:param name="openlabel" value="View Page Source" />
- </ui:include>
- </div>
- </fieldset>
- </ui:remove>
- </ui:define>
-
- </ui:composition>
-</html>
+ <fieldset class="demo_fieldset"><legend
class="demo_legend">Component
+ can get message using current code:</legend> <rich:panel
+ styleClass="viewsourcepanel" bodyClass="viewsourcebody">
+ <rich:insert highlight="java"
+ src="/richfaces/push/snippets/listenermessage.java" />
+ </rich:panel></fieldset>
+ </p>
+ <p>Thus, component 'push' uses asynchronous model instead of
+ polls.</p>
+ <p>
+ Push example using <b>Runabble</b> interface (should be described.)
+ </p>
+ <fieldset class="demo_fieldset"><legend
+ class="demo_legend">Push Demo</legend>
+ <div class="sample-container"><ui:include
+ src="/richfaces/push/examples/push.xhtml" /> <ui:include
+ src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcepath"
+ value="/richfaces/push/examples/push.xhtml" />
+ <ui:param name="openlabel" value="View Page Source" />
+ </ui:include></div>
+ </fieldset>
+
+ </ui:define>
+
+</ui:composition>
+</html>