Author: lfryc(a)redhat.com
Date: 2010-07-10 15:26:34 -0400 (Sat, 10 Jul 2010)
New Revision: 17845
Added:
root/tests/metamer/trunk/src/main/webapp/components/richExtendedDataTable/filtering.xhtml
root/tests/metamer/trunk/src/main/webapp/components/richExtendedDataTable/sorting.xhtml
Modified:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/RichExtendedDataTableBean.java
root/tests/metamer/trunk/src/main/webapp/components/richExtendedDataTable/list.xhtml
Log:
RFPL-466
* added sorting and filtering to extended data table
Modified:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/RichExtendedDataTableBean.java
===================================================================
---
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/RichExtendedDataTableBean.java 2010-07-10
19:25:55 UTC (rev 17844)
+++
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/RichExtendedDataTableBean.java 2010-07-10
19:26:34 UTC (rev 17845)
@@ -29,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.UIExtendedDataTable;
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;
@@ -53,7 +56,17 @@
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.
@@ -140,6 +153,77 @@
this.state = state;
}
+ 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());
}
Added:
root/tests/metamer/trunk/src/main/webapp/components/richExtendedDataTable/filtering.xhtml
===================================================================
---
root/tests/metamer/trunk/src/main/webapp/components/richExtendedDataTable/filtering.xhtml
(rev 0)
+++
root/tests/metamer/trunk/src/main/webapp/components/richExtendedDataTable/filtering.xhtml 2010-07-10
19:26:34 UTC (rev 17845)
@@ -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="#{richExtendedDataTableBean.state}">
+ <a4j:ajax render="richDataTable scroller1"/>
+ </h:selectBooleanCheckbox>
+ <br/><br/>
+ <rich:dataScroller id="scroller1" for="richDataTable"
page="#{richExtendedDataTableBean.page}" maxPages="7"
render="richDataTable"/>
+ </ui:define>
+
+ <ui:define name="component">
+ <rich:extendedDataTable id="richDataTable"
+
filterVar="#{richExtendedDataTableBean.attributes['filterVar']}"
+
filteringListeners="#{richExtendedDataTableBean.attributes['filteringListeners']}"
+
first="#{richExtendedDataTableBean.attributes['first']}"
+
iterationState="#{richExtendedDataTableBean.attributes['iterationState']}"
+
iterationStatusVar="#{richExtendedDataTableBean.attributes['iterationStatusVar']}"
+
keepSaved="#{richExtendedDataTableBean.attributes['keepSaved']}"
+
noDataLabel="#{richExtendedDataTableBean.attributes['noDataLabel']}"
+
relativeRowIndex="#{richExtendedDataTableBean.attributes['relativeRowIndex']}"
+
rendered="#{richExtendedDataTableBean.attributes['rendered']}"
+
rowAvailable="#{richExtendedDataTableBean.attributes['rowAvailable']}"
+
rowCount="#{richExtendedDataTableBean.attributes['rowCount']}"
+
rowData="#{richExtendedDataTableBean.attributes['rowData']}"
+
rowIndex="#{richExtendedDataTableBean.attributes['rowIndex']}"
+
rowKey="#{richExtendedDataTableBean.attributes['rowKey']}"
+
rowKeyConverter="#{richExtendedDataTableBean.attributes['rowKeyConverter']}"
+
rows="#{richExtendedDataTableBean.attributes['rows']}"
+
sortMode="#{richExtendedDataTableBean.attributes['sortMode']}"
+
sortPriority="#{richExtendedDataTableBean.attributes['sortPriority']}"
+
sortingListeners="#{richExtendedDataTableBean.attributes['sortingListeners']}"
+ value="#{richExtendedDataTableBean.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="#{richExtendedDataTableBean.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="#{richExtendedDataTableBean.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="#{richExtendedDataTableBean.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="#{richExtendedDataTableBean.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="#{richExtendedDataTableBean.titleFilter}"
filterExpression="#{richExtendedDataTableBean.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="#{richExtendedDataTableBean.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="#{richExtendedDataTableBean.page}"
maxPages="7" render="richDataTable" />
+ </f:facet>
+ </rich:extendedDataTable>
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <ta:attributes value="#{richExtendedDataTableBean.attributes}"
id="attributes" />
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Modified:
root/tests/metamer/trunk/src/main/webapp/components/richExtendedDataTable/list.xhtml
===================================================================
---
root/tests/metamer/trunk/src/main/webapp/components/richExtendedDataTable/list.xhtml 2010-07-10
19:25:55 UTC (rev 17844)
+++
root/tests/metamer/trunk/src/main/webapp/components/richExtendedDataTable/list.xhtml 2010-07-10
19:26:34 UTC (rev 17845)
@@ -46,5 +46,10 @@
<div class="description">Page that contains
<b>rich:extendedDataTable</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:extendedDataTable</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:extendedDataTable</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/richExtendedDataTable/sorting.xhtml
===================================================================
---
root/tests/metamer/trunk/src/main/webapp/components/richExtendedDataTable/sorting.xhtml
(rev 0)
+++
root/tests/metamer/trunk/src/main/webapp/components/richExtendedDataTable/sorting.xhtml 2010-07-10
19:26:34 UTC (rev 17845)
@@ -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="#{richExtendedDataTableBean.state}">
+ <a4j:ajax render="richDataTable scroller1"/>
+ </h:selectBooleanCheckbox>
+ <br/><br/>
+ <rich:dataScroller id="scroller1" for="table"
page="#{richExtendedDataTableBean.page}" maxPages="7"
render="table"/>
+ </ui:define>
+
+ <ui:define name="component">
+
+ <rich:extendedDataTable id="table"
+
filterVar="#{richExtendedDataTableBean.attributes['filterVar']}"
+
filteringListeners="#{richExtendedDataTableBean.attributes['filteringListeners']}"
+
first="#{richExtendedDataTableBean.attributes['first']}"
+
iterationState="#{richExtendedDataTableBean.attributes['iterationState']}"
+
iterationStatusVar="#{richExtendedDataTableBean.attributes['iterationStatusVar']}"
+
keepSaved="#{richExtendedDataTableBean.attributes['keepSaved']}"
+
noDataLabel="#{richExtendedDataTableBean.attributes['noDataLabel']}"
+
relativeRowIndex="#{richExtendedDataTableBean.attributes['relativeRowIndex']}"
+
rendered="#{richExtendedDataTableBean.attributes['rendered']}"
+
rowAvailable="#{richExtendedDataTableBean.attributes['rowAvailable']}"
+
rowCount="#{richExtendedDataTableBean.attributes['rowCount']}"
+
rowData="#{richExtendedDataTableBean.attributes['rowData']}"
+
rowIndex="#{richExtendedDataTableBean.attributes['rowIndex']}"
+
rowKey="#{richExtendedDataTableBean.attributes['rowKey']}"
+
rowKeyConverter="#{richExtendedDataTableBean.attributes['rowKeyConverter']}"
+
rows="#{richExtendedDataTableBean.attributes['rows']}"
+
sortMode="#{richExtendedDataTableBean.attributes['sortMode']}"
+
sortPriority="#{richExtendedDataTableBean.attributes['sortPriority']}"
+
sortingListeners="#{richExtendedDataTableBean.attributes['sortingListeners']}"
+ value="#{richExtendedDataTableBean.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="#{richExtendedDataTableBean.statesOrder}">
+ <f:facet name="header">
+ <a4j:commandLink id="columnHeaderState"
value="State" render="table"
action="#{richExtendedDataTableBean.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="#{richExtendedDataTableBean.capitalsOrder}"
sortingListeners="#{richExtendedDataTableBean.sortingListener}">
+ <f:facet name="header">
+ <a4j:commandLink id="columnHeaderCapital"
value="Capital" render="table"
action="#{richExtendedDataTableBean.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="table"
page="#{richExtendedDataTableBean.page}" maxPages="7"
render="table" />
+ </f:facet>
+
+ </rich:extendedDataTable>
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <h:commandButton value="sort state">
+ <rich:componentControl event="click"
target="table" operation="sort"/>
+ </h:commandButton>
+
+ <h:commandButton value="sort capital">
+ <rich:componentControl event="click"
target="table" operation="sort">
+ <f:param value="columnCapital" />
+ </rich:componentControl>
+ </h:commandButton>
+
+ <br/><br/>
+
+ <ta:attributes value="#{richExtendedDataTableBean.attributes}"
id="attributes" />
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file