[richfaces-svn-commits] JBoss Rich Faces SVN: r11810 - in trunk/samples/richfaces-demo/src/main: resources/org/richfaces/demo/common and 4 other directories.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Tue Dec 16 08:53:24 EST 2008
Author: ilya_shaikovsky
Date: 2008-12-16 08:53:24 -0500 (Tue, 16 Dec 2008)
New Revision: 11810
Modified:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/queue/QueueBean.java
trunk/samples/richfaces-demo/src/main/resources/org/richfaces/demo/common/components.properties
trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/customization.xhtml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/queue.xhtml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/repeater.xhtml
trunk/samples/richfaces-demo/src/main/webapp/scripts/queueUi.js
Log:
Modified: trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/queue/QueueBean.java
===================================================================
--- trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/queue/QueueBean.java 2008-12-16 13:41:37 UTC (rev 11809)
+++ trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/queue/QueueBean.java 2008-12-16 13:53:24 UTC (rev 11810)
@@ -2,14 +2,9 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
-import org.ajax4jsf.event.AjaxEvent;
-
public class QueueBean {
public int requestDelay = 500;
public boolean ignoreDupResponces = false;
@@ -19,7 +14,6 @@
public String text="";
public int requests=0;
public int events=0;
- private static final String AJAX_REQUESTS_COUNT_ATTRIBUTE = "ajaxRequestsCount";
public List<SelectItem> strategies = new ArrayList<SelectItem>();
@@ -35,21 +29,13 @@
}
public void waitDelay() throws InterruptedException {
- System.out.println("QueueBean.waitDelay()");
Thread.sleep(1000);
}
- public void processAjax(AjaxEvent event) {
- ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
- Map<String, Object> sessionMap = externalContext.getSessionMap();
- Long count = (Long) sessionMap.get(AJAX_REQUESTS_COUNT_ATTRIBUTE);
- if (count == null) {
- count = Long.valueOf(0);
- }
- sessionMap.put(AJAX_REQUESTS_COUNT_ATTRIBUTE, ++count);
+ public void resetText() {
+ setText("");
}
-
public int getRequestDelay() {
return requestDelay;
}
Modified: trunk/samples/richfaces-demo/src/main/resources/org/richfaces/demo/common/components.properties
===================================================================
--- trunk/samples/richfaces-demo/src/main/resources/org/richfaces/demo/common/components.properties 2008-12-16 13:41:37 UTC (rev 11809)
+++ trunk/samples/richfaces-demo/src/main/resources/org/richfaces/demo/common/components.properties 2008-12-16 13:53:24 UTC (rev 11810)
@@ -90,4 +90,4 @@
stateAPI=richMisc, \t State Manager API, \t\t/images/ico_StateManagerAPI.gif, \t\t/images/cn_StateManagerAPI.gif, ArchitectureOverview.html\#statemanagerapi, jbossrichfaces/freezone/docs/tlddoc/rich/graphValidator.html, jbossrichfaces/freezone/docs/apidoc/org/richfaces/component/UIhotkey.html, \t\t\t\t\t/richfaces/stateAPI.jsf
extendedDataTable= richDataIterators, Extended Data Table, /images/ico_ExtendedDataTable.gif, /images/cn_ExtendedDataTable.gif, extendedDataTable.html, jbossrichfaces/freezone/docs/tlddoc/rich/dataTable.html, jbossrichfaces/freezone/docs/apidoc/org/richfaces/component/UIDataTable.html, /richfaces/extendedDataTable.jsf
editor= richInputs, Editor, /images/ico_Editor.gif, /images/cn_Editor.gif, editor.html, jbossrichfaces/freezone/docs/tlddoc/rich/editor.html, jbossrichfaces/freezone/docs/apidoc/org/richfaces/component/UIEditor.html, /richfaces/editor.jsf
-queue= ajaxSupport, Queue, /images/ico_Queue.gif, /images/cn_Queue.gif, Queue.html, jbossrichfaces/freezone/docs/tlddoc/rich/queue.html, jbossrichfaces/freezone/docs/apidoc/org/richfaces/component/UIQueue.html, /richfaces/queue.jsf
+queue= ajaxSupport, Queue, /images/ico_common.gif, /images/cn_Queue.gif, Queue.html, jbossrichfaces/freezone/docs/tlddoc/rich/queue.html, jbossrichfaces/freezone/docs/apidoc/org/richfaces/component/UIQueue.html, /richfaces/queue.jsf
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-16 13:41:37 UTC (rev 11809)
+++ trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml 2008-12-16 13:53:24 UTC (rev 11810)
@@ -481,6 +481,14 @@
<to-view-id>/richfaces/stateAPI/examples/simple.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
+ <navigation-rule>
+ <display-name>ajaxOptimization</display-name>
+ <from-view-id>/richfaces/queue.xhtml</from-view-id>
+ <navigation-case>
+ <from-outcome>ajaxOptimization</from-outcome>
+ <to-view-id>/richfaces/ajaxAttributes.xhtml</to-view-id>
+ </navigation-case>
+ </navigation-rule>
<application>
<navigation-handler>org.richfaces.ui.application.StateNavigationHandler</navigation-handler>
<el-resolver>org.richfaces.el.StateELResolver</el-resolver>
Modified: trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/customization.xhtml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/customization.xhtml 2008-12-16 13:41:37 UTC (rev 11809)
+++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/customization.xhtml 2008-12-16 13:53:24 UTC (rev 11810)
@@ -8,8 +8,35 @@
<ui:composition template="/templates/component-sample.xhtml">
<ui:define name="sample">
<p>
- Description
+ There you could explore <b>optimization </b>parameters of the <b>queue
+ </b>and learn how them influence the <b>Ajax requests</b>. This example
+ is a good start to learn about Ajax requests flood protection.
</p>
+
+ <p>
+ Pay attention to some points in the example:
+ </p>
+ <ul>
+ <li>
+ Setting ignoreDupResponces to true - will reduce the count of DOM updates on typing inside input.
+ (in initial state - count of updates will be equals to count of requests)
+ </li>
+ <li>
+ Disabling the queue will causes fully asynchronous updates. Note
+ that updates could appears not in the right order and you could get
+ wrong string in the result.
+ </li>
+ <li>
+ Setting request delay to greater value will reduce the requests count
+ on fast typing. (More similar requests will be combined in the result)
+ </li>
+ </ul>
+ <p><i>
+
+ Also pay your attention to the queue definition. As it mentioned in
+ our documentation such definition (inside some form without name)
+ means that the queue becomes global for the form.
+ </i></p>
<fieldset class="demo_fieldset">
<legend class="demo_legend">Queue demo</legend>
<div class="sample-container">
@@ -18,8 +45,64 @@
<ui:param name="sourcepath" value="/richfaces/queue/examples/repeater.xhtml"/>
<ui:param name="openlabel" value="View Source" />
</ui:include>
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcepath" value="/WEB-INF/src/org/richfaces/demo/queue/QueueBean.java"/>
+ <ui:param name="openlabel" value="View QueueBean.java code" />
+ <ui:param name="sourcetype" value="java" />
+ </ui:include>
</div>
</fieldset>
+ <h:form>
+ <p>
+ <b>Queue</b> provides subset of common <b>Ajax requests optimization attributes</b>
+ (<i>requestDelay, ignoreDupResponse and timeout</i>)
+ which you could explore at <h:commandLink value="Queue and Traffic Flood Protection" immediate="true" action="ajaxOptimization"/> section.
+ These attributes defined within the queue will be used for all the request
+ in case concrete components do not override them.
+ </p>
+ </h:form>
+ <p>The queue component also provides some additional attributes in order to
+ control queue itself:
+ </p>
+ <ul>
+ <li>
+ <b>name</b> attribute which defines name for the queue.
+ </li>
+ <li>
+ <b>disabled</b> - attribute which allows to disable the queue.
+ Could be used in order to disable the global queue for particular
+ views or in order to switch between same named queues with different
+ parameters.
+ </li>
+ <li>
+ <b>size</b> - Defines the count of requests which could be queued
+ at the moment. -1 value means that queue has no size limit.
+ </li>
+ <li>
+ <b>sizeExceededBehavior</b> - defines the behavior for the queue
+ if size already exceeded and new request tried to be added to
+ the queue. (dropNew, dropNext, fireNew, fireNext values allowed)
+ </li>
+ <li>
+ <b>status</b> - attribute which allows to point status component
+ to all the requests from the particular queue.
+ </li>
+ </ul>
+ <p><i>
+
+ Also pay your attention to the queue definition. As it mentioned in
+ our documentation such definition (inside some form without name)
+ means that the queue becomes global for the form.
+ </i></p>
+ <p class="note">
+ <i><b>Note:</b></i> queue component could get its parameters from
+ EL bindings. But the component isn't designed to be updated via
+ ajax requests. (There are no useful cases where the developers
+ need to change the timeouts or request delays on the fly). So
+ as you could see the example below uses <b>h:commandButton</b> in order to
+ reebuild all the view and reinitialize the queue with new parameter
+ values.
+ </p>
</ui:define>
</ui:composition>
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-16 13:41:37 UTC (rev 11809)
+++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/queue.xhtml 2008-12-16 13:53:24 UTC (rev 11810)
@@ -10,7 +10,7 @@
<h:form id="form1" prependId="false">
<a4j:queue requestDelay="1000" ignoreDupResponce="true"/>
- <h:panelGrid columns="2" cellspacing="5">
+ <h:panelGrid columns="1" cellspacing="5">
<h:panelGrid id="board1" columns="6" border="1">
<f:facet name="header">
<h:outputText value="Ajax Requests" styleClass="keytitle" />
Modified: trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/repeater.xhtml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/repeater.xhtml 2008-12-16 13:41:37 UTC (rev 11809)
+++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/queue/examples/repeater.xhtml 2008-12-16 13:53:24 UTC (rev 11810)
@@ -15,7 +15,7 @@
<h:panelGrid columns="2">
<h:outputText value="Type here:" />
<h:inputText id="myinput" value="#{queueBean.text}">
- <a4j:support event="onkeyup" reRender="outtext,reqs"
+ <a4j:support event="onkeyup" reRender="outtext"
onsubmit="addEvent();" ajaxSingle="true"
oncomplete="printCounts()"
onbeforedomupdate="addUpdate()" action="#{queueBean.waitDelay}"/>
@@ -54,15 +54,11 @@
<h:outputText value="Disable Queue" />
<h:selectBooleanCheckbox value="#{queueBean.disabled}" />
<f:facet name="footer">
- <h:panelGroup>
- <h:commandButton value="Apply"/>
- <h:commandButton value="Reset"/>
- </h:panelGroup>
+ <h:commandButton value="Apply" action="#{queueBean.resetText}"/>
</f:facet>
</h:panelGrid>
</rich:panel>
</h:panelGrid>
- <a4j:log popup="false" style="width:800px; height:400px; overflow:auto;"/>
</h:form>
<script type="text/javascript">
var events=0;
Modified: trunk/samples/richfaces-demo/src/main/webapp/scripts/queueUi.js
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/scripts/queueUi.js 2008-12-16 13:41:37 UTC (rev 11809)
+++ trunk/samples/richfaces-demo/src/main/webapp/scripts/queueUi.js 2008-12-16 13:53:24 UTC (rev 11810)
@@ -41,19 +41,27 @@
function removeCell(cellData) {
var row = document.getElementById("tr1");
var cells = row.getElementsByTagName("td");
+ var deletedCellIndex=-1;
if (cells.length==1) {
lastButtonActivated=undefined;
lastButtonCounter=undefined;
}
if (typeof cells != 'undefined' || cells != null) {
- for (var i=0; i<cells.length; i++) {
+ for (var i=cells.length-1; i>=0; i--) {
if (cells[i].firstChild.nodeValue.indexOf(cellData.nodeValue)==0) {
- row.deleteCell(i);
+ if (deletedCellIndex==-1){
+ deletedCellIndex=i;
+ row.deleteCell(i);
+ }else{
+ deletedCellIndex=-1;
+ break;
+ }
+ }
+ }
+ if (deletedCellIndex!=-1){
var button = document.getElementById(cellData.nodeValue);
button.value = 'submit';
button.src = enabledImage;
- break;
- }
}
}
}
More information about the richfaces-svn-commits
mailing list