[richfaces-svn-commits] JBoss Rich Faces SVN: r11639 - in trunk/samples/richfaces-demo/src/main: java/org/richfaces/demo/queue and 6 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon Dec 8 10:26:58 EST 2008


Author: ilya_shaikovsky
Date: 2008-12-08 10:26:58 -0500 (Mon, 08 Dec 2008)
New Revision: 11639

Added:
   trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/queue/
   trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/queue/MojarraBean.java
   trunk/samples/richfaces-demo/src/main/webapp/css/queueStylesheet.css
   trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/resources/
   trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/resources/bgblack18.jpg
   trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/resources/button2.gif
   trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/resources/button3.gif
   trunk/samples/richfaces-demo/src/main/webapp/scripts/queueUi.js
Modified:
   trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml
   trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/queue.xhtml
   trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/usage.xhtml
Log:


Added: trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/queue/MojarraBean.java
===================================================================
--- trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/queue/MojarraBean.java	                        (rev 0)
+++ trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/queue/MojarraBean.java	2008-12-08 15:26:58 UTC (rev 11639)
@@ -0,0 +1,25 @@
+package org.richfaces.demo.queue;
+
+
+import java.util.Random;
+
+import javax.faces.event.ActionEvent;
+
+/**
+ * <p>This simple bean conains one <code>ActionEvent</code>
+ * handler to simulate random processing times for 
+ * requests on the server.
+ * <p/>
+ *
+ */
+public class MojarraBean {
+
+    public void process(ActionEvent ae) {
+        Random generator2 = new Random(System.currentTimeMillis());
+        int delay = generator2.nextInt(6001) + 1;
+        try {
+            Thread.sleep(delay);
+        } catch (Exception e) {
+        }
+    }
+}

Modified: trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml	2008-12-08 15:18:10 UTC (rev 11638)
+++ trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml	2008-12-08 15:26:58 UTC (rev 11639)
@@ -413,6 +413,11 @@
   <managed-bean-class>org.richfaces.demo.editor.EditorBean</managed-bean-class>
   <managed-bean-scope>session</managed-bean-scope>
  </managed-bean>
+ <managed-bean>
+  <managed-bean-name>mojarraBean</managed-bean-name>
+  <managed-bean-class>org.richfaces.demo.queue.MojarraBean</managed-bean-class>
+  <managed-bean-scope>session</managed-bean-scope>
+ </managed-bean>
  <navigation-rule>
   <from-view-id>/richfaces/include/examples/wstep1.xhtml</from-view-id>
   <navigation-case>

Added: trunk/samples/richfaces-demo/src/main/webapp/css/queueStylesheet.css
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/css/queueStylesheet.css	                        (rev 0)
+++ trunk/samples/richfaces-demo/src/main/webapp/css/queueStylesheet.css	2008-12-08 15:26:58 UTC (rev 11639)
@@ -0,0 +1,90 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License").  You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code.  If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license."  If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above.  However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+.title-panel {
+    background-image: url('bgblack18.jpg');
+    height: 80px;
+    width: 900px;
+}
+
+.title-panel-text {
+    color: white;
+    font-family: 'Georgia','Times New Roman','times',serif;
+    font-size: 24px;
+    font-weight: bold;
+}
+
+.title-panel-subtext {
+    color: white;
+    font-family: 'Georgia','Times New Roman','times',serif;
+    font-size: 14px;
+    font-style: italic
+}
+
+body {
+    font-family: Arial, Helvetica, sans-serif;
+    font-size: 12px;
+}
+
+.panel-input-border {
+    border: 2px outset blue;
+    background-color: #e0eeee;
+}
+
+.panel-data-border {
+    border: 3px outset blue;
+    background-color: #e0eeee;
+}
+
+.keytitle {
+    font-family: Arial, Helvetica, sans-serif;
+    font-size: 16px;
+    color: #330066;
+}
+
+.ticker {
+    position: relative;
+    visibility: hidden;
+    font-size: 16px;
+}
+
+.serialize-border {
+    border: 4px outset red;
+}
+
+.queueCell {
+    background-color: #00ffff;
+}

Modified: trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/queue.xhtml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/queue.xhtml	2008-12-08 15:18:10 UTC (rev 11638)
+++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/queue.xhtml	2008-12-08 15:26:58 UTC (rev 11639)
@@ -3,22 +3,43 @@
       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">
-	<style>
-		.link{
-			width:40px;
-			height:40px;
-		}
-	</style>
-		<h:form>
-			<rich:dataGrid value="#{queueBean.buttons}" var="button" columns="4">
-				<rich:paint2D cacheable="false" paint="#{queueBean.paint}" data="#{button.color}">
-				</rich:paint2D>
-				<ui:remove>
-				<h:panelGroup layout="block" style="background-color: #{button.color}" styleClass="link">
-					<h:outputText value="#{button.name}"/>
-				</h:panelGroup>
-				</ui:remove>
-			</rich:dataGrid>
-		</h:form>
+	  xmlns:rich="http://richfaces.org/rich"
+	  xmlns:c="http://java.sun.com/jstl/core">
+	<a4j:loadScript src="/scripts/queueUi.js"/>
+	<a4j:loadStyle src="/css/queueStylesheet.js"/>
+	<h:form id="form1" prependId="false">
+		<a4j:queue />
+
+		<h:panelGrid columns="2" cellspacing="5">
+			<h:panelGrid id="board1" columns="6" border="1">
+				<f:facet name="header">
+					<h:outputText value="Ajax Requests" styleClass="keytitle" />
+				</f:facet>
+				
+				<c:forEach begin="0" end="17" step="1" var="i">
+					<h:panelGrid>
+						<a4j:commandButton id="_#{i}" image="queue/examples/resources/button2.gif"
+							style="height:50px;width:50px;"
+							onclick="buttonpush('_#{i}');"
+							oncomplete="buttonpop('_#{i}');"	
+							actionListener="#{mojarraBean.process}" />
+						<h:panelGrid cellpadding="5">
+								<h:outputText value="#{i}" style="font-weight:bold"/>
+						</h:panelGrid>
+					</h:panelGrid> 
+				</c:forEach>
+			</h:panelGrid>
+			<h:panelGrid>
+				<f:facet name="header">
+					<h:outputText value="Request Queue" styleClass="keytitle" />
+				</f:facet>
+				<table id="queuetable" border="1">
+					<tr id="tr1">
+					</tr>
+				</table>
+			</h:panelGrid>
+		</h:panelGrid>
+
+	</h:form>
+
 	</ui:composition>

Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/resources/bgblack18.jpg
===================================================================
(Binary files differ)


Property changes on: trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/resources/bgblack18.jpg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/resources/button2.gif
===================================================================
(Binary files differ)


Property changes on: trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/resources/button2.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/resources/button3.gif
===================================================================
(Binary files differ)


Property changes on: trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/resources/button3.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/usage.xhtml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/usage.xhtml	2008-12-08 15:18:10 UTC (rev 11638)
+++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/usage.xhtml	2008-12-08 15:26:58 UTC (rev 11639)
@@ -8,8 +8,16 @@
 	<ui:composition template="/templates/component-sample.xhtml">
 		<ui:define name="sample">
 		<p>
-			DESCRIPTION
+			The <b>Ajax Requests</b> area represent individual Ajax requests that can be fired by clicking the green images (a4j:commandLink components).
+		    A <i>JSF managed bean</i> on the server causes a random sleep time (4 seconds or less) to simulate  
+			different processing times for each request.  The &lt;a4j:queue/&gt; (defined as global 
+			for the form where controls placed)	handles all the requests and fires next one only after
+			the responce from previous returned.
 		</p>
+		<p>
+			The demo JavaScript on the client includes a function that subscribes to these queue events, so the UI is updated as queue events happen.<br />
+			Just click on any sequence of green images (any number, any order) and you will see that each request is handled in the order they were fired.
+		</p>
 
 			<fieldset class="demo_fieldset">
 				<legend class="demo_legend">Queue demo</legend>

Added: trunk/samples/richfaces-demo/src/main/webapp/scripts/queueUi.js
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/scripts/queueUi.js	                        (rev 0)
+++ trunk/samples/richfaces-demo/src/main/webapp/scripts/queueUi.js	2008-12-08 15:26:58 UTC (rev 11639)
@@ -0,0 +1,50 @@
+var disabledImage = 'queue/examples/resources/button3.gif';
+var enabledImage = 'queue/examples/resources/button2.gif';
+
+function buttonpush(buttonName) {
+    var button = document.getElementById(buttonName);
+    if (!button.disabled) {
+        button.src = disabledImage;
+        button.disabled = true;
+    }
+    var txt = document.createTextNode(buttonName);
+    addCell(txt);
+} 
+
+function buttonpop(buttonName) {
+    var txt = document.createTextNode(buttonName);
+    removeCell(txt);
+} 
+
+function addCell(cellData) {
+    var cell = document.getElementById("tr1").insertCell(0);
+    cell.setAttribute("height", "50px");
+    cell.setAttribute("width", "50px");
+    cell.innerHTML = cellData.nodeValue;
+    cell.className = "queueCell";
+}
+
+function removeCell(cellData) {
+    var row = document.getElementById("tr1");
+    var cells = row.getElementsByTagName("td");
+    if (typeof cells != 'undefined' || cells != null) {
+        for (var i=0; i<cells.length; i++) {
+            if (cells[i].firstChild.nodeValue == cellData.nodeValue) {
+                row.deleteCell(i);
+                var button = document.getElementById(cellData.nodeValue);
+                button.disabled = false;
+                button.src = enabledImage;
+                break;
+            }
+        }
+    }
+}
+
+function errorMsg(eventName, data) {
+    alert("Name: "+eventName+" Error Status: "+data.statusMessage);
+}
+
+// Listen for all queue events
+//OpenAjax.hub.subscribe("javax.faces.Event.**",msg);
+// Listen for all error events
+//OpenAjax.hub.subscribe("javax.faces.Error.**",errorMsg);
\ No newline at end of file




More information about the richfaces-svn-commits mailing list