[richfaces-svn-commits] JBoss Rich Faces SVN: r6003 - in trunk/ui/dataTable/src/main: templates/org/richfaces and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon Feb 11 08:05:10 EST 2008


Author: konstantin.mishin
Date: 2008-02-11 08:05:10 -0500 (Mon, 11 Feb 2008)
New Revision: 6003

Modified:
   trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
   trunk/ui/dataTable/src/main/templates/org/richfaces/htmlDataTable.jspx
Log:
RF-1741

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-11 11:28:00 UTC (rev 6002)
+++ trunk/ui/dataTable/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java	2008-02-11 13:05:10 UTC (rev 6003)
@@ -23,6 +23,8 @@
 
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 import javax.faces.component.UIColumn;
 import javax.faces.component.UIComponent;
@@ -30,8 +32,8 @@
 import javax.faces.context.ResponseWriter;
 
 import org.ajax4jsf.component.UIDataAdaptor;
+import org.ajax4jsf.context.AjaxContext;
 import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.javascript.JSReference;
 import org.ajax4jsf.renderkit.AjaxRendererUtils;
 import org.ajax4jsf.renderkit.RendererUtils.HTML;
 import org.apache.commons.collections.Predicate;
@@ -46,6 +48,8 @@
  */
 public abstract class AbstractTableRenderer extends AbstractRowsRenderer {
 
+	private static final String FILTER_PARAMETER_VALUE = "f";
+	
 	/**
 	 * Encode all table structure - colgroups definitions, caption, header,
 	 * footer
@@ -163,37 +167,29 @@
 					(org.richfaces.component.UIColumn) column;
 				String clientId = col.getClientId(context) + facetName;
 				writer.writeAttribute("id", clientId, null);
-				if (col.isSortable()) {
-					String sortExpression = col.getSortExpression();
-					String sortMode = col.getSortMode();
-					if ("client".equals(sortMode)) {
-						JSFunction function = new JSFunction("new RichFaces.SortControl");
-						function.addParameter(clientId);
-						function.addParameter(((UIDataAdaptor)column.getParent()).getBaseClientId(context));
-						function.addParameter(new JSReference(sortExpression));
-						function.addParameter(column.getClientId(context));
-						getUtils().writeScript(context, column, function.toScript());
-					} else if ("ajax".equals(sortMode)) {
-						
-						//AjaxRendererUtils.buildOnClick(uiComponent, facesContext)
-						
-						JSFunction function = new JSFunction("new RichFaces.SortControl.Ajax");
-						function.addParameter(clientId);
-						getUtils().writeScript(context, column, function.toScript());
-						
-					} else {
-						JSFunction function = new JSFunction("new RichFaces.SortControl.Server");
-						function.addParameter(clientId);
-						getUtils().writeScript(context, column, function.toScript());
-					}
-					
-				}
 			}
 
 			UIComponent facet = column.getFacet(facetName);
 			if (facet != null) {
 				renderChild(context, facet);
 			}
+			if (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, FILTER_PARAMETER_VALUE);
+				ajaxFunction.addParameter(eventOptions);
+				StringBuffer buffer = new StringBuffer();
+				ajaxFunction.appendScript(buffer);
+				writer.startElement(HTML.INPUT_ELEM, column);
+				writer.writeAttribute(HTML.TYPE_ATTR, "text", null);
+				writer.writeAttribute(HTML.NAME_ATTRIBUTE, column.getClientId(context) + FILTER_PARAMETER_VALUE, null);
+				writer.writeAttribute(HTML.value_ATTRIBUTE, column.getAttributes().get("filterValue"), null);
+				writer.writeAttribute(HTML.onchange_ATTRIBUTE, buffer.toString(), null);
+				writer.endElement(HTML.INPUT_ELEM);				
+			}
 			
 			writer.endElement(element);
 			
@@ -452,4 +448,23 @@
 			getUtils().writeScript(context, component, function.toScript());
 		}
 	}
+	
+	@Override
+	protected void doDecode(FacesContext context, UIComponent component) {
+		Map<String, String> map = context.getExternalContext().getRequestParameterMap();
+		if (FILTER_PARAMETER_VALUE.equals(map.get(component.getClientId(context)))) {
+			List<UIComponent> list = component.getChildren();
+			for (Iterator<UIComponent> iterator = list.iterator(); iterator
+					.hasNext();) {
+				UIComponent children = iterator.next();
+				if (children instanceof org.richfaces.component.UIColumn) {
+					children.getAttributes().put("filterValue",
+							map.get(children.getClientId(context) + FILTER_PARAMETER_VALUE));
+				}
+
+			}
+			AjaxContext.getCurrentInstance()
+					.addComponentToAjaxRender(component);
+		}
+	}
 }
\ No newline at end of file

Modified: trunk/ui/dataTable/src/main/templates/org/richfaces/htmlDataTable.jspx
===================================================================
--- trunk/ui/dataTable/src/main/templates/org/richfaces/htmlDataTable.jspx	2008-02-11 11:28:00 UTC (rev 6002)
+++ trunk/ui/dataTable/src/main/templates/org/richfaces/htmlDataTable.jspx	2008-02-11 13:05:10 UTC (rev 6003)
@@ -13,7 +13,6 @@
 	component="org.richfaces.component.UIDataTable" 
 	>
 	<h:styles>css/table.xcss</h:styles>
-	<h:scripts>new org.ajax4jsf.javascript.PrototypeScript(),scripts/data-table.js</h:scripts>
 	<f:clientid var="clientId"/>
 	<table id="#{clientId}"
 	    class="dr-table rich-table #{component.attributes['styleClass']}" style="#{component.attributes['style']}" 
@@ -29,5 +28,4 @@
 				</vcp:body>
 		</tbody>
 	</table>
-	<f:call name="encodeScriptIfNecessary"/>
 </f:root>
\ No newline at end of file




More information about the richfaces-svn-commits mailing list