Author: ilya_shaikovsky
Date: 2007-06-05 10:34:05 -0400 (Tue, 05 Jun 2007)
New Revision: 1022
Added:
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/pages/columnsSorting.jsp
Modified:
trunk/richfaces-samples/richfaces-art-datatable/src/main/java/org/rf/datatable/ExpenseReport.java
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/WEB-INF/faces-config.xml
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/WEB-INF/faces-config.xml.l4t
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/pages/main.jsp
Log:
Modified:
trunk/richfaces-samples/richfaces-art-datatable/src/main/java/org/rf/datatable/ExpenseReport.java
===================================================================
---
trunk/richfaces-samples/richfaces-art-datatable/src/main/java/org/rf/datatable/ExpenseReport.java 2007-06-05
14:25:26 UTC (rev 1021)
+++
trunk/richfaces-samples/richfaces-art-datatable/src/main/java/org/rf/datatable/ExpenseReport.java 2007-06-05
14:34:05 UTC (rev 1022)
@@ -1,12 +1,60 @@
package org.rf.datatable;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
public class ExpenseReport {
private List records = null;
+
+ private boolean citySorted=true;
+ private boolean mealsSorted=true;
+ private boolean hotelsSorted=true;
+ private boolean totalsSorted=true;
+ private boolean transportSorted=true;
+
+ public boolean isCitySorted() {
+ return citySorted;
+ }
+ public void setCitySorted(boolean citySorted) {
+ this.citySorted = citySorted;
+ }
+
+ public boolean isHotelsSorted() {
+ return hotelsSorted;
+ }
+
+ public void setHotelsSorted(boolean hotelsSorted) {
+ this.hotelsSorted = hotelsSorted;
+ }
+
+ public boolean isMealsSorted() {
+ return mealsSorted;
+ }
+
+ public void setMealsSorted(boolean mealsSorted) {
+ this.mealsSorted = mealsSorted;
+ }
+
+ public boolean isTotalsSorted() {
+ return totalsSorted;
+ }
+
+ public void setTotalsSorted(boolean totalsSorted) {
+ this.totalsSorted = totalsSorted;
+ }
+
+ public boolean isTransportSorted() {
+ return transportSorted;
+ }
+
+ public void setTransportSorted(boolean transportSorted) {
+ this.transportSorted = transportSorted;
+ }
+
public List getRecords() {
if (records==null) {
initRecords();
@@ -73,4 +121,122 @@
records.add(rec);
}
+ public String sortCityNames(){
+ Collections.sort(records, new Comparator(){
+ public int compare(Object record, Object record2) {
+ if (isCitySorted()) return
((ExpenseReportRecord)record).getCity().compareTo(((ExpenseReportRecord)record2).getCity());
+ else return
-((ExpenseReportRecord)record).getCity().compareTo(((ExpenseReportRecord)record2).getCity());
+ }
+ });
+ setCitySorted(!isCitySorted());
+ setHotelsSorted(true);
+ setMealsSorted(true);
+ setTotalsSorted(true);
+ setTransportSorted(true);
+ return null;
+ }
+
+ public String sortMeals(){
+ Collections.sort(records, new Comparator(){
+ public int compare(Object record, Object record2) {
+ if ((((ExpenseReportRecord)record).getTotalMeals() >
((ExpenseReportRecord)record2).getTotalMeals())&& isMealsSorted())
+ if (isMealsSorted()){
+ return 1;}
+ else{
+ return -1;
+ }
+ else if (((ExpenseReportRecord)record).getTotalMeals() <
((ExpenseReportRecord)record2).getTotalMeals())
+ if (isMealsSorted()){
+ return -1;
+ }
+ else{
+ return 1;
+ }
+ else return 0;
+ }
+
+ });
+ setMealsSorted(!isMealsSorted());
+ setHotelsSorted(true);
+ setTotalsSorted(true);
+ setTransportSorted(true);
+ setCitySorted(true);
+ return null;
+ }
+
+ public String sortTransport(){
+ Collections.sort(records, new Comparator(){
+ public int compare(Object record, Object record2) {
+ if (((ExpenseReportRecord)record).getTotalTransport() >
((ExpenseReportRecord)record2).getTotalTransport())
+ if (isTransportSorted())
+ return 1;
+ else
+ return -1;
+ else if (((ExpenseReportRecord)record).getTotalTransport() <
((ExpenseReportRecord)record2).getTotalTransport())
+ if (isTransportSorted())
+ return -1;
+ else
+ return 1;
+ else return 0;
+ }
+
+ });
+ setTransportSorted(!isTransportSorted());
+ setMealsSorted(true);
+ setHotelsSorted(true);
+ setTotalsSorted(true);
+ setCitySorted(true);
+ return null;
+ }
+
+ public String sortHotels(){
+ Collections.sort(records, new Comparator(){
+ public int compare(Object record, Object record2) {
+ if (((ExpenseReportRecord)record).getTotalHotels() >
((ExpenseReportRecord)record2).getTotalHotels())
+ if (isHotelsSorted())
+ return 1;
+ else
+ return -1;
+ else if (((ExpenseReportRecord)record).getTotalHotels() <
((ExpenseReportRecord)record2).getTotalHotels())
+ if (isHotelsSorted())
+ return -1;
+ else
+ return 1;
+ else return 0;
+ }
+
+ });
+ setHotelsSorted(!isHotelsSorted());
+ setMealsSorted(true);
+ setTotalsSorted(true);
+ setCitySorted(true);
+ setTransportSorted(true);
+ return null;
+ }
+
+ public String sortTotal(){
+ Collections.sort(records, new Comparator(){
+ public int compare(Object record, Object record2) {
+ if (((ExpenseReportRecord)record).getTotal() >
((ExpenseReportRecord)record2).getTotal())
+ if (isTotalsSorted())
+ return 1;
+ else
+ return -1;
+ else if (((ExpenseReportRecord)record).getTotal() <
((ExpenseReportRecord)record2).getTotal() )
+ if (isTotalsSorted())
+ return -1;
+ else
+ return 1;
+ else return 0;
+ }
+
+ });
+ setTotalsSorted(!isTotalsSorted());
+ setMealsSorted(true);
+ setCitySorted(true);
+ setTransportSorted(true);
+ setHotelsSorted(true);
+ return null;
+ }
+
}
Modified:
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/WEB-INF/faces-config.xml 2007-06-05
14:25:26 UTC (rev 1021)
+++
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/WEB-INF/faces-config.xml 2007-06-05
14:34:05 UTC (rev 1022)
@@ -54,6 +54,11 @@
<to-view-id>/pages/example10.jsp</to-view-id>
<redirect/>
</navigation-case>
+ <navigation-case>
+ <from-outcome>example5</from-outcome>
+ <to-view-id>/pages/columnsSorting.jsp</to-view-id>
+ <redirect/>
+ </navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>*</from-view-id>
Modified:
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/WEB-INF/faces-config.xml.l4t
===================================================================
---
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/WEB-INF/faces-config.xml.l4t 2007-06-05
14:25:26 UTC (rev 1021)
+++
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/WEB-INF/faces-config.xml.l4t 2007-06-05
14:34:05 UTC (rev 1022)
@@ -19,6 +19,10 @@
<PROCESS-ITEM-OUTPUT ENTITY="JSFProcessItemOutput"
ID="example10::#pages#example10.jsp" NAME="output4"
PATH="/pages/example10.jsp" TARGET="rules:#pages#example10.jsp"
TITLE="example10"/>
+ <PROCESS-ITEM-OUTPUT ENTITY="JSFProcessItemOutput"
+ ID="example5::#pages#columnsSorting.jsp" NAME="output5"
+ PATH="/pages/columnsSorting.jsp"
+ TARGET="rules:#pages#columnsSorting.jsp" TITLE="example5"/>
</PROCESS-ITEM>
</PROCESS-ITEM>
<PROCESS-ITEM ENTITY="JSFProcessGroup" NAME="rules:*"
PATH="*" SHAPE="32,17,0,0">
@@ -38,4 +42,7 @@
PATH="/pages/example4.jsp" SHAPE="512,481,0,0"/>
<PROCESS-ITEM ENTITY="JSFProcessGroup"
NAME="rules:#pages#example1.jsp"
PATH="/pages/example1.jsp" SHAPE="512,17,0,0"/>
+ <PROCESS-ITEM ENTITY="JSFProcessGroup"
+ NAME="rules:#pages#columnsSorting.jsp"
+ PATH="/pages/columnsSorting.jsp" SHAPE="512,289,0,0"/>
</PROCESS>
Added:
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/pages/columnsSorting.jsp
===================================================================
---
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/pages/columnsSorting.jsp
(rev 0)
+++
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/pages/columnsSorting.jsp 2007-06-05
14:34:05 UTC (rev 1022)
@@ -0,0 +1,70 @@
+<%@ taglib
uri="http://java.sun.com/jsf/html" prefix="h"%>
+<%@ taglib
uri="http://java.sun.com/jsf/core" prefix="f"%>
+<%@ taglib
uri="https://ajax4jsf.dev.java.net/ajax"
prefix="a4j"%>
+<%@ taglib
uri="http://richfaces.ajax4jsf.org/rich"
prefix="rich"%>
+
+<html>
+<head>
+ <title>RichFaces dataTable Article. Example #6. Sorting Rows.</title>
+</head>
+<body>
+ <f:view>
+ <h:outputText value="RichFaces dataTable Article. Example #6. Sorting
Rows."/>
+ <h:form>
+ <rich:dataTable value="#{expenseReport.records}" var="record"
id="table">
+ <h:column>
+ <f:facet name="header">
+ <a4j:commandLink value="City Name"
action="#{expenseReport.sortCityNames}" reRender="table"
ajaxSingle="true"/>
+ </f:facet>
+ <h:outputText value="#{record.city}" />
+ </h:column>
+ <h:column>
+ <f:facet name="header">
+ <a4j:commandLink value="Meals"
action="#{expenseReport.sortMeals}" reRender="table"
ajaxSingle="true"/>
+ </f:facet>
+ <h:outputText value="#{record.totalMeals}">
+ <f:convertNumber pattern="$####.00" />
+ </h:outputText>
+ </h:column>
+ <h:column>
+ <f:facet name="header">
+ <a4j:commandLink value="Transport"
action="#{expenseReport.sortTransport}" reRender="table"
ajaxSingle="true"/>
+ </f:facet>
+ <h:outputText value="#{record.totalTransport}">
+ <f:convertNumber pattern="$####.00" />
+ </h:outputText>
+ </h:column>
+ <h:column>
+ <f:facet name="header">
+ <a4j:commandLink value="Hotels"
action="#{expenseReport.sortHotels}" reRender="table"
ajaxSingle="true"/>
+ </f:facet>
+ <h:outputText value="#{record.totalHotels}">
+ <f:convertNumber pattern="$####.00" />
+ </h:outputText>
+ </h:column>
+ <h:column>
+ <f:facet name="header">
+ <a4j:commandLink value="Total"
action="#{expenseReport.sortTotal}" reRender="table"
ajaxSingle="true"/>
+ </f:facet>
+ <h:outputText value="#{record.total}">
+ <f:convertNumber pattern="$####.00" />
+ </h:outputText>
+ </h:column>
+ </rich:dataTable>
+ <a4j:status startText="Sorting in progress" stopText=" "
startStyle="color:red">
+ </a4j:status>
+ </h:form>
+ <h:form>
+ <rich:separator lineType="dashed" height="1"
style="padding-top:20px" />
+ <h:outputText value="Source Code:" />
+ <h:outputLink
value="http://anonsvn.jboss.org/repos/richfaces/trunk/richfaces-samp...
+ <h:outputText value="Page" />
+ </h:outputLink>
+ <h:outputLink
value="http://anonsvn.jboss.org/repos/richfaces/trunk/richfaces-samp...
+ <h:outputText value="Project" />
+ </h:outputLink>
+ <rich:separator lineType="dashed" height="1"
style="padding-top:20px" />
+ <h:commandLink value="back to example list"
action="main"></h:commandLink>
+ </h:form> </f:view>
+</body>
+</html>
\ No newline at end of file
Modified: trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/pages/main.jsp
===================================================================
---
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/pages/main.jsp 2007-06-05
14:25:26 UTC (rev 1021)
+++
trunk/richfaces-samples/richfaces-art-datatable/src/main/webapp/pages/main.jsp 2007-06-05
14:34:05 UTC (rev 1022)
@@ -12,6 +12,7 @@
<h:commandLink value="Example #2. Using rich:column and
rich:columnGroup" action="example2" />
<h:commandLink value="Example #3. Look-n-Feel Customization with Predefined
Classes" action="example3" />
<h:commandLink value="Example #4. Look-n-Feel Customization. Using Classes
and Styles" action="example4" />
+ <h:commandLink value="Example #5. Sorting Rows."
action="example5"/>
<h:commandLink value="Example #10. Ajax Update"
action="example10" />
</h:panelGrid>