[richfaces-svn-commits] JBoss Rich Faces SVN: r5207 - in branches/3.1.x: samples/richfaces-demo/src/main/webapp/WEB-INF and 2 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Tue Jan 8 18:46:08 EST 2008


Author: alexsmirnov
Date: 2008-01-08 18:46:08 -0500 (Tue, 08 Jan 2008)
New Revision: 5207

Added:
   branches/3.1.x/samples/scrollableDataTableDemo/src/main/webapp/pages/testScript.xhtml
Modified:
   branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/component/UIDataAdaptor.java
   branches/3.1.x/samples/richfaces-demo/src/main/webapp/WEB-INF/web.xml
   branches/3.1.x/ui/scrollableDataTable/src/main/javascript/ClientUI/common/utils/Utils.js
Log:
Few data table/grid optimisations

Modified: branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/component/UIDataAdaptor.java
===================================================================
--- branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/component/UIDataAdaptor.java	2008-01-08 20:58:35 UTC (rev 5206)
+++ branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/component/UIDataAdaptor.java	2008-01-08 23:46:08 UTC (rev 5207)
@@ -23,10 +23,12 @@
 
 import java.io.IOException;
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -806,7 +808,11 @@
 	 * Saved values of {@link EditableValueHolder} fields per iterations.
 	 */
 	private Map childState;
+	
+	private List allDataChildren = null;
 
+	private List editableDataChildren = null;
+
 	/**
 	 * @param faces
 	 * @return Saved values of {@link EditableValueHolder} fields per
@@ -826,19 +832,30 @@
 	}
 
 	/**
-	 * Save values of {@link EditableValueHolder} fields before change current
-	 * row.
+	 * Save values of {@link EditableValueHolder} fields before change
+	 * current row.
 	 * 
 	 * @param faces
 	 */
-	protected void saveChildState(FacesContext faces) {
+    protected void saveChildState(FacesContext faces) {
+	Map childState = this.getChildState(faces);
+	if (null == editableDataChildren) {
+	    allDataChildren = new ArrayList();
+	    editableDataChildren = new ArrayList();
+	    Iterator itr = dataChildren();
+	    while (itr.hasNext()) {
+		this
+			.saveChildState(faces, (UIComponent) itr.next(),
+				childState);
+	    }
 
-		Iterator itr = dataChildren();
-		while (itr.hasNext()) {
-			Map childState = this.getChildState(faces);
-			this.saveChildState(faces, (UIComponent) itr.next(), childState);
-		}
+	} else {
+	    for (Iterator c = editableDataChildren.iterator(); c.hasNext();) {
+		UIComponent child = (UIComponent) c.next();
+		populateChildState(faces, child, childState);
+	    }
 	}
+    }
 
 	/**
 	 * Recursive method for Iterate on children for save
@@ -850,15 +867,10 @@
 	 */
 	private void saveChildState(FacesContext faces, UIComponent c,
 			Map childState) {
-
-		if (c instanceof EditableValueHolder && !c.isTransient()) {
-			String clientId = c.getClientId(faces);
-			SavedState ss = (SavedState) childState.get(clientId);
-			if (ss == null) {
-				ss = new SavedState();
-				childState.put(clientId, ss);
-			}
-			ss.populate((EditableValueHolder) c);
+	    	allDataChildren.add(c);
+		if (c instanceof EditableValueHolder ) {
+			populateChildState(faces, c, childState);
+			editableDataChildren.add(c);
 		}
 
 		// continue hack
@@ -873,19 +885,52 @@
 	}
 
 	/**
-	 * Restore values of {@link EditableValueHolder} fields after change current
-	 * row.
+	 * @param faces
+	 * @param c
+	 * @param childState
+	 */
+	private void populateChildState(FacesContext faces, UIComponent c,
+		Map childState) {
+	    String clientId = c.getClientId(faces);
+	    SavedState ss = (SavedState) childState.get(clientId);
+	    if (ss == null) {
+	    	ss = new SavedState();
+	    	childState.put(clientId, ss);
+	    }
+	    ss.populate((EditableValueHolder) c);
+	}
+
+	/**
+	 * Restore values of {@link EditableValueHolder} fields after change
+	 * current row.
 	 * 
 	 * @param faces
 	 */
-	protected void restoreChildState(FacesContext faces) {
+    protected void restoreChildState(FacesContext faces) {
+	Map childState = this.getChildState(faces);
 
-		Iterator itr = dataChildren();
-		while (itr.hasNext()) {
-			Map childState = this.getChildState(faces);
-			this.restoreChildState(faces, (UIComponent) itr.next(), childState);
-		}
+	if (null == editableDataChildren) {
+	    allDataChildren = new ArrayList();
+	    editableDataChildren = new ArrayList();
+	    Iterator itr = dataChildren();
+	    while (itr.hasNext()) {
+		this.restoreChildState(faces, (UIComponent) itr.next(),
+			childState);
+	    }
+
+	} else {
+	    for (Iterator c = allDataChildren.iterator(); c.hasNext();) {
+		UIComponent child = (UIComponent) c.next();
+		// reset id
+		String id = child.getId();
+		child.setId(id);
+	    }	    
+	    for (Iterator c = editableDataChildren.iterator(); c.hasNext();) {
+		UIComponent child = (UIComponent) c.next();
+		applyChildState(faces, child, childState);
+	    }	    
 	}
+    }
 
 	/**
 	 * Recursive part of
@@ -901,17 +946,11 @@
 		// reset id
 		String id = c.getId();
 		c.setId(id);
-
+	    	allDataChildren.add(c);
 		// hack
 		if (c instanceof EditableValueHolder) {
-			EditableValueHolder evh = (EditableValueHolder) c;
-			String clientId = c.getClientId(faces);
-			SavedState ss = (SavedState) childState.get(clientId);
-			if (ss != null) {
-				ss.apply(evh);
-			} else {
-				NullState.apply(evh);
-			}
+			applyChildState(faces, c, childState);
+			editableDataChildren.add(c);
 		}
 
 		// continue hack
@@ -926,6 +965,23 @@
 	}
 
 	/**
+	 * @param faces
+	 * @param c
+	 * @param childState
+	 */
+	private void applyChildState(FacesContext faces, UIComponent c,
+		Map childState) {
+	    EditableValueHolder evh = (EditableValueHolder) c;
+	    String clientId = c.getClientId(faces);
+	    SavedState ss = (SavedState) childState.get(clientId);
+	    if (ss != null) {
+	    	ss.apply(evh);
+	    } else {
+	    	NullState.apply(evh);
+	    }
+	}
+
+	/**
 	 * Check for validation errors on children components. If true, saved values
 	 * must be keep on render phase
 	 * 
@@ -1056,6 +1112,8 @@
 
 	public void encodeBegin(FacesContext context) throws IOException {
 		resetDataModel();
+		this.editableDataChildren = null;
+		this.allDataChildren = null;
 		if (!keepSaved(context)) {
 			childState.remove(getBaseClientId(context));
 		}

Modified: branches/3.1.x/samples/richfaces-demo/src/main/webapp/WEB-INF/web.xml
===================================================================
--- branches/3.1.x/samples/richfaces-demo/src/main/webapp/WEB-INF/web.xml	2008-01-08 20:58:35 UTC (rev 5206)
+++ branches/3.1.x/samples/richfaces-demo/src/main/webapp/WEB-INF/web.xml	2008-01-08 23:46:08 UTC (rev 5207)
@@ -37,6 +37,10 @@
  </context-param>
  <context-param>
   <param-name>org.ajax4jsf.COMPRESS_SCRIPT</param-name>
+  <param-value>true</param-value>
+ </context-param>
+ <context-param>
+  <param-name>org.ajax4jsf.COMPRESS_STYLE</param-name>
   <param-value>false</param-value>
  </context-param>
  <context-param>
@@ -45,11 +49,11 @@
  </context-param>
  	<!--context-param>
 		<param-name>org.richfaces.LoadStyleStrategy</param-name>
-		<param-value>ALL</param-value>
-	</context-param>
+		<param-value>DEFAULT</param-value>
+	</context-param-->
 	<context-param>
 		<param-name>org.richfaces.LoadScriptStrategy</param-name>
-		<param-value>ALL</param-value>
+		<param-value>DEFAULT</param-value>
 	</context-param-->
  
  <filter>

Added: branches/3.1.x/samples/scrollableDataTableDemo/src/main/webapp/pages/testScript.xhtml
===================================================================
--- branches/3.1.x/samples/scrollableDataTableDemo/src/main/webapp/pages/testScript.xhtml	                        (rev 0)
+++ branches/3.1.x/samples/scrollableDataTableDemo/src/main/webapp/pages/testScript.xhtml	2008-01-08 23:46:08 UTC (rev 5207)
@@ -0,0 +1,52 @@
+<!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:f="http://java.sun.com/jsf/core"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:ui="http://java.sun.com/jsf/facelets"
+	xmlns:sg="http://labs.jboss.com/jbossrichfaces/ui/scrollableDataTable"
+	xmlns:dt="http://labs.jboss.com/jbossrichfaces/ui/dataTable"
+	xmlns:a4j="http://richfaces.org/a4j">
+<head><title>JavaScript test</title></head>
+<body>
+<f:view>
+	<a4j:loadScript src="resource:///org/ajax4jsf/framework.pack.js"></a4j:loadScript>
+	<a4j:loadScript src="resource:///org/richfaces/renderkit/html/scripts/scrollable-data-table.js"></a4j:loadScript>
+	<h:form id="form">
+	<script type="text/javascript">
+	mockRequest = Class.create({
+	  initialize: function(element){
+	  	this.element = $(element);
+	  },
+	  getElementById: function(id){
+	    return this.element;
+	  }
+	});
+	function startTest(){
+	  LOG.debug("script started");
+	  var table=$("form:dt");
+	  var display=table.style.display;
+//	  table.style.display = 'none';
+	  var row=$("form:dt:1");
+	  var req = new mockRequest(row);
+	  LOG.debug("update started");
+	  Utils.DOM.replaceNode("form:dt:0",req);
+	  LOG.debug("script done");
+	  table.style.display = display;
+	};
+	</script>
+		<dt:dataTable id="dt" value="#{modelBuilder.model3}" var="issues" rowKeyVar="row"
+			frozenColCount="3" first="0" rows="40" width="100%" height="500px">
+		<dt:column colspan="19">
+			<h:outputText value="&lt;/td&gt;&lt;/tr&gt;&lt;tr id='form:dt:#{row}' class='dr-table-row rich-table-row'&gt;&lt;td class='dr-table-cell rich-table-cell'&gt;" escape="false"></h:outputText>
+		</dt:column>
+			<ui:include src="columns.xhtml">
+				<ui:param name="issues" value="#{issues}" />
+			</ui:include>
+		</dt:dataTable>
+		<a4j:status startText="loading..." stopText="done"/>
+		<input type="button" onclick="startTest()" value="run script"/>
+	</h:form>
+	<a4j:log popup="false" width="100%" height="800pt"></a4j:log>
+</f:view>
+</body>
+</html>


Property changes on: branches/3.1.x/samples/scrollableDataTableDemo/src/main/webapp/pages/testScript.xhtml
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: branches/3.1.x/ui/scrollableDataTable/src/main/javascript/ClientUI/common/utils/Utils.js
===================================================================
--- branches/3.1.x/ui/scrollableDataTable/src/main/javascript/ClientUI/common/utils/Utils.js	2008-01-08 20:58:35 UTC (rev 5206)
+++ branches/3.1.x/ui/scrollableDataTable/src/main/javascript/ClientUI/common/utils/Utils.js	2008-01-08 23:46:08 UTC (rev 5207)
@@ -60,15 +60,15 @@
 					target.parentNode.replaceChild(imported, target);;
 					return imported;
 					
-				} else if (ClientUILib.isGecko){
-					//Mozill family
-					var theDoc = document;
-					
-					Utils.DOM._clearAttributes(target);
-					Utils.DOM.copyAttributes(target, src);
-
-					target.innerHTML = src.innerHTML;//nnerHTML.join("");
-					return target;
+//				} else if (ClientUILib.isGecko){
+//					//Mozill family
+//					var theDoc = document;
+//					
+//					Utils.DOM._clearAttributes(target);
+//					Utils.DOM.copyAttributes(target, src);
+//
+//					target.innerHTML = src.innerHTML;//nnerHTML.join("");
+//					return target;
 				} else {
 					//Fall back to DOM, and cross the fingers
 					src = document.importNode(src, true);




More information about the richfaces-svn-commits mailing list