Author: adubovsky
Date: 2008-10-20 11:01:00 -0400 (Mon, 20 Oct 2008)
New Revision: 10838
Modified:
trunk/test-applications/facelets/src/main/java/scrollableDataTable/ScrollableDataTable.java
trunk/test-applications/facelets/src/main/webapp/ScrollableDataTable/ScrollableDataTable.xhtml
Log:
Add "Show selection" functionality to scrollableDataTable
Modified:
trunk/test-applications/facelets/src/main/java/scrollableDataTable/ScrollableDataTable.java
===================================================================
---
trunk/test-applications/facelets/src/main/java/scrollableDataTable/ScrollableDataTable.java 2008-10-20
14:59:15 UTC (rev 10837)
+++
trunk/test-applications/facelets/src/main/java/scrollableDataTable/ScrollableDataTable.java 2008-10-20
15:01:00 UTC (rev 10838)
@@ -2,21 +2,22 @@
import java.util.ArrayList;
import java.util.GregorianCalendar;
+import java.util.Iterator;
import org.ajax4jsf.model.DataComponentState;
import org.richfaces.component.html.HtmlScrollableDataTable;
-import org.richfaces.model.selection.Selection;
+import org.richfaces.model.selection.SimpleSelection;
import util.componentInfo.ComponentInfo;
import util.data.Data;
/**
* @author AYanul
- *
+ *
*/
-public class ScrollableDataTable
-{
+public class ScrollableDataTable {
private ArrayList<Data> data;
+ private ArrayList<Data> selectedRows;
private String width;
private int rows;
private String key;
@@ -34,16 +35,16 @@
private boolean ignoreDupResponses;
private String eventsQueue;
private String activeRowKey;
- private Selection selection;
+ private SimpleSelection selection;
private boolean ajaxSingle;
private GregorianCalendar date;
private HtmlScrollableDataTable htmlScrollableDataTable = null;
-
- public void addHtmlScrollableDataTable(){
+
+ public void addHtmlScrollableDataTable() {
ComponentInfo info = ComponentInfo.getInstance();
info.addField(htmlScrollableDataTable);
}
-
+
public HtmlScrollableDataTable getHtmlScrollableDataTable() {
return htmlScrollableDataTable;
}
@@ -63,11 +64,12 @@
public ScrollableDataTable() {
sortMode = "single";
- width = "400px";
+ width = "750px";
rows = 30;
- hideWhenScrolling = false;
+ hideWhenScrolling = true;
dataLength = 40;
data = new ArrayList<Data>();
+ selectedRows = new ArrayList<Data>();
first = 0;
rendered = true;
timeout = 0;
@@ -79,12 +81,29 @@
date = new GregorianCalendar();
addNewItem();
}
-
- public Selection getSelection() {
+
+ public void takeSelection() {
+ getSelectedRows().clear();
+ if (getSelection().isSelectAll()) {
+ getSelectedRows().addAll(data);
+ } else {
+ Iterator<Object> iterator = getSelection().getKeys();
+ while (iterator.hasNext()) {
+ Object key = iterator.next();
+ htmlScrollableDataTable.setRowKey(key);
+ if (htmlScrollableDataTable.isRowAvailable()) {
+ getSelectedRows().add(
+ (Data) htmlScrollableDataTable.getRowData());
+ }
+ }
+ }
+ }
+
+ public SimpleSelection getSelection() {
return selection;
}
- public void setSelection(Selection selection) {
+ public void setSelection(SimpleSelection selection) {
this.selection = selection;
}
@@ -187,19 +206,21 @@
public void setHideWhenScrolling(boolean hideWhenScrolling) {
this.hideWhenScrolling = hideWhenScrolling;
}
-
- public void addNewItem() {
- if(dataLength < 0) dataLength = 0;
- if(data.size() > dataLength)
- for(int i = data.size() - 1; i >= dataLength; i--)
+
+ public void addNewItem() {
+ if (dataLength < 0)
+ dataLength = 0;
+ if (data.size() > dataLength)
+ for (int i = data.size() - 1; i >= dataLength; i--)
data.remove(i);
else
- for(int i = data.size(); i < dataLength; i++){
- date.set(2008, 5, 14, 3, i);
- data.add(new Data(i, "Text " + i, "Link " + i, "select"
+(i % 5), Data.statusIcon[i % 5], date.getTime()));
+ for (int i = data.size(); i < dataLength; i++) {
+ date.set(2008, 5, 14, 3, i);
+ data.add(new Data(i, "Text " + i, "Link " + i,
"select"
+ + (i % 5), Data.statusIcon[i % 5], date.getTime()));
}
}
-
+
public ArrayList<Data> getData() {
return data;
}
@@ -251,4 +272,12 @@
public void setSortMode(String sortMode) {
this.sortMode = sortMode;
}
+
+ public ArrayList<Data> getSelectedRows() {
+ return selectedRows;
+ }
+
+ public void setSelectedRows(ArrayList<Data> selectedRows) {
+ this.selectedRows = selectedRows;
+ }
}
\ No newline at end of file
Modified:
trunk/test-applications/facelets/src/main/webapp/ScrollableDataTable/ScrollableDataTable.xhtml
===================================================================
---
trunk/test-applications/facelets/src/main/webapp/ScrollableDataTable/ScrollableDataTable.xhtml 2008-10-20
14:59:15 UTC (rev 10837)
+++
trunk/test-applications/facelets/src/main/webapp/ScrollableDataTable/ScrollableDataTable.xhtml 2008-10-20
15:01:00 UTC (rev 10838)
@@ -1,72 +1,109 @@
-<f:subview
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
id="scrollableDataTableSubviewID">
- <h:panelGrid columns="6" border="1"
style="font-size:12px">
- <h:outputText value="#1"></h:outputText>
- <h:outputText value="#2"></h:outputText>
- <h:outputText value="#3"></h:outputText>
- <h:outputText value="#4"></h:outputText>
- <h:outputText value="#5"></h:outputText>
- <h:outputText value="#6"></h:outputText>
-
+<f:subview
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:rich="http://richfaces.org/rich"
+ id="scrollableDataTableSubviewID">
+
+ <h:panelGrid columns="7" border="1"
style="font-size:12px">
+ <h:outputText value="#1 "></h:outputText>
+ <h:outputText value="#2 Text"></h:outputText>
+ <h:outputText value="#3 Link"></h:outputText>
+ <h:outputText value="#4 Select"></h:outputText>
+ <h:outputText value="#5 Icon"></h:outputText>
+ <h:outputText value="#6 outputLink"></h:outputText>
+ <h:outputText value="#7 Date"></h:outputText>
+
<h:panelGrid columns="1" title="1">
- <h:outputText value="sortExpression"/>
- <h:outputText value="sortable='true'"/>
+ <h:outputText value="sortBy" />
+ <h:outputText value="sortable='true'" />
</h:panelGrid>
<h:panelGrid columns="1" title="2">
- <h:outputText value="sortExpression"/>
- <h:outputText value="sortable='false'"/>
+ <h:outputText value="sortBy" />
+ <h:outputText value="sortable='false'" />
</h:panelGrid>
<h:panelGrid columns="1" title="3">
- <h:outputText value="sortExpression"/>
+ <h:outputText value="sortBy" />
+ <h:outputText value="undefined sortable" />
</h:panelGrid>
<h:panelGrid columns="1" title="4">
- <h:outputText value="sortExpression"/>
+ <h:outputText value="sortBy" />
+ <h:outputText value="undefined sortable" />
</h:panelGrid>
<h:panelGrid columns="1" title="5">
- <h:outputText value="sortExpression"/>
+ <h:outputText value="sortBy" />
+ <h:outputText value="undefined sortable" />
</h:panelGrid>
<h:panelGrid columns="1" title="6">
- <h:outputText value=""/>
+ <h:outputText value="undefined sortBy" />
+ <h:outputText value="undefined sortable" />
</h:panelGrid>
+ <h:panelGrid columns="1" title="7">
+ <h:outputText value="sortBy" />
+ <h:outputText value="sortable='true'" />
+ </h:panelGrid>
</h:panelGrid>
- <rich:scrollableDataTable id="sdt" var="sdt"
rowKeyVar="key" onRowDblClick="alert('row:#{key}')"
- ajaxSingle="#{scrollableDT.ajaxSingle}"
- binding="#{scrollableDT.htmlScrollableDataTable}"
- value="#{scrollableDT.data}" rows="#{scrollableDT.rows}"
- width="#{scrollableDT.width}" height="#{scrollableDT.height}"
+ <br />
+ <rich:scrollableDataTable
+ binding="#{scrollableDT.htmlScrollableDataTable}" id="sdt"
var="sdt"
+ rowKeyVar="key" onRowDblClick="alert('row: #{key}')"
+ rowKeyConverter="#{dataConverter}" value="#{scrollableDT.data}"
+ rows="#{scrollableDT.rows}" width="#{scrollableDT.width}"
+ height="#{scrollableDT.height}"
hideWhenScrolling="#{scrollableDT.hideWhenScrolling}"
reRender="inputID" frozenColCount="#{scrollableDT.frozenColCount}"
- first="#{scrollableDT.first}"
ignoreDupResponses="#{scrollableDT.ignoreDupResponses}"
- bypassUpdates="#{scrollableDT.bypassUpdates}"
rendered="#{scrollableDT.rendered}"
- limitToList="#{scrollableDT.limitToList}"
-
- timeout="#{scrollableDT.timeout}"
sortMode="#{scrollableDT.sortMode}"
- selection="#{scrollableDT.selection}" eventsQueue="myEventsQueue"
- captionClass="#{style.captionClass}"
columnClasses="#{style.columnClasses}"
footerClass="#{style.footerClass}" headerClass="#{style.headerClass}"
rowClasses="#{style.rowClasses}" activeClass="#{style.activeClass}"
styleClass="#{style.styleClass}" style="#{style.style}"
selectedClass="#{style.selectedClass}"
- onbeforedomupdate="#{event.onbeforedomupdate}"
oncomplete="#{event.oncomplete}" onRowClick="#{event.onRowClick}"
onRowMouseDown="#{event.onRowMouseDown}"
onRowMouseUp="#{event.onRowMouseUp}"
onselectionchange="#{event.onselectionchange}">
+ first="#{scrollableDT.first}"
+ ignoreDupResponses="#{scrollableDT.ignoreDupResponses}"
+ bypassUpdates="#{scrollableDT.bypassUpdates}"
+ rendered="#{scrollableDT.rendered}"
timeout="#{scrollableDT.timeout}"
+ sortMode="#{scrollableDT.sortMode}" eventsQueue="myEventsQueue"
+ columnClasses="#{style.columnClasses}"
+ footerClass="#{style.footerClass}"
headerClass="#{style.headerClass}"
+ rowClasses="#{style.rowClasses}"
activeClass="#{style.activeClass}"
+ styleClass="#{style.styleClass}" style="#{style.style}"
+ selectedClass="#{style.selectedClass}"
+ onRowMouseDown="#{event.onRowMouseDown}"
+ onRowMouseUp="#{event.onRowMouseUp}"
+ onselectionchange="#{event.onselectionchange}"
+ selection="#{scrollableDT.selection}">
<f:facet name="header">
- <h:outputText value="facet header"></h:outputText>
+ <h:outputText value="facet header"></h:outputText>
</f:facet>
- <rich:column sortExpression="#{sdt.int0}" sortable="true">
- <f:facet name="header"><h:outputText
value="#"/></f:facet>
+ <rich:column sortBy="#{sdt.int0}" sortable="true"
id="colID">
+ <f:facet name="header">
+ <h:outputText value="#" />
+ </f:facet>
<h:outputText value="#{sdt.int0}"></h:outputText>
- <f:facet name="footer"><h:outputText
value="#"/></f:facet>
+ <f:facet name="footer">
+ <h:outputText value="#" />
+ </f:facet>
</rich:column>
- <rich:column sortExpression="#{sdt.str0}" sortable="false">
- <f:facet name="header"><h:outputText
value="Text"></h:outputText> </f:facet>
+ <rich:column sortBy="#{sdt.str0}" sortable="false">
+ <f:facet name="header">
+ <h:outputText value="Text"></h:outputText>
+ </f:facet>
<h:outputText value="#{sdt.str0}"></h:outputText>
- <f:facet name="footer"><h:outputText
value="Text"></h:outputText> </f:facet>
+ <f:facet name="footer">
+ <h:outputText value="Text"></h:outputText>
+ </f:facet>
</rich:column>
- <rich:column sortExpression="#{sdt.str1}">
- <f:facet name="header"><h:outputText
value="Link"></h:outputText> </f:facet>
+ <rich:column sortBy="#{sdt.str1}">
+ <f:facet name="header">
+ <h:outputText value="Link"></h:outputText>
+ </f:facet>
<a4j:commandLink value="#{sdt.str1}"
reRender="sdt"></a4j:commandLink>
- <f:facet name="footer"><h:outputText
value="Link"></h:outputText> </f:facet>
+ <f:facet name="footer">
+ <h:outputText value="Link"></h:outputText>
+ </f:facet>
</rich:column>
- <rich:column sortExpression="#{sdt.str2}">
- <f:facet name="header"><h:outputText
value="Select"></h:outputText> </f:facet>
+ <rich:column sortBy="#{sdt.str2}">
+ <f:facet name="header">
+ <h:outputText value="Select"></h:outputText>
+ </f:facet>
<h:selectOneMenu value="#{sdt.str2}">
<f:selectItem itemLabel="select0" itemValue="select0" />
<f:selectItem itemLabel="select1" itemValue="select1" />
@@ -74,27 +111,153 @@
<f:selectItem itemLabel="select3" itemValue="select3" />
<f:selectItem itemLabel="select4" itemValue="select4" />
</h:selectOneMenu>
- <f:facet name="footer"><h:outputText
value="Select"></h:outputText> </f:facet>
+ <f:facet name="footer">
+ <h:outputText value="Select"></h:outputText>
+ </f:facet>
</rich:column>
- <rich:column sortExpression="#{sdt.str3}">
- <f:facet name="header"><h:outputText
value="Select"></h:outputText> </f:facet>
+ <rich:column sortBy="#{sdt.str3}">
+ <f:facet name="header">
+ <h:outputText value="Icon"></h:outputText>
+ </f:facet>
<h:graphicImage value="#{sdt.str3}"></h:graphicImage>
- <f:facet name="footer"><h:outputText
value="Select"></h:outputText> </f:facet>
+ <f:facet name="footer">
+ <h:outputText value="Icon"></h:outputText>
+ </f:facet>
</rich:column>
-
+
<rich:column>
<f:facet name="header">
- <h:outputText value="Link"></h:outputText>
+ <h:outputText value="outputLink"></h:outputText>
</f:facet>
- <h:outputLink
value="http://www.jboss.com/"><f:verbatim>Link</f:v...
+ <h:outputLink
value="http://www.jboss.com/">
+ <f:verbatim>Link</f:verbatim>
+ </h:outputLink>
<f:facet name="footer">
- <h:outputText value="Link"></h:outputText>
+ <h:outputText value="outputLink"></h:outputText>
</f:facet>
- </rich:column>
-
+ </rich:column>
+
+ <rich:column sortBy="#{sdt.date0}" sortable="true">
+ <f:facet name="header">
+ <h:outputText value="Date" />
+ </f:facet>
+ <h:outputText value="#{sdt.date0}"></h:outputText>
+ <f:facet name="footer">
+ <h:outputText value="Date" />
+ </f:facet>
+ </rich:column>
+
<f:facet name="footer">
<h:outputText value="facet footer"></h:outputText>
</f:facet>
</rich:scrollableDataTable>
+ <br />
+ <a4j:commandButton value="Show Current Selection"
reRender="table"
+ action="#{scrollableDT.takeSelection}"
+ oncomplete="javascript:Richfaces.showModalPanel('panel');" />
+
+ <rich:modalPanel id="panel" autosized="true"
keepVisualState="false" >
+ <f:facet name="header">
+ <h:outputText value="Selected Rows" />
+ </f:facet>
+ <f:facet name="controls">
+ <a4j:commandLink style="cursor: pointer"
+ onclick="javascript:Richfaces.hideModalPanel('panel')"
value="X" />
+ </f:facet>
+ <h:panelGroup layout="block" styleClass="scrolls">
+ <rich:dataTable value="#{scrollableDT.selectedRows}" var="sel"
+ id="table">
+ <rich:column sortBy="#{sel.int0}" sortable="true"
id="colID">
+ <f:facet name="header">
+ <h:outputText value="#" />
+ </f:facet>
+ <h:outputText value="#{sel.int0}"></h:outputText>
+ </rich:column>
+
+ <rich:column sortBy="#{sel.str0}" sortable="false">
+ <f:facet name="header">
+ <h:outputText value="Text"></h:outputText>
+ </f:facet>
+ <h:outputText value="#{sel.str0}"></h:outputText>
+ </rich:column>
+
+ <rich:column sortBy="#{sel.str1}">
+ <f:facet name="header">
+ <h:outputText value="Link"></h:outputText>
+ </f:facet>
+ <a4j:commandLink value="#{sel.str1}"
reRender="sdt"></a4j:commandLink>
+ </rich:column>
+
+ <rich:column sortBy="#{sel.str2}">
+ <f:facet name="header">
+ <h:outputText value="Select"></h:outputText>
+ </f:facet>
+ <h:selectOneMenu value="#{sel.str2}">
+ <f:selectItem itemLabel="select0" itemValue="select0" />
+ <f:selectItem itemLabel="select1" itemValue="select1" />
+ <f:selectItem itemLabel="select2" itemValue="select2" />
+ <f:selectItem itemLabel="select3" itemValue="select3" />
+ <f:selectItem itemLabel="select4" itemValue="select4" />
+ </h:selectOneMenu>
+ </rich:column>
+
+ <rich:column sortBy="#{sel.str3}">
+ <f:facet name="header">
+ <h:outputText value="Icon"></h:outputText>
+ </f:facet>
+ <h:graphicImage value="#{sel.str3}"></h:graphicImage>
+ </rich:column>
+
+ <rich:column>
+ <f:facet name="header">
+ <h:outputText value="outputLink"></h:outputText>
+ </f:facet>
+ <h:outputLink
value="http://www.jboss.com/">
+ <f:verbatim>Link</f:verbatim>
+ </h:outputLink>
+ </rich:column>
+
+ <rich:column sortBy="#{sel.date0}" sortable="true">
+ <f:facet name="header">
+ <h:outputText value="Date" />
+ </f:facet>
+ <h:outputText value="#{sel.date0}"></h:outputText>
+ </rich:column>
+ </rich:dataTable>
+ </h:panelGroup>
+ </rich:modalPanel>
+ <br />
+ <h:panelGrid columns="2" border="1">
+ <h:panelGroup>
+ <h:outputText value="JS API test" style="FONT-WEIGHT:
bold;"></h:outputText>
+ <br />
+ <a4j:commandLink
+ onclick="$('formID:scrollableDataTableSubviewID:sdt').component.collapse(colID)"
+ value="collapse('colID')"></a4j:commandLink>
+ <br />
+ <a4j:commandLink
+ onclick="$('formID:scrollableDataTableSubviewID:sdt').component.expand(colID)"
+ value="expand('colID')"></a4j:commandLink>
+ </h:panelGroup>
+ <h:panelGroup>
+ <f:verbatim>
+ <h:outputText value="Component control+JS API"
+ style="FONT-WEIGHT: bold;"></h:outputText>
+ <br />
+ <a href="#" id="collapseID">collapseID</a>
+ <br />
+ <a href="#" id="expandID">expandID</a>
+ </f:verbatim>
+ <rich:componentControl attachTo="collapseID" event="onclick"
+ for="sdt" operation="collapse">
+ <f:param value="colID" name="colID" />
+ </rich:componentControl>
+ <rich:componentControl attachTo="expandID" event="onclick"
for="sdt"
+ operation="expand">
+ <f:param value="colID" name="colID" />
+ </rich:componentControl>
+ </h:panelGroup>
+ </h:panelGrid>
+ <br />
</f:subview>