Author: lfryc(a)redhat.com
Date: 2010-07-10 15:25:55 -0400 (Sat, 10 Jul 2010)
New Revision: 17844
Added:
root/tests/metamer/trunk/src/main/webapp/components/richDataTable/filtering.xhtml
root/tests/metamer/trunk/src/main/webapp/components/richDataTable/sorting.xhtml
Modified:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/RichDataTableBean.java
root/tests/metamer/trunk/src/main/webapp/components/richDataTable/list.xhtml
root/tests/metamer/trunk/src/main/webapp/templates/header.xhtml
Log:
RFPL-466
* added sorting and filtering features to rich:dataTable
* fixed header (button for rerendering)
Modified:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/RichDataTableBean.java
===================================================================
---
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/RichDataTableBean.java 2010-07-10
19:22:56 UTC (rev 17843)
+++
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/RichDataTableBean.java 2010-07-10
19:25:55 UTC (rev 17844)
@@ -19,7 +19,6 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
*******************************************************************************/
-
package org.richfaces.testapp.bean;
import java.io.Serializable;
@@ -30,11 +29,14 @@
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
+import javax.swing.SortOrder;
import org.ajax4jsf.model.DataComponentState;
import org.richfaces.component.UIDataTable;
import org.richfaces.event.SortingEvent;
+import org.richfaces.model.Filter;
import org.richfaces.testapp.Attributes;
+import org.richfaces.testapp.model.Employee;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,8 +56,18 @@
private DataComponentState dataTableState;
private Map<Object, Integer> stateMap = new HashMap<Object, Integer>();
private int page = 1;
+ // true = model, false = empty table
private boolean state = true;
+ // sorting
+ private SortOrder capitalsOrder = SortOrder.UNSORTED;
+ private SortOrder statesOrder = SortOrder.UNSORTED;
+
+ // filtering
+ private String sexFilter;
+ private String nameFilter;
+ private String titleFilter;
+
/**
* Initializes the managed bean.
*/
@@ -67,7 +79,7 @@
attributes = Attributes.getUIComponentAttributes(UIDataTable.class, getClass());
attributes.put("rendered", true);
attributes.put("rows", 10);
-
+
// TODO these must be tested in other way
attributes.remove("componentState");
attributes.remove("rowKeyVar");
@@ -122,11 +134,82 @@
this.state = state;
}
+ public Date getDate() {
+ return new Date();
+ }
+
+ public SortOrder getCapitalsOrder() {
+ return capitalsOrder;
+ }
+
+ public void setCapitalsOrder(SortOrder capitalsOrder) {
+ this.capitalsOrder = capitalsOrder;
+ }
+
+ public SortOrder getStatesOrder() {
+ return statesOrder;
+ }
+
+ public void setStatesOrder(SortOrder statesOrder) {
+ this.statesOrder = statesOrder;
+ }
+
+ public String getSexFilter() {
+ return sexFilter;
+ }
+
+ public void setSexFilter(String sexFilter) {
+ this.sexFilter = sexFilter;
+ }
+
+ public String getNameFilter() {
+ return nameFilter;
+ }
+
+ public void setNameFilter(String nameFilter) {
+ this.nameFilter = nameFilter;
+ }
+
+ public String getTitleFilter() {
+ return titleFilter;
+ }
+
+ public void setTitleFilter(String titleFilter) {
+ this.titleFilter = titleFilter;
+ }
+
+ public void sortByCapitals() {
+ statesOrder = SortOrder.UNSORTED;
+ if (capitalsOrder.equals(SortOrder.ASCENDING)) {
+ setCapitalsOrder(SortOrder.DESCENDING);
+ } else {
+ setCapitalsOrder(SortOrder.ASCENDING);
+ }
+ }
+
+ public void sortByStates() {
+ capitalsOrder = SortOrder.UNSORTED;
+ if (statesOrder.equals(SortOrder.ASCENDING)) {
+ setStatesOrder(SortOrder.DESCENDING);
+ } else {
+ setStatesOrder(SortOrder.ASCENDING);
+ }
+ }
+
+ public Filter<?> getFilterSexImpl() {
+ return new Filter<Employee>() {
+
+ public boolean accept(Employee e) {
+ String sex = getSexFilter();
+ if (sex == null || sex.length() == 0 ||
sex.equalsIgnoreCase("all") || sex.equalsIgnoreCase(e.getSex().toString())) {
+ return true;
+ }
+ return false;
+ }
+ };
+ }
+
public void sortingListener(SortingEvent event) {
System.out.println(event.getSortOrder());
}
-
- public Date getDate() {
- return new Date();
- }
}
Added: root/tests/metamer/trunk/src/main/webapp/components/richDataTable/filtering.xhtml
===================================================================
--- root/tests/metamer/trunk/src/main/webapp/components/richDataTable/filtering.xhtml
(rev 0)
+++
root/tests/metamer/trunk/src/main/webapp/components/richDataTable/filtering.xhtml 2010-07-10
19:25:55 UTC (rev 17844)
@@ -0,0 +1,178 @@
+<!--
+JBoss, Home of Professional Open Source
+Copyright 2010, Red Hat, Inc. and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+This software is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+-->
+
+<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:ta="http://java.sun.com/jsf/composite/testapp"
xmlns:rich="http://richfaces.org/rich"
+
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="head">
+ <f:metadata>
+ <f:viewParam name="templates"
value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ <h:outputStylesheet library="css"
name="richDataTable.css"/>
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ <br/>
+ <h:outputText value="Show data in table: " />
+ <h:selectBooleanCheckbox value="#{richDataTableBean.state}">
+ <a4j:ajax render="richDataTable scroller1"/>
+ </h:selectBooleanCheckbox>
+ <br/><br/>
+ <rich:dataScroller id="scroller1" for="richDataTable"
page="#{richDataTableBean.page}" maxPages="7"
render="richDataTable"/>
+ </ui:define>
+
+ <ui:define name="component">
+ <rich:dataTable id="richDataTable"
+
filterVar="#{richDataTableBean.attributes['filterVar']}"
+
filteringListeners="#{richDataTableBean.attributes['filteringListeners']}"
+
first="#{richDataTableBean.attributes['first']}"
+
iterationState="#{richDataTableBean.attributes['iterationState']}"
+
iterationStatusVar="#{richDataTableBean.attributes['iterationStatusVar']}"
+
keepSaved="#{richDataTableBean.attributes['keepSaved']}"
+
noDataLabel="#{richDataTableBean.attributes['noDataLabel']}"
+
relativeRowIndex="#{richDataTableBean.attributes['relativeRowIndex']}"
+
rendered="#{richDataTableBean.attributes['rendered']}"
+
rowAvailable="#{richDataTableBean.attributes['rowAvailable']}"
+
rowCount="#{richDataTableBean.attributes['rowCount']}"
+
rowData="#{richDataTableBean.attributes['rowData']}"
+
rowIndex="#{richDataTableBean.attributes['rowIndex']}"
+
rowKey="#{richDataTableBean.attributes['rowKey']}"
+
rowKeyConverter="#{richDataTableBean.attributes['rowKeyConverter']}"
+
rows="#{richDataTableBean.attributes['rows']}"
+
sortMode="#{richDataTableBean.attributes['sortMode']}"
+
sortPriority="#{richDataTableBean.attributes['sortPriority']}"
+
sortingListeners="#{richDataTableBean.attributes['sortingListeners']}"
+ value="#{richDataTableBean.state ? model.employees :
null}"
+ var="record"
+ >
+
+ <f:facet name="noData">
+ <h:outputText value="There is no data."
style="color: red;"/>
+ </f:facet>
+
+ <rich:column id="columnSex"
filter="#{richDataTableBean.filterSexImpl}">
+ <f:facet name="header">
+ <h:panelGroup>
+ <h:outputText id="columnHeaderSex"
value="Sex" />
+ <br/>
+ <h:outputText id="columnHeaderSexType"
value="(filter)" />
+ <br/>
+ <h:selectOneMenu id="columnHeaderSexInput"
value="#{richDataTableBean.sexFilter}" >
+ <f:selectItem itemValue="ALL"
itemLabel="all"/>
+ <f:selectItem itemValue="FEMALE"
itemLabel="female"/>
+ <f:selectItem itemValue="MALE"
itemLabel="male"/>
+ <a4j:ajax id="columnHeaderSexAjax"
render="commonGrid" execute="@this" event="change"/>
+ </h:selectOneMenu>
+ </h:panelGroup>
+ </f:facet>
+
+ <h:graphicImage library="images" name="#{record.sex
== 'MALE' ? 'male.png' : 'female.png'}" />
+
+ <f:facet name="footer">
+ <h:outputText id="columnFooterSex"
value="Sex" />
+ </f:facet>
+ </rich:column>
+
+
+ <rich:column id="columnName"
filterValue="#{richDataTableBean.nameFilter}"
filterExpression="#{fn:containsIgnoreCase(record.name,
richDataTableBean.nameFilter)}">
+ <f:facet name="header">
+ <h:outputText id="columnHeaderName"
value="Name" />
+ <br/>
+ <h:outputText id="columnHeaderNameType"
value="(expression contains ignore case)" />
+ <br/>
+ <h:inputText id="columnHeaderNameInput"
value="#{richDataTableBean.nameFilter}">
+ <a4j:ajax id="columnHeaderNameAjax"
render="commonGrid" execute="@this" event="change"/>
+ </h:inputText>
+ </f:facet>
+
+ <h:outputText value="#{record.name}" />
+ <f:facet name="footer">
+ <h:outputText id="columnFooterState"
value="Name" />
+ </f:facet>
+ </rich:column>
+
+ <rich:column id="columnTitle"
filterValue="#{richDataTableBean.titleFilter}"
filterExpression="#{richDataTableBean.titleFilter == null ||
richDataTableBean.titleFilter == '' || record.title ==
richDataTableBean.titleFilter}">
+ <f:facet name="header">
+ <h:outputText id="columnHeaderTitle"
value="Title" />
+ <br/>
+ <h:outputText id="columnHeaderTitleType"
value="(expression equals)" />
+ <br/>
+ <h:inputText id="columnHeaderTitleInput"
value="#{richDataTableBean.titleFilter}">
+ <a4j:ajax id="columnHeaderTitleAjax"
render="commonGrid" execute="@this" event="change"/>
+ </h:inputText>
+ </f:facet>
+
+ <h:outputText value="#{record.title}" />
+ <f:facet name="footer">
+ <h:outputText id="columnFooterTitle"
value="Title" />
+ </f:facet>
+ </rich:column>
+
+ <rich:column id="columnNumberOfKids">
+ <f:facet name="header">
+ <h:outputText id="columnHeaderNumberOfKids"
value="Number of Kids" />
+ <br/>
+ <h:outputText id="columnHeaderNumberOfKidsType"
value="(expression >=)" />
+ <br/>
+ <h:inputText id="columnHeaderNumberOfKidsInput"
value="TODO inputNumberSpinner"/>
+ </f:facet>
+
+ <h:outputText value="#{record.numberOfKids}" />
+ <f:facet name="footer">
+ <h:outputText id="columnFooterNumberOfKids"
value="Number of Kids" />
+ </f:facet>
+ </rich:column>
+
+ <rich:column id="columnNumberOfKids2">
+ <f:facet name="header">
+ <h:outputText id="columnHeaderNumberOfKids2"
value="Number of Kids" />
+ <br/>
+ <h:outputText id="columnHeaderNumberOfKids2Type"
value="(expression <)" />
+ <br/>
+ <h:inputText id="columnHeaderNumberOfKids2Input"
value="TODO inputNumberSlider"/>
+ </f:facet>
+
+ <h:outputText value="#{record.numberOfKids}" />
+ <f:facet name="footer">
+ <h:outputText id="columnFooterNumberOfKids2"
value="Number of Kids" />
+ </f:facet>
+ </rich:column>
+
+ <f:facet name="footer">
+ <rich:dataScroller id="scroller2"
for="richDataTable" page="#{richDataTableBean.page}"
maxPages="7" render="richDataTable" />
+ </f:facet>
+ </rich:dataTable>
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <ta:attributes value="#{richDataTableBean.attributes}"
id="attributes" />
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Modified: root/tests/metamer/trunk/src/main/webapp/components/richDataTable/list.xhtml
===================================================================
---
root/tests/metamer/trunk/src/main/webapp/components/richDataTable/list.xhtml 2010-07-10
19:22:56 UTC (rev 17843)
+++
root/tests/metamer/trunk/src/main/webapp/components/richDataTable/list.xhtml 2010-07-10
19:25:55 UTC (rev 17844)
@@ -46,5 +46,10 @@
<div class="description">Page that contains
<b>rich:dataTable</b> (with model containing employees) and input boxes for
all its attributes.
<span style="color: red">TODO will be used with various types
of input and command components as soon as available</span></div>
+ <h:link outcome="sorting" value="Table Sorting"
styleClass="link"/>
+ <div class="description">Page that contains sortable
<b>rich:dataTable</b> (with model containing capitals) and input boxes for all
its attributes.</div>
+
+ <h:link outcome="filtering" value="Table filtering"
styleClass="link"/>
+ <div class="description">Page that contains filterable
<b>rich:dataTable</b> (with model containing capitals) and input boxes for all
its attributes.</div>
</h:body>
</html>
\ No newline at end of file
Added: root/tests/metamer/trunk/src/main/webapp/components/richDataTable/sorting.xhtml
===================================================================
--- root/tests/metamer/trunk/src/main/webapp/components/richDataTable/sorting.xhtml
(rev 0)
+++
root/tests/metamer/trunk/src/main/webapp/components/richDataTable/sorting.xhtml 2010-07-10
19:25:55 UTC (rev 17844)
@@ -0,0 +1,125 @@
+<!--
+JBoss, Home of Professional Open Source
+Copyright 2010, Red Hat, Inc. and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+This software is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+-->
+
+<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:ta="http://java.sun.com/jsf/composite/testapp"
xmlns:rich="http://richfaces.org/rich">
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="head">
+ <f:metadata>
+ <f:viewParam name="templates"
value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ <h:outputStylesheet library="css"
name="richDataTable.css"/>
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ <br/>
+ <h:outputText value="Show data in table: " />
+ <h:selectBooleanCheckbox value="#{richDataTableBean.state}">
+ <a4j:ajax render="richDataTable scroller1"/>
+ </h:selectBooleanCheckbox>
+ <br/><br/>
+ <rich:dataScroller id="scroller1" for="richDataTable"
page="#{richDataTableBean.page}" maxPages="7"
render="richDataTable"/>
+ </ui:define>
+
+ <ui:define name="component">
+
+ <rich:dataTable id="richDataTable"
+
filterVar="#{richDataTableBean.attributes['filterVar']}"
+
filteringListeners="#{richDataTableBean.attributes['filteringListeners']}"
+
first="#{richDataTableBean.attributes['first']}"
+
iterationState="#{richDataTableBean.attributes['iterationState']}"
+
iterationStatusVar="#{richDataTableBean.attributes['iterationStatusVar']}"
+
keepSaved="#{richDataTableBean.attributes['keepSaved']}"
+
noDataLabel="#{richDataTableBean.attributes['noDataLabel']}"
+
relativeRowIndex="#{richDataTableBean.attributes['relativeRowIndex']}"
+
rendered="#{richDataTableBean.attributes['rendered']}"
+
rowAvailable="#{richDataTableBean.attributes['rowAvailable']}"
+
rowCount="#{richDataTableBean.attributes['rowCount']}"
+
rowData="#{richDataTableBean.attributes['rowData']}"
+
rowIndex="#{richDataTableBean.attributes['rowIndex']}"
+
rowKey="#{richDataTableBean.attributes['rowKey']}"
+
rowKeyConverter="#{richDataTableBean.attributes['rowKeyConverter']}"
+
rows="#{richDataTableBean.attributes['rows']}"
+
sortMode="#{richDataTableBean.attributes['sortMode']}"
+
sortPriority="#{richDataTableBean.attributes['sortPriority']}"
+
sortingListeners="#{richDataTableBean.attributes['sortingListeners']}"
+ value="#{richDataTableBean.state ? model.capitals :
null}"
+ var="record"
+ >
+
+ <f:facet name="noData">
+ <h:outputText value="There is no data."
style="color: red;"/>
+ </f:facet>
+
+ <rich:column id="columnState"
sortBy="#{record.state}"
sortOrder="#{richDataTableBean.statesOrder}">
+ <f:facet name="header">
+ <a4j:commandLink id="columnHeaderState"
value="State" render="richDataTable"
action="#{richDataTableBean.sortByStates}"/>
+ </f:facet>
+
+ <h:outputText value="#{record.state}" />
+ <f:facet name="footer">
+ <h:outputText id="columnFooterState"
value="State" />
+ </f:facet>
+ </rich:column>
+
+ <rich:column id="columnCapital"
sortBy="#{record.name}" sortOrder="#{richDataTableBean.capitalsOrder}"
sortingListeners="#{richDataTableBean.sortingListener}">
+ <f:facet name="header">
+ <a4j:commandLink id="columnHeaderCapital"
value="Capital" render="richDataTable"
action="#{richDataTableBean.sortByCapitals}"/>
+ </f:facet>
+
+ <h:outputText value="#{record.name}" />
+ <f:facet name="footer">
+ <h:outputText id="columnFooterCapital"
value="Capital" />
+ </f:facet>
+ </rich:column>
+
+ <f:facet name="footer">
+ <rich:dataScroller id="scroller2"
for="richDataTable" page="#{richDataTableBean.page}"
maxPages="7" render="richDataTable" />
+ </f:facet>
+
+ </rich:dataTable>
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <h:commandButton value="sort state">
+ <rich:componentControl event="click"
target="richDataTable" operation="sort"/>
+ </h:commandButton>
+
+ <h:commandButton value="sort capital">
+ <rich:componentControl event="click"
target="richDataTable" operation="sort">
+ <f:param value="columnCapital" />
+ </rich:componentControl>
+ </h:commandButton>
+
+ <br/><br/>
+
+ <ta:attributes value="#{richDataTableBean.attributes}"
id="attributes" />
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Modified: root/tests/metamer/trunk/src/main/webapp/templates/header.xhtml
===================================================================
--- root/tests/metamer/trunk/src/main/webapp/templates/header.xhtml 2010-07-10 19:22:56
UTC (rev 17843)
+++ root/tests/metamer/trunk/src/main/webapp/templates/header.xhtml 2010-07-10 19:25:55
UTC (rev 17844)
@@ -8,7 +8,7 @@
<h:link outcome="/index"><h:graphicImage
library="images" name="home.png" title="Go Home"
style="width: 36px;"/></h:link>
<h:link outcome="list"><h:graphicImage
library="images" name="back.png" title="Go to List of Pages"
style="width: 36px;"/></h:link>
<h:graphicImage library="images" name="refresh.png"
title="Rerender All" style="width: 36px;">
- <a4j:ajax event="click" render="commondGrid"/>
+ <a4j:ajax event="click" render="commonGrid"/>
</h:graphicImage>
</h:panelGrid>