Author: nbelaevski
Date: 2008-11-24 19:46:49 -0500 (Mon, 24 Nov 2008)
New Revision: 11345
Added:
trunk/samples/queue-sample/src/main/java/org/richfaces/MojarraBean.java
trunk/samples/queue-sample/src/main/webapp/mojarra.xhtml
trunk/samples/queue-sample/src/main/webapp/resources/
trunk/samples/queue-sample/src/main/webapp/resources/bgblack18.jpg
trunk/samples/queue-sample/src/main/webapp/resources/button2.gif
trunk/samples/queue-sample/src/main/webapp/resources/button3.gif
trunk/samples/queue-sample/src/main/webapp/resources/stylesheet.css
trunk/samples/queue-sample/src/main/webapp/resources/ui.js
Modified:
trunk/samples/queue-sample/src/main/webapp/WEB-INF/faces-config.xml
trunk/samples/queue-sample/src/main/webapp/WEB-INF/web.xml
Log:
JSF 2.0 queue demo rewritten
Added: trunk/samples/queue-sample/src/main/java/org/richfaces/MojarraBean.java
===================================================================
--- trunk/samples/queue-sample/src/main/java/org/richfaces/MojarraBean.java
(rev 0)
+++ trunk/samples/queue-sample/src/main/java/org/richfaces/MojarraBean.java 2008-11-25
00:46:49 UTC (rev 11345)
@@ -0,0 +1,25 @@
+package org.richfaces;
+
+
+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/queue-sample/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- trunk/samples/queue-sample/src/main/webapp/WEB-INF/faces-config.xml 2008-11-24
23:02:49 UTC (rev 11344)
+++ trunk/samples/queue-sample/src/main/webapp/WEB-INF/faces-config.xml 2008-11-25
00:46:49 UTC (rev 11345)
@@ -13,6 +13,11 @@
<managed-bean-class>org.richfaces.OversizeBean</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.MojarraBean</managed-bean-class>
+ <managed-bean-scope>application</managed-bean-scope>
+ </managed-bean>
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
Modified: trunk/samples/queue-sample/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/samples/queue-sample/src/main/webapp/WEB-INF/web.xml 2008-11-24 23:02:49 UTC
(rev 11344)
+++ trunk/samples/queue-sample/src/main/webapp/WEB-INF/web.xml 2008-11-25 00:46:49 UTC
(rev 11345)
@@ -24,10 +24,10 @@
<param-name>org.richfaces.LoadStyleStrategy</param-name>
<param-value>DEFAULT</param-value>
</context-param>
- <!-- context-param>
+ <context-param>
<param-name>org.richfaces.LoadScriptStrategy</param-name>
- <param-value>NONE</param-value>
- </context-param -->
+ <param-value>DEFAULT</param-value>
+ </context-param>
<!--
-->
Added: trunk/samples/queue-sample/src/main/webapp/mojarra.xhtml
===================================================================
--- trunk/samples/queue-sample/src/main/webapp/mojarra.xhtml (rev
0)
+++ trunk/samples/queue-sample/src/main/webapp/mojarra.xhtml 2008-11-25 00:46:49 UTC (rev
11345)
@@ -0,0 +1,78 @@
+<!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:a4j="http://richfaces.org/a4j"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:c="http://java.sun.com/jstl/core">
+<f:view contentType="text/html" />
+
+<head>
+ <meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
+ <title>Ajax</title>
+ <link type="text/css" href="resources/stylesheet.css"
rel="stylesheet" />
+ <script src="resources/ui.js"></script>
+</head>
+
+
+<body>
+
+ <h:form id="form1" prependId="false">
+ <a4j:queue />
+
+ <h:panelGrid styleClass="title-panel">
+ <h:panelGrid columns="2" cellpadding="20">
+ <h:outputText value="a j a x R e q u e s t"
+ styleClass="title-panel-text" />
+ <h:outputText value="Q u e u e" styleClass="title-panel-text"
/>
+ </h:panelGrid>
+ <h:outputText value="Powered By RichFaces 3.3.0 "
+ styleClass="title-panel-subtext" />
+ </h:panelGrid>
+
+ <h:panelGrid border="1">
+ <f:facet name="header">
+ <h:outputText value="Instructions" styleClass="keytitle"
/>
+ </f:facet>
+ The <b>Ajax Requests</b> area represent individual Ajax requests that can
be fired by clicking the green images. Each click fires a <br />
+ <i>jsf.ajaxRequest</i>. A <i>JSF managed bean</i> on the
server causes a random sleep time (4 seconds or less) to simulate <br />
+ different processing times for each request. The JSF 2.0 Ajax request queue on the
client uses the <i>observer</i> pattern to "record" queue events as
they happen.<br />
+ 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.
+ </h:panelGrid>
+
+ <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="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}" />
+ </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>
+
+</body>
+
+</html>
Added: trunk/samples/queue-sample/src/main/webapp/resources/bgblack18.jpg
===================================================================
(Binary files differ)
Property changes on: trunk/samples/queue-sample/src/main/webapp/resources/bgblack18.jpg
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/samples/queue-sample/src/main/webapp/resources/button2.gif
===================================================================
(Binary files differ)
Property changes on: trunk/samples/queue-sample/src/main/webapp/resources/button2.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/samples/queue-sample/src/main/webapp/resources/button3.gif
===================================================================
(Binary files differ)
Property changes on: trunk/samples/queue-sample/src/main/webapp/resources/button3.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/samples/queue-sample/src/main/webapp/resources/stylesheet.css
===================================================================
--- trunk/samples/queue-sample/src/main/webapp/resources/stylesheet.css
(rev 0)
+++ trunk/samples/queue-sample/src/main/webapp/resources/stylesheet.css 2008-11-25
00:46:49 UTC (rev 11345)
@@ -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;
+}
Added: trunk/samples/queue-sample/src/main/webapp/resources/ui.js
===================================================================
--- trunk/samples/queue-sample/src/main/webapp/resources/ui.js
(rev 0)
+++ trunk/samples/queue-sample/src/main/webapp/resources/ui.js 2008-11-25 00:46:49 UTC
(rev 11345)
@@ -0,0 +1,50 @@
+var disabledImage = 'resources/button3.gif';
+var enabledImage = '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