[richfaces-svn-commits] JBoss Rich Faces SVN: r6379 - trunk/ui/dataTable/src/main/java/org/richfaces/renderkit.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Wed Feb 27 11:18:42 EST 2008


Author: sergeyhalipov
Date: 2008-02-27 11:18:42 -0500 (Wed, 27 Feb 2008)
New Revision: 6379

Modified:
   trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
Log:
Inputs for filter value. Some optimization.

Modified: trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
===================================================================
--- trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java	2008-02-27 16:13:27 UTC (rev 6378)
+++ trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java	2008-02-27 16:18:42 UTC (rev 6379)
@@ -55,6 +55,8 @@
 	
 	private static final String FILTER_INPUT_FACET_NAME = "filterValueInput";
 	
+	private static final String SPACER_PATH = "/org/richfaces/renderkit/html/images/spacer.gif";
+	
 	/**
 	 * Encode all table structure - colgroups definitions, caption, header,
 	 * footer
@@ -111,7 +113,7 @@
 						headerClass, "th");
 			}
 
-			if (headers.hasNext()&&findFacet(table,"header")) {
+			if (headers.hasNext()) {
 				writer.startElement("tr", table);
 				encodeStyleClass(writer, null,
 						"dr-table-subheader rich-table-subheader", null,
@@ -126,20 +128,8 @@
 		}
 	}
 	
-	public boolean findFacet(UIDataTable table, String facetName)
-	{
-		Iterator iter = columnFacets(table,facetName);
-		boolean find = false;
-		while(iter.hasNext()){
-			UIComponent comp = (UIComponent) iter.next();
-			if(comp.getFacet(facetName)!=null)
-			{
-				find = true;
-				break;
-			}
-		
-		}
-		return find;
+	public boolean findFacet(UIDataTable table, String facetName) {
+		return columnFacets(table,facetName).hasNext();
 	}
 	
 	protected void encodeHeaderFacets(FacesContext context,
@@ -147,7 +137,7 @@
 			String headerClass, String facetName, String element, int colCount)
 			throws IOException {
 		int t_colCount = 0;
-		String spacerUrl = getResource("/org/richfaces/renderkit/html/images/spacer.gif").getUri(context, null);
+		String spacerUrl = getResource(SPACER_PATH).getUri(context, null);
 		while (headers.hasNext()) {
 			UIComponent column = (UIComponent) headers.next();
 			if((Integer)column.getAttributes().get("colspan")!=null){
@@ -167,8 +157,13 @@
 					columnHeaderClass);
 			writer.writeAttribute("scope", "col", null);			
 			getUtils().encodeAttribute(context, column, "colspan");
-
-			if (column instanceof org.richfaces.component.UIColumn) {
+			
+			boolean richHeader = column instanceof org.richfaces.component.UIColumn
+				&& "header".equals(facetName);
+			boolean sortableColumn = column.getValueExpression("comparator") != null 
+				|| column.getValueExpression("sortBy") != null;
+			
+			if (richHeader) {
 				org.richfaces.component.UIColumn col = 
 					(org.richfaces.component.UIColumn) column;
 				String clientId = col.getClientId(context) + facetName;
@@ -176,24 +171,9 @@
 				
 				writer.startElement(HTML.DIV_ELEM, column);
 				
-				if (column.getValueExpression("comparator") != null
-						|| column.getValueExpression("sortBy") != null) {
-					StringBuffer buffer;
+				if (sortableColumn) {
 					if (col.isSelfSorted()) {
-						UIComponent table = column.getParent();
-						String id = table.getClientId(context);
-						JSFunction ajaxFunction = AjaxRendererUtils
-								.buildAjaxFunction(table, context);
-						Map eventOptions = AjaxRendererUtils.buildEventOptions(
-								context, table);
-						Map parameters = (Map) eventOptions.get("parameters");
-						parameters.put(id, SORT_FILTER_PARAMETER);
-						parameters.put(SORT_FILTER_PARAMETER, column
-								.getClientId(context));
-						ajaxFunction.addParameter(eventOptions);
-						buffer = new StringBuffer();
-						ajaxFunction.appendScript(buffer);
-						writer.writeAttribute(HTML.onclick_ATTRIBUTE, buffer
+						writer.writeAttribute(HTML.onclick_ATTRIBUTE, buildAjaxFunction(context, column, true)
 								.toString(), null);
 						writer.writeAttribute(HTML.class_ATTRIBUTE, "dr-table-cursor-pointer", null);
 					}
@@ -212,11 +192,10 @@
 			if (facet != null) {
 				renderChild(context, facet);
 			}
-			if (column instanceof org.richfaces.component.UIColumn) {
-				if (column.getValueExpression("comparator") != null
-						|| column.getValueExpression("sortBy") != null) {
-					org.richfaces.component.UIColumn col = 
-						(org.richfaces.component.UIColumn) column;
+			if (richHeader) {
+				org.richfaces.component.UIColumn col = 
+					(org.richfaces.component.UIColumn) column;
+				if (sortableColumn) {
 					if (Ordering.ASCENDING.equals(col.getSortOrder()) ||
 							Ordering.DESCENDING.equals(col.getSortOrder())) {
 						writer.startElement(HTML.IMG_ELEMENT, column);
@@ -229,21 +208,12 @@
 				
 				writer.endElement(HTML.DIV_ELEM);
 				
-				if (((org.richfaces.component.UIColumn)column).getFilterMethod() == null
-						&& column.getValueExpression("filterExpression") == null
-						&& column.getValueExpression("filterBy") != null) {
-					UIComponent table = column.getParent();
-					String id = table.getClientId(context);
-					JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(table, context);
-					Map eventOptions = AjaxRendererUtils.buildEventOptions(context, table);
-					Map parameters = (Map) eventOptions.get("parameters");
-					parameters.put(id, SORT_FILTER_PARAMETER);
-					ajaxFunction.addParameter(eventOptions);
-					StringBuffer buffer = new StringBuffer();
-					ajaxFunction.appendScript(buffer);
+				if (col.getFilterMethod() == null
+						&& col.getValueExpression("filterExpression") == null
+						&& col.getValueExpression("filterBy") != null) {
 					
 					writer.startElement(HTML.DIV_ELEM, column);
-					addInplaceInput(context, column, buffer);
+					addInplaceInput(context, column, buildAjaxFunction(context, column, false));
 					writer.endElement(HTML.DIV_ELEM);
 				}
 		}
@@ -565,10 +535,9 @@
 			filterValueInput.setImmediate(true);
 			column.getFacets().put(FILTER_INPUT_FACET_NAME, filterValueInput);
 		}
-		String event = inplaceInput ? "onviewactivated" : "onchange";
 		String onkeydownEvent = inplaceInput ? "oninputkeydown" : "onkeydown";
 		
-		filterValueInput.getAttributes().put(event, buffer.toString());
+		filterValueInput.getAttributes().put("onchange", buffer.toString());
 		filterValueInput.getAttributes().put(onkeydownEvent, "RichFaces.blurFilterInput(event);");
 		filterValueInput.setValue(column.getAttributes().get("filterValue"));
 		
@@ -576,4 +545,21 @@
 		renderChild(context, filterValueInput);
 		getUtils().encodeEndFormIfNessesary(context, column);
 	}
+	
+	private StringBuffer buildAjaxFunction(FacesContext context, UIComponent column, boolean sortable) {
+		UIComponent table = column.getParent();
+		String id = table.getClientId(context);
+		JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(table, context);
+		Map eventOptions = AjaxRendererUtils.buildEventOptions(context, table);
+		Map parameters = (Map) eventOptions.get("parameters");
+		parameters.put(id, SORT_FILTER_PARAMETER);
+		if (sortable) {
+			parameters.put(SORT_FILTER_PARAMETER, column.getClientId(context));
+		}
+		ajaxFunction.addParameter(eventOptions);
+		StringBuffer buffer = new StringBuffer();
+		ajaxFunction.appendScript(buffer);
+		
+		return buffer;
+	}
 }
\ No newline at end of file




More information about the richfaces-svn-commits mailing list