You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2006/04/28 10:09:59 UTC
svn commit: r397795 - in /myfaces/tomahawk/trunk:
core/src/main/java/org/apache/myfaces/component/html/ext/
core/src/main/java/org/apache/myfaces/custom/column/
core/src/main/tld/tomahawk-entities/ examples/simple/src/main/webapp/
Author: mmarinschek
Date: Fri Apr 28 01:09:56 2006
New Revision: 397795
URL: http://svn.apache.org/viewcvs?rev=397795&view=rev
Log:
TOMAHAWK-395 patch applied
Added:
myfaces/tomahawk/trunk/examples/simple/src/main/webapp/sortAutoTable2.jsp
Modified:
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/HtmlDataTable.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/column/HtmlColumnTag.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/column/HtmlSimpleColumn.java
myfaces/tomahawk/trunk/core/src/main/tld/tomahawk-entities/tomahawk_column_attributes.xml
myfaces/tomahawk/trunk/examples/simple/src/main/webapp/home.jsp
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/HtmlDataTable.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/HtmlDataTable.java?rev=397795&r1=397794&r2=397795&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/HtmlDataTable.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/ext/HtmlDataTable.java Fri Apr 28 01:09:56 2006
@@ -446,48 +446,66 @@
// into this object.
((UIColumns) component).encodeTableBegin(context);
}
- }
-
- if (isSortable())
+ }
+
+ //replace facet header content component of the columns, with a new command sort header component
+ //if sortable=true, replace it for all, if not just for the columns marked as sortable
+ for (Iterator iter = getChildren().iterator(); iter.hasNext();)
{
- //replace facet header content component of the columns, with a new command sort header component
- for (Iterator iter = getChildren().iterator(); iter.hasNext();)
+ UIComponent component = (UIComponent) iter.next();
+ if (component instanceof UIColumn)
{
- UIComponent component = (UIComponent) iter.next();
- if (component instanceof UIColumn)
+ UIColumn aColumn = (UIColumn)component;
+ UIComponent headerFacet = aColumn.getHeader();
+
+ boolean replaceHeaderFacets = isSortable(); //if the table is sortable, all
+ //header facets can be changed if needed
+ String columnName = null;
+ String propertyName = null;
+ boolean defaultSorted = false;
+
+ if (aColumn instanceof HtmlSimpleColumn)
{
- UIColumn aColumn = (UIColumn)component;
- UIComponent headerFacet = aColumn.getHeader();
+ HtmlSimpleColumn asColumn = (HtmlSimpleColumn)aColumn;
+ propertyName = asColumn.getSortPropertyName();
+ defaultSorted = asColumn.isDefaultSorted();
- String columnName = null;
+ if (asColumn.isSortable())
+ replaceHeaderFacets = true;
+ }
+
+ //replace header facet with a sortable header component if needed
+ if (replaceHeaderFacets && isSortHeaderNeeded(aColumn, headerFacet))
+ {
+ propertyName = propertyName != null ? propertyName : getSortPropertyFromEL(aColumn);
- if (isSortHeaderNeeded(aColumn, headerFacet))
- {
- HtmlCommandSortHeader sortHeader = createSortHeaderComponent(aColumn, headerFacet, context);
- columnName = sortHeader.getColumnName();
-
- aColumn.setHeader(sortHeader);
- }
- else
- {
- HtmlCommandSortHeader sortHeader = (HtmlCommandSortHeader)headerFacet;
- columnName = sortHeader.getColumnName();
- }
- //make the column marked as default sorted be the current sorted column
- if (aColumn instanceof HtmlSimpleColumn)
- {
- HtmlSimpleColumn tColumn = (HtmlSimpleColumn)aColumn;
- if (tColumn.isDefaultSorted() && getSortColumn() == null)
- setSortColumn(columnName);
- }
+ HtmlCommandSortHeader sortHeader = createSortHeaderComponent(context, aColumn, headerFacet, propertyName);
+ columnName = sortHeader.getColumnName();
+
+ aColumn.setHeader(sortHeader);
+ sortHeader.setParent(aColumn);
+ }
+ else if (headerFacet instanceof HtmlCommandSortHeader)
+ {
+ HtmlCommandSortHeader sortHeader = (HtmlCommandSortHeader)headerFacet;
+ columnName = sortHeader.getColumnName();
+ propertyName = sortHeader.getPropertyName();
+ }
+
+ //make the column marked as default sorted be the current sorted column
+ if (defaultSorted && getSortColumn() == null)
+ {
+ setSortColumn(columnName);
+ setSortProperty(propertyName);
}
}
- }
+ }
// Now invoke the superclass encodeBegin, which will eventually
// execute the encodeBegin for the associated renderer.
super.encodeBegin(context);
- }
+ }
+
/**
*
*/
@@ -498,7 +516,7 @@
/**
*
*/
- protected HtmlCommandSortHeader createSortHeaderComponent(UIColumn parentColumn, UIComponent initialHeaderFacet, FacesContext context)
+ protected HtmlCommandSortHeader createSortHeaderComponent(FacesContext context, UIColumn parentColumn, UIComponent initialHeaderFacet, String propertyName)
{
Application application = context.getApplication();
@@ -506,10 +524,11 @@
String id = context.getViewRoot().createUniqueId();
sortHeader.setId(id);
sortHeader.setColumnName(id);
- sortHeader.setPropertyName(getSortPropertyFromEL(parentColumn));
+ sortHeader.setPropertyName(propertyName);
sortHeader.setArrow(true);
sortHeader.setImmediate(true); //needed to work when dataScroller is present
sortHeader.getChildren().add(initialHeaderFacet);
+ initialHeaderFacet.setParent(sortHeader);
return sortHeader;
}
@@ -709,15 +728,36 @@
*/
protected DataModel createDataModel()
{
- DataModel dataModel = super.createDataModel();
-
- //if this table is sortable, replace the current model with a sortable one
- if (!(dataModel instanceof SortableModel) && isSortable())
- {
- dataModel = new SortableModel(dataModel);
+ DataModel dataModel = super.createDataModel();
+
+ boolean isSortable = isSortable();
+
+ if (!(dataModel instanceof SortableModel))
+ {
+ //if sortable=true make each column sortable
+ //if sortable=false, check to see if at least one column sortable
+ for (Iterator iter = getChildren().iterator(); iter.hasNext();)
+ {
+ UIComponent component = (UIComponent) iter.next();
+ if (component instanceof HtmlSimpleColumn)
+ {
+ HtmlSimpleColumn aColumn = (HtmlSimpleColumn)component;
+ if (isSortable())
+ aColumn.setSortable(true);
+
+ if (aColumn.isSortable())
+ isSortable = true;
+
+ if (aColumn.isDefaultSorted() && getSortColumn() == null)
+ setSortProperty(aColumn.getSortPropertyName());
+ }
+ }
+
+ if (isSortable)
+ dataModel = new SortableModel(dataModel);
}
- if (getSortProperty() != null && isSortable())
+ if (isSortable && getSortProperty() != null)
{
SortCriterion criterion = new SortCriterion(getSortProperty(), isSortAscending());
List criteria = new ArrayList();
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/column/HtmlColumnTag.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/column/HtmlColumnTag.java?rev=397795&r1=397794&r2=397795&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/column/HtmlColumnTag.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/column/HtmlColumnTag.java Fri Apr 28 01:09:56 2006
@@ -65,7 +65,11 @@
private String _width;
private String _groupBy;
+
+ //sort related attributes
private String _defaultSorted;
+ private String _sortable;
+ private String _sortPropertyName;
public String getComponentType()
{
@@ -114,7 +118,10 @@
_width = null;
_groupBy = null;
+
_defaultSorted=null;
+ _sortable=null;
+ _sortPropertyName=null;
}
protected void setProperties(UIComponent component)
@@ -154,7 +161,10 @@
setStringProperty(component, "width", _width);
setBooleanProperty(component,"groupBy",_groupBy);
+
setBooleanProperty(component,"defaultSorted",_defaultSorted);
+ setBooleanProperty(component,"sortable",_sortable);
+ setStringProperty(component,"sortPropertyName",_sortPropertyName);
}
public void setFooterdir(String footerdir)
@@ -320,5 +330,15 @@
public void setDefaultSorted(String defaultSorted)
{
_defaultSorted = defaultSorted;
+ }
+
+ public void setSortable(String sortable)
+ {
+ _sortable = sortable;
+ }
+
+ public void setSortPropertyName(String sortPropertyName)
+ {
+ _sortPropertyName = sortPropertyName;
}
}
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/column/HtmlSimpleColumn.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/column/HtmlSimpleColumn.java?rev=397795&r1=397794&r2=397795&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/column/HtmlSimpleColumn.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/column/HtmlSimpleColumn.java Fri Apr 28 01:09:56 2006
@@ -16,8 +16,10 @@
package org.apache.myfaces.custom.column;
import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
+import org.apache.myfaces.component.html.ext.HtmlDataTable;
/**
* @author Mathias Broekelmann (latest modification by $Author$)
@@ -84,10 +86,13 @@
private String _width;
private Boolean _groupBy;
+
private Boolean _defaultSorted;
+ private Boolean _sortable;
+ private String _sortPropertyName;
+
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlColumn";
- public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlColumn";
-
/**
* @param localValue
* @param valueBindingName
@@ -873,7 +878,7 @@
_groupBy = groupBy ? Boolean.TRUE : Boolean.FALSE;
}
- public boolean isDefaultSorted()
+ public boolean isDefaultSorted()
{
if (_defaultSorted != null) return _defaultSorted.booleanValue();
ValueBinding vb = getValueBinding("defaultSorted");
@@ -885,13 +890,36 @@
{
_defaultSorted = defaultSorted ? Boolean.TRUE : Boolean.FALSE;
}
+
+ public boolean isSortable()
+ {
+ if (_sortable != null) return _sortable.booleanValue();
+ ValueBinding vb = getValueBinding("sortable");
+ Boolean v = vb != null ? (Boolean)vb.getValue(getFacesContext()) : null;
+ return v != null && v.booleanValue();
+ }
+
+ public void setSortable(boolean sortable)
+ {
+ _sortable = sortable ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ public String getSortPropertyName()
+ {
+ return (String) getLocalOrValueBindingValue(_sortPropertyName, "sortPropertyName");
+ }
+
+ public void setSortPropertyName(String sortPropertyName)
+ {
+ _sortPropertyName = sortPropertyName;
+ }
/**
* @see javax.faces.component.UIComponentBase#saveState(javax.faces.context.FacesContext)
*/
public Object saveState(FacesContext context)
{
- Object[] values = new Object[49];
+ Object[] values = new Object[51];
values[0] = super.saveState(context);
values[1] = _headerdir;
@@ -944,7 +972,10 @@
values[46] = _width;
values[47] = _groupBy;
+
values[48] = _defaultSorted;
+ values[49] = _sortable;
+ values[50] = _sortPropertyName;
return values;
}
@@ -1007,6 +1038,9 @@
_width = (String) values[46];
_groupBy = (Boolean) values[47];
+
_defaultSorted = (Boolean) values[48];
+ _sortable = (Boolean) values[49];
+ _sortPropertyName = (String) values[50];
}
}
Modified: myfaces/tomahawk/trunk/core/src/main/tld/tomahawk-entities/tomahawk_column_attributes.xml
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/main/tld/tomahawk-entities/tomahawk_column_attributes.xml?rev=397795&r1=397794&r2=397795&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/tld/tomahawk-entities/tomahawk_column_attributes.xml (original)
+++ myfaces/tomahawk/trunk/core/src/main/tld/tomahawk-entities/tomahawk_column_attributes.xml Fri Apr 28 01:09:56 2006
@@ -63,4 +63,20 @@
sortable=true
</description>
</attribute>
+ <attribute>
+ <name>sortable</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ This attribute makes this column automaticaly sortable by a row object's property
+ </description>
+ </attribute>
+ <attribute>
+ <name>sortPropertyName</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ This attribute tells row object's property by which sorting will be performed on this column
+ </description>
+ </attribute>
Modified: myfaces/tomahawk/trunk/examples/simple/src/main/webapp/home.jsp
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/examples/simple/src/main/webapp/home.jsp?rev=397795&r1=397794&r2=397795&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple/src/main/webapp/home.jsp (original)
+++ myfaces/tomahawk/trunk/examples/simple/src/main/webapp/home.jsp Fri Apr 28 01:09:56 2006
@@ -34,7 +34,8 @@
<h:outputLink value="masterDetail.jsf" ><f:verbatim>Master-Detail</f:verbatim></h:outputLink>
<h:outputLink value="dataScroller.jsf" ><f:verbatim>Data Scroller</f:verbatim></h:outputLink>
<h:outputLink value="sortTable.jsf" ><f:verbatim>Sortable</f:verbatim></h:outputLink>
- <h:outputLink value="sortAutoTable.jsf" ><f:verbatim>Automaticaly sortable</f:verbatim></h:outputLink>
+ <h:outputLink value="sortAutoTable.jsf" ><f:verbatim>Automaticaly sortable by all columns</f:verbatim></h:outputLink>
+ <h:outputLink value="sortAutoTable2.jsf" ><f:verbatim>Automaticaly sortable by choosen columns</f:verbatim></h:outputLink>
<h:outputLink value="pagedSortTable.jsf" ><f:verbatim>Paged and Sortable</f:verbatim></h:outputLink>
<h:outputLink value="openDataTable.jsf" ><f:verbatim>Paged and Sortable (dynamic number of columns; mouseover)</f:verbatim></h:outputLink>
<h:outputLink value="crossDataTable.jsf" ><f:verbatim>Dynamic number of columns, add a column</f:verbatim></h:outputLink>
Added: myfaces/tomahawk/trunk/examples/simple/src/main/webapp/sortAutoTable2.jsp
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/examples/simple/src/main/webapp/sortAutoTable2.jsp?rev=397795&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple/src/main/webapp/sortAutoTable2.jsp (added)
+++ myfaces/tomahawk/trunk/examples/simple/src/main/webapp/sortAutoTable2.jsp Fri Apr 28 01:09:56 2006
@@ -0,0 +1,73 @@
+<%@ page session="false" contentType="text/html;charset=utf-8"%>
+<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
+<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
+<html>
+
+<!--
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//-->
+
+<%@include file="inc/head.inc" %>
+
+<body>
+
+<f:view>
+
+ <f:loadBundle basename="org.apache.myfaces.examples.resource.example_messages" var="example_messages"/>
+
+ <t:dataTable id="data"
+ styleClass="standardTable"
+ headerClass="standardTable_SortHeader"
+ footerClass="standardTable_Footer"
+ rowClasses="standardTable_Row1,standardTable_Row2"
+ var="car"
+ value="#{autosortlist.cars}"
+ sortColumn="#{autosortlist.sortColumn}"
+ sortAscending="#{autosortlist.sortAscending}"
+ preserveDataModel="true"
+ preserveSort="true">
+
+ <t:column sortable="true" defaultSorted="true">
+ <f:facet name="header">
+ <h:outputText value="ID" />
+ </f:facet>
+ <h:outputText value="#{car.id}" />
+ </t:column>
+
+ <t:column>
+ <f:facet name="header">
+ <h:outputText value="#{example_messages['sort_cartype']}" />
+ </f:facet>
+ <h:outputText value="#{car.type}" />
+ </t:column>
+
+ <t:column sortable="true">
+ <f:facet name="header">
+ <h:outputText value="#{example_messages['sort_carcolor']}" />
+ </f:facet>
+ <h:outputText value="#{car.color}" />
+ </t:column>
+
+ </t:dataTable>
+</f:view>
+
+<%@include file="inc/page_footer.jsp" %>
+
+</body>
+
+</html>