Author: ilya_shaikovsky
Date: 2008-03-18 12:25:42 -0400 (Tue, 18 Mar 2008)
New Revision: 6919
Added:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/datatablescroller/SortOption.java
trunk/samples/richfaces-demo/src/main/java/org/richfaces/datatablescroller/SortingBean.java
Modified:
trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/sortingFilteringFeatures/examples/externalMultipleSorting.xhtml
Log:
Added:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/datatablescroller/SortOption.java
===================================================================
---
trunk/samples/richfaces-demo/src/main/java/org/richfaces/datatablescroller/SortOption.java
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/java/org/richfaces/datatablescroller/SortOption.java 2008-03-18
16:25:42 UTC (rev 6919)
@@ -0,0 +1,38 @@
+/**
+ *
+ */
+package org.richfaces.datatablescroller;
+
+import org.richfaces.model.Ordering;
+
+/**
+ * @author Ilya Shaikovsky
+ *
+ */
+public class SortOption {
+ private int item;
+ private Ordering direction;
+
+ public SortOption(Integer item) {
+ setItem(item);
+ setDirection(Ordering.UNSORTED);
+ }
+
+ public Ordering getDirection() {
+ return direction;
+ }
+ public void setDirection(Ordering direction) {
+ this.direction = direction;
+ }
+
+
+ public int getItem() {
+ return item;
+ }
+
+
+ public void setItem(int item) {
+ this.item = item;
+ }
+
+}
Copied:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/datatablescroller/SortingBean.java
(from rev 6889,
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/dataTableScroller/SortingBean.java)
===================================================================
---
trunk/samples/richfaces-demo/src/main/java/org/richfaces/datatablescroller/SortingBean.java
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/java/org/richfaces/datatablescroller/SortingBean.java 2008-03-18
16:25:42 UTC (rev 6919)
@@ -0,0 +1,198 @@
+/**
+ *
+ */
+package org.richfaces.datatablescroller;
+
+import java.util.ArrayList;
+
+import javax.faces.event.ValueChangeEvent;
+import javax.faces.model.SelectItem;
+
+import org.richfaces.model.Ordering;
+
+/**
+ * @author Ilya Shaikovsky
+ *
+ */
+public class SortingBean {
+
+ //Settings panel data bindings
+ ArrayList<SelectItem> firstSortItems = new ArrayList<SelectItem>();
+ ArrayList<SelectItem> secondSortItems = new ArrayList<SelectItem>();
+ ArrayList<SelectItem> thirdSortItems = new ArrayList<SelectItem>();
+ SelectItem[] sortDirectionItems = new SelectItem[3];
+ private SortOption firstSortOption= new SortOption(0);
+ private SortOption secondSortOption = new SortOption(0);
+ private SortOption thirdSortOption = new SortOption(0);
+
+ //Table Sort directions Binding
+ ArrayList<String> prioritList = new ArrayList<String>();
+
+ private String makeDirection = Ordering.UNSORTED.name();
+ private String modelDirection = Ordering.UNSORTED.name();
+ private String priceDirection = Ordering.UNSORTED.name();
+ private String mileageDirection = Ordering.UNSORTED.name();
+
+ public SortingBean() {
+ firstSortItems.add(new SelectItem(0,"None"));
+ firstSortItems.add(new SelectItem(1,"Model"));
+ firstSortItems.add(new SelectItem(2,"Price"));
+ firstSortItems.add(new SelectItem(3,"Make"));
+ firstSortItems.add(new SelectItem(4,"Mileage"));
+
+ sortDirectionItems[0] = new SelectItem(Ordering.UNSORTED, "Unsorted");
+ sortDirectionItems[1] = new SelectItem(Ordering.ASCENDING, "Ascending");
+ sortDirectionItems[2] = new SelectItem(Ordering.DESCENDING, "Descending");
+ }
+
+ public void firstSortOptionValueChanged(ValueChangeEvent valueChangeEvent) {
+ if (!(valueChangeEvent.getNewValue().equals(new Integer(0)))){
+ secondSortItems.clear();
+ thirdSortItems.clear();
+ for (SelectItem item : firstSortItems) {
+ if (!(item.getValue().equals(valueChangeEvent.getNewValue()))){
+ secondSortItems.add(item);
+ }
+ }
+ }
+ firstSortOption.setDirection(Ordering.UNSORTED);
+ secondSortOption.setItem(0);
+ secondSortOption.setDirection(Ordering.UNSORTED);
+ thirdSortOption.setItem(0);
+ thirdSortOption.setDirection(Ordering.UNSORTED);
+ }
+
+ public void secondSortOptionValueChanged(ValueChangeEvent valueChangeEvent) {
+ if (!(valueChangeEvent.getNewValue().equals(new Integer(0)))){
+ thirdSortItems.clear();
+ for (SelectItem item : secondSortItems) {
+ if (!(item.getValue().equals(valueChangeEvent.getNewValue()))){
+ thirdSortItems.add(item);
+ }
+ }
+ }
+ secondSortOption.setDirection(Ordering.UNSORTED);
+ thirdSortOption.setItem(0);
+ thirdSortOption.setDirection(Ordering.UNSORTED);
+ }
+
+ public void thirdSortOptionValueChanged(ValueChangeEvent valueChangeEvent) {
+ thirdSortOption.setDirection(Ordering.UNSORTED);
+ }
+
+ public void checkSort(SortOption value){
+ switch (value.getItem()) {
+ case 1:
+ prioritList.add("model");
+ setModelDirection(value.getDirection().name());
+ break;
+ case 2:
+ prioritList.add("price");
+ setPriceDirection(value.getDirection().name());
+ break;
+ case 3:
+ prioritList.add("make");
+ setMakeDirection(value.getDirection().name());
+ break;
+ case 4:
+ prioritList.add("mileage");
+ setMileageDirection(value.getDirection().name());
+ break;
+ }
+ }
+
+ public String sortTable() {
+ prioritList.clear();
+ setModelDirection(Ordering.UNSORTED.name());
+ setMakeDirection(Ordering.UNSORTED.name());
+ setPriceDirection(Ordering.UNSORTED.name());
+ setMileageDirection(Ordering.UNSORTED.name());
+ if (firstSortOption.getItem()!=0){
+ checkSort(firstSortOption);
+ if (secondSortOption.getItem()!=0){
+ checkSort(secondSortOption);
+ if (thirdSortOption.getItem()!=0) {
+ checkSort(thirdSortOption);
+ }
+ }
+ }
+ return null;
+ }
+
+ public SelectItem[] getSortDirectionItems() {
+ return sortDirectionItems;
+ }
+
+ public ArrayList<String> getPrioritList() {
+ return prioritList;
+ }
+
+ public SortOption getFirstSortOption() {
+ return firstSortOption;
+ }
+
+ public void setFirstSortOption(SortOption firstSortOption) {
+ this.firstSortOption = firstSortOption;
+ }
+
+ public SortOption getSecondSortOption() {
+ return secondSortOption;
+ }
+
+ public void setSecondSortOption(SortOption secondSortOption) {
+ this.secondSortOption = secondSortOption;
+ }
+
+ public SortOption getThirdSortOption() {
+ return thirdSortOption;
+ }
+
+ public void setThirdSortOption(SortOption thirdSortOption) {
+ this.thirdSortOption = thirdSortOption;
+ }
+
+ public ArrayList<SelectItem> getFirstSortItems() {
+ return firstSortItems;
+ }
+
+ public ArrayList<SelectItem> getSecondSortItems() {
+ return secondSortItems;
+ }
+
+ public ArrayList<SelectItem> getThirdSortItems() {
+ return thirdSortItems;
+ }
+
+ public String getMakeDirection() {
+ return makeDirection;
+ }
+
+ public void setMakeDirection(String makeDirection) {
+ this.makeDirection = makeDirection;
+ }
+
+ public String getModelDirection() {
+ return modelDirection;
+ }
+
+ public void setModelDirection(String modelDirection) {
+ this.modelDirection = modelDirection;
+ }
+
+ public String getPriceDirection() {
+ return priceDirection;
+ }
+
+ public void setPriceDirection(String priceDirection) {
+ this.priceDirection = priceDirection;
+ }
+
+ public String getMileageDirection() {
+ return mileageDirection;
+ }
+
+ public void setMileageDirection(String mileageDirection) {
+ this.mileageDirection = mileageDirection;
+ }
+
+}
Modified: trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml 2008-03-18
16:25:12 UTC (rev 6918)
+++ trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml 2008-03-18
16:25:42 UTC (rev 6919)
@@ -300,8 +300,8 @@
</managed-bean>
<managed-bean>
<managed-bean-name>sortingBean</managed-bean-name>
-
<managed-bean-class>org.richfaces.demo.dataTableScroller.SortingBean</managed-bean-class>
- <managed-bean-scope>request</managed-bean-scope>
+
<managed-bean-class>org.richfaces.datatablescroller.SortingBean</managed-bean-class>
+ <managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/richfaces/include/examples/wstep1.xhtml</from-view-id>
Modified:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/sortingFilteringFeatures/examples/externalMultipleSorting.xhtml
===================================================================
---
trunk/samples/richfaces-demo/src/main/webapp/richfaces/sortingFilteringFeatures/examples/externalMultipleSorting.xhtml 2008-03-18
16:25:12 UTC (rev 6918)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/sortingFilteringFeatures/examples/externalMultipleSorting.xhtml 2008-03-18
16:25:42 UTC (rev 6919)
@@ -1,67 +1,133 @@
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
-
xmlns:ui="http://java.sun.com/jsf/facelets"
-
xmlns:h="http://java.sun.com/jsf/html"
-
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:a4j="http://richfaces.org/a4j"
-
xmlns:rich="http://richfaces.org/rich">
- <style>
- .top{
- vertical-align:top;
- }
- </style>
-
- <h:panelGrid columns="2" columnClasses="top">
- <rich:dataTable value="#{dataTableScrollerBean.allCars}"
var="category" rows="30" id="table">
- <rich:column id="make" sortBy="#{category.make}"
sortOrder="#{sortingBean.makeDirection}">
- <f:facet name="header"><h:outputText
styleClass="headerText" value="Make" /></f:facet>
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich">
+ <style>
+.top {
+ vertical-align: top;
+}
+
+.equals {
+ width: 33%;
+}
+</style>
+
+ <h:panelGrid columns="2" columnClasses="top">
+ <h:form>
+ <rich:dataTable value="#{dataTableScrollerBean.allCars}"
+ var="category" rows="30" id="table"
+ sortPriorities="#{sortingBean.prioritList}">
+ <rich:column id="make" sortBy="#{category.make}"
+ sortOrder="#{sortingBean.makeDirection}" selfSorted="false">
+ <f:facet name="header">
+ <h:outputText styleClass="headerText" value="Make" />
+ </f:facet>
<h:outputText value="#{category.make}" />
</rich:column>
- <rich:column id="model" sortBy="#{category.model}"
sortOrder="#{sortingBean.modelDirection}">
- <f:facet name="header"><h:outputText
styleClass="headerText" value="Model" /></f:facet>
+ <rich:column id="model" sortBy="#{category.model}"
+ sortOrder="#{sortingBean.modelDirection}"
selfSorted="false">
+ <f:facet name="header">
+ <h:outputText styleClass="headerText" value="Model" />
+ </f:facet>
<h:outputText value="#{category.model}" />
</rich:column>
- <rich:column id="price" sortBy="#{category.price}"
sortOrder="#{sortingBean.priceDirection}">
- <f:facet name="header"><h:outputText
styleClass="headerText" value="Price" /></f:facet>
+ <rich:column id="price" sortBy="#{category.price}"
+ sortOrder="#{sortingBean.priceDirection}"
selfSorted="false">
+ <f:facet name="header">
+ <h:outputText styleClass="headerText" value="Price" />
+ </f:facet>
<h:outputText value="#{category.price}" />
</rich:column>
- <rich:column id="mileage" sortBy="#{category.mileage}"
sortOrder="#{sortingBean.mileageDirection}">
- <f:facet name="header"><h:outputText
styleClass="headerText" value="Mileage" /></f:facet>
+ <rich:column id="mileage" sortBy="#{category.mileage}"
+ sortOrder="#{sortingBean.mileageDirection}"
selfSorted="false">
+ <f:facet name="header">
+ <h:outputText styleClass="headerText" value="Mileage" />
+ </f:facet>
<h:outputText value="#{category.mileage}" />
</rich:column>
<rich:column width="200px" id="vin">
- <f:facet name="header"><h:outputText
styleClass="headerText" value="VIN" /></f:facet>
+ <f:facet name="header">
+ <h:outputText styleClass="headerText" value="VIN" />
+ </f:facet>
<h:outputText value="#{category.vin}" />
</rich:column>
<rich:column id="stock">
- <f:facet name="header"><h:outputText
styleClass="headerText" value="Stock" /></f:facet>
+ <f:facet name="header">
+ <h:outputText styleClass="headerText" value="Stock" />
+ </f:facet>
<h:outputText value="#{category.stock}" />
</rich:column>
+ <f:facet name="footer">
+ <rich:datascroller />
+ </f:facet>
</rich:dataTable>
- <h:form>
- <rich:panel>
- <f:facet name="header">
- <h:outputText value="Specify Sorting Conditions:"/>
- </f:facet>
- <h:panelGrid columns="2">
- <h:outputText value="First Sort Property"/>
- <h:selectOneMenu value="#{sortingBean.firstSortOption}">
- <f:selectItems value="#{sortingBean.sortByItems}"/>
- </h:selectOneMenu>
- <h:outputText value="Second Sort Property"/>
- <h:selectOneMenu value="#{sortingBean.secondSortOption}">
- <f:selectItems value="#{sortingBean.sortByItems}"/>
- </h:selectOneMenu>
- <h:outputText value="Third Sort Property"/>
- <h:selectOneMenu value="#{sortingBean.thirdSortOption}">
- <f:selectItems value="#{sortingBean.sortByItems}"/>
- </h:selectOneMenu>
- <h:outputText value="Fourth Sort Property"/>
- <h:selectOneMenu value="#{sortingBean.fourthSortOption}">
- <f:selectItems value="#{sortingBean.sortByItems}"/>
- </h:selectOneMenu>
+ </h:form>
+ <h:form>
+ <rich:panel id="sortPanel">
+ <f:facet name="header">
+ <h:outputText value="Specify Sorting Conditions:" />
+ </f:facet>
+ <h:panelGrid columns="1">
+ <a4j:outputPanel>
+ <h:panelGrid columns="3" width="300px"
+ columnClasses="equals,equals,equals">
+ <h:outputText value="First sort by:" />
+ <h:selectOneMenu value="#{sortingBean.firstSortOption.item}"
+ valueChangeListener="#{sortingBean.firstSortOptionValueChanged}">
+ <a4j:support event="onchange" reRender="sortPanel"
+ ajaxSingle="true" />
+ <f:selectItems value="#{sortingBean.firstSortItems}" />
+ </h:selectOneMenu>
+ <h:selectOneMenu
value="#{sortingBean.firstSortOption.direction}">
+ <a4j:support event="onchange" reRender="sortPanel" />
+ <f:selectItems value="#{sortingBean.sortDirectionItems}" />
+ </h:selectOneMenu>
+ </h:panelGrid>
+ </a4j:outputPanel>
+
+ <a4j:outputPanel
+ rendered="#{(!(sortingBean.firstSortOption.item ==
0))and(!(sortingBean.firstSortOption.direction == 'UNSORTED'))}">
+ <h:panelGrid columns="3" width="300px"
+ columnClasses="equals,equals,equals">
+ <h:outputText value="Second sort by:" />
+ <h:selectOneMenu value="#{sortingBean.secondSortOption.item}"
+ valueChangeListener="#{sortingBean.secondSortOptionValueChanged}">
+ <a4j:support event="onchange" reRender="sortPanel"
+ ajaxSingle="true" />
+ <f:selectItems value="#{sortingBean.secondSortItems}" />
+ </h:selectOneMenu>
+ <h:selectOneMenu
+ value="#{sortingBean.secondSortOption.direction}">
+ <a4j:support event="onchange" reRender="sortPanel" />
+ <f:selectItems value="#{sortingBean.sortDirectionItems}" />
+ </h:selectOneMenu>
+ </h:panelGrid>
+ </a4j:outputPanel>
+
+ <a4j:outputPanel
+ rendered="#{(!(sortingBean.secondSortOption.item ==
0))and(!(sortingBean.firstSortOption.item ==
0))and(!(sortingBean.secondSortOption.direction == 'UNSORTED'))}">
+ <h:panelGrid columns="3" width="300px"
+ columnClasses="equals,equals,equals">
+ <h:outputText value="Third sort by:" />
+ <h:selectOneMenu value="#{sortingBean.thirdSortOption.item}"
+ valueChangeListener="#{sortingBean.thirdSortOptionValueChanged}">
+ <a4j:support event="onchange" reRender="sortPanel"
+ ajaxSingle="true" />
+ <f:selectItems value="#{sortingBean.thirdSortItems}" />
+ </h:selectOneMenu>
+ <h:selectOneMenu
value="#{sortingBean.thirdSortOption.direction}">
+ <a4j:support event="onchange" reRender="sortPanel" />
+ <f:selectItems value="#{sortingBean.sortDirectionItems}" />
+ </h:selectOneMenu>
+ </h:panelGrid>
+ </a4j:outputPanel>
</h:panelGrid>
- <a4j:commandButton value="Sort Table" reRender="table"
action="#{sortingBean.changeSorting}"/>
- </rich:panel>
- </h:form>
- </h:panelGrid>
+ <a4j:commandButton value="Sort Table"
+ action="#{sortingBean.sortTable}" reRender="table"
+ disabled="#{sortingBean.firstSortOption.direction=='UNSORTED'}"
/>
+ </rich:panel>
+ </h:form>
+ </h:panelGrid>
</ui:composition>
\ No newline at end of file