JBoss Rich Faces SVN: r16700 - root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-03-31 11:29:01 -0400 (Wed, 31 Mar 2010)
New Revision: 16700
Removed:
root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/RenderPhaseComponentVisitor.java
Log:
Deleted: root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/RenderPhaseComponentVisitor.java
===================================================================
--- root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/RenderPhaseComponentVisitor.java 2010-03-31 15:25:51 UTC (rev 16699)
+++ root/ui-sandbox/trunk/components/datascroller/api/src/main/java/org/richfaces/event/RenderPhaseComponentVisitor.java 2010-03-31 15:29:01 UTC (rev 16700)
@@ -1,36 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.event;
-
-import javax.faces.component.UIComponent;
-import javax.faces.event.PhaseEvent;
-
-public interface RenderPhaseComponentVisitor {
-
- Object beforeRoot(PhaseEvent event);
-
- void beforeComponent(UIComponent component, PhaseEvent event, Object state);
-
- void afterComponent(UIComponent component, PhaseEvent event, Object state);
-
- void afterRoot(PhaseEvent event, Object state);
-
-}
14 years, 9 months
JBoss Rich Faces SVN: r16699 - root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-03-31 11:25:51 -0400 (Wed, 31 Mar 2010)
New Revision: 16699
Removed:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/RenderPhaseDataScrollerVisitor.java
Log:
use dataTable's PreRender event listener instead of this visitor
Deleted: root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/RenderPhaseDataScrollerVisitor.java
===================================================================
--- root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/RenderPhaseDataScrollerVisitor.java 2010-03-31 15:24:11 UTC (rev 16698)
+++ root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/RenderPhaseDataScrollerVisitor.java 2010-03-31 15:25:51 UTC (rev 16699)
@@ -1,232 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.component;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.el.Expression;
-import javax.el.ValueExpression;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIData;
-import javax.faces.context.FacesContext;
-import javax.faces.event.PhaseEvent;
-
-import org.ajax4jsf.Messages;
-import org.richfaces.component.util.MessageUtil;
-import org.richfaces.event.RenderPhaseComponentVisitor;
-import org.richfaces.log.RichfacesLogger;
-import org.slf4j.Logger;
-
-
-/**
- * Created 08.03.2008
- * @author Nick Belaevski
- * @since 3.2
- */
-
-public class RenderPhaseDataScrollerVisitor implements RenderPhaseComponentVisitor {
-
- private class State {
-
- private ComponentConnections connections;
- private LinkedList<UIComponent> components;
-
- private State(LinkedList<UIComponent> components,
- ComponentConnections connections) {
- this.components = components;
- this.connections = connections;
- }
- }
-
- private static final class ComponentConnections {
- private final Map<UIData, List<UIDataScroller>> map =
- new HashMap<UIData, List<UIDataScroller>>();
-
- public void addConnection(UIData one, UIDataScroller multi) {
- List<UIDataScroller> list = map.get(one);
- if (list == null) {
- list = new ArrayList<UIDataScroller>(1);
- map.put(one, list);
- }
-
- list.add(multi);
- }
-
- public Iterator<Entry<UIData, List<UIDataScroller>>> iterator() {
- return map.entrySet().iterator();
- }
-
- @Override
- public String toString() {
- return this.getClass().getSimpleName() + ": " + map;
- }
- }
-
- private static final Logger log = RichfacesLogger.COMPONENTS.getLogger();
-
- public Object beforeRoot(PhaseEvent event) {
- return new State(new LinkedList<UIComponent>(), new ComponentConnections());
- }
-
- public void beforeComponent(UIComponent component, PhaseEvent event, Object object) {
- State state = (State) object;
- state.components.addLast(component);
-
- if (component instanceof UIDataScroller && isRendered(state.components)) {
- UIDataScroller datascroller = (UIDataScroller) component;
- //UIData dataTable = datascroller.getDataTable();
-
- // state.connections.addConnection(dataTable, datascroller);
- }
- }
-
- public void afterComponent(UIComponent component, PhaseEvent event, Object object) {
- State state = (State) object;
- state.components.removeLast();
- }
-
- public void afterRoot(PhaseEvent event, Object object) {
- State state = (State) object;
- FacesContext facesContext = event.getFacesContext();
- Iterator<Entry<UIData, List<UIDataScroller>>> entries =
- state.connections.iterator();
-
- while (entries.hasNext()) {
- Entry<UIData, List<UIDataScroller>> entry = entries.next();
- List<UIDataScroller> scrollers = entry.getValue();
- if (!scrollers.isEmpty()) {
- List<Object> values = new ArrayList<Object>(scrollers.size());
-
- UIData data = entry.getKey();
- UIDataScroller activeComponent = null;
-
- Map<String, Object> attributes = data.getAttributes();
- Object pageValue = attributes.get(UIDataScroller.SCROLLER_STATE_ATTRIBUTE);
-
- if (pageValue == null) {
- boolean valid = true;
-
- for (UIDataScroller datascroller : scrollers) {
- Object nextPageValue = null;
-
- if (datascroller.isLocalPageSet()) {
- nextPageValue = datascroller.getPage();
- attributes.put(UIDataScroller.SCROLLER_STATE_ATTRIBUTE, nextPageValue);
- datascroller.resetLocalPage();
- } else {
- nextPageValue = datascroller.getValueExpression("page");
- }
-
- if (!values.isEmpty() && !same(values.get(values.size() - 1), nextPageValue)) {
- valid = false;
- }
-
- values.add(nextPageValue);
-
- if (nextPageValue != null) {
- activeComponent = datascroller;
- pageValue = nextPageValue;
- }
- }
-
- if (!valid) {
- StringBuilder builder = new StringBuilder("\n[");
- Iterator<UIDataScroller> scrollerItr = scrollers.iterator();
- Iterator<Object> valueItr = values.iterator();
-
- while (scrollerItr.hasNext()) {
- UIDataScroller next = scrollerItr.next();
- builder.append(MessageUtil.getLabel(facesContext, next));
- builder.append(": ");
-
- Object value = valueItr.next();
- if (value instanceof Expression) {
- builder.append(((Expression) value).getExpressionString());
- } else {
- builder.append(value);
- }
-
- builder.append(scrollerItr.hasNext() ? ",\n" : "]");
- }
-
- String formattedMessage = Messages.getMessage(Messages.DATASCROLLER_PAGES_DIFFERENT,
- new Object[] {MessageUtil.getLabel(facesContext, data), builder});
-
-
- log.error(formattedMessage);
- }
-
- }
-
- if (activeComponent == null) {
- activeComponent = scrollers.get(scrollers.size() - 1);
- }
-
- if (pageValue != null) {
- activeComponent.setupFirstRowValue();
- }
- }
- }
- }
-
- private static boolean isRendered(List<UIComponent> components) {
- boolean rendered;
-
- for (UIComponent component : components) {
- rendered = false;
-
- try {
- rendered = component.isRendered();
- } catch (Exception e) {
- //ignore that
- if (log.isDebugEnabled()) {
- log.debug(e.getLocalizedMessage(), e);
- }
- }
-
- if (!rendered) {
- return false;
- }
- }
-
- return true;
- }
-
- private static boolean same(Object o1, Object o2) {
- if (o1 instanceof ValueExpression && o2 instanceof ValueExpression) {
- ValueExpression ve1 = (ValueExpression) o1;
- ValueExpression ve2 = (ValueExpression) o2;
-
- if (same(ve1.getExpressionString(), ve2.getExpressionString()) && same(ve1.getExpectedType(), ve2.getExpectedType())) {
- return true;
- }
- }
-
- return (o1 != null && o1.equals(o2)) || (o1 == null && o2 == null);
- }
-}
14 years, 9 months
JBoss Rich Faces SVN: r16698 - root/ui-sandbox/trunk/components/datascroller/ui/src/main/config.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-03-31 11:24:11 -0400 (Wed, 31 Mar 2010)
New Revision: 16698
Added:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/dataTable.faces-config.xml.xml
Log:
dataTable preRenderEvent listener registration
Added: root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/dataTable.faces-config.xml.xml
===================================================================
--- root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/dataTable.faces-config.xml.xml (rev 0)
+++ root/ui-sandbox/trunk/components/datascroller/ui/src/main/config/dataTable.faces-config.xml.xml 2010-03-31 15:24:11 UTC (rev 16698)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<faces-config version="2.0" metadata-complete="false" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:cdk="http://richfaces.org/cdk/extensions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <name>richfaces</name>
+ <application>
+ <system-event-listener>
+ <system-event-listener-class>org.richfaces.event.DataTablePreRenderListener</system-event-listener-class>
+ <system-event-class>javax.faces.event.PreRenderComponentEvent</system-event-class>
+ </system-event-listener>
+ </application>
+</faces-config>
14 years, 9 months
JBoss Rich Faces SVN: r16697 - root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-03-31 11:23:03 -0400 (Wed, 31 Mar 2010)
New Revision: 16697
Added:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/DataScrollerUtils.java
Log:
Added: root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/DataScrollerUtils.java
===================================================================
--- root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/DataScrollerUtils.java (rev 0)
+++ root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/DataScrollerUtils.java 2010-03-31 15:23:03 UTC (rev 16697)
@@ -0,0 +1,103 @@
+package org.richfaces;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+
+import org.richfaces.component.UIDataScroller;
+
+
+
+public class DataScrollerUtils {
+
+ protected enum PropertyKeys {
+ rowCount, rows
+ }
+
+ public static int getPageCount(UIComponent data, int rowCount, int rows) {
+ int pageCount;
+ if (rows > 0) {
+ pageCount = rows <= 0 ? 1 : rowCount / rows;
+ if (rowCount % rows > 0) {
+ pageCount++;
+ }
+ if (pageCount == 0) {
+ pageCount = 1;
+ }
+ } else {
+ rows = 1;
+ pageCount = 1;
+ }
+ return pageCount;
+ }
+
+ public static int getRows(UIComponent component) {
+ int row = 0;
+ row = (Integer)component.getAttributes().get("rows");
+ if (row == 0) {
+ row = getRowCount(component);
+ }
+
+ return row;
+ }
+
+ public static int getRowCount(UIComponent component) {
+ return (Integer)eval(PropertyKeys.rowCount, component, 0);
+ }
+
+ protected static Object eval(Serializable key, UIComponent component, Object defaultValue) {
+ String name = key.toString();
+ Object retObject = component.getAttributes().get(name);
+ return retObject != null ? retObject : defaultValue;
+ }
+
+ public static UIComponent findParentContainer(UIComponent component) {
+ UIComponent parent = component.getParent();
+ if(!(component instanceof NamingContainer)) {
+ findParentContainer(parent);
+ }
+ return parent;
+ }
+
+ public static List<UIDataScroller> findDataScrollers(UIComponent dataTable) {
+ List <UIDataScroller> datascrollers = new ArrayList<UIDataScroller>();
+
+ Map<String, UIComponent> facets = dataTable.getFacets();
+ Set<Entry<String, UIComponent>> entries = facets.entrySet();
+
+ for (Entry<String, UIComponent> entry: entries) {
+ findBelow(entry.getValue(), datascrollers);
+ }
+
+ UIComponent parent = findParentContainer(dataTable);
+
+ if(parent != null) {
+ findBelow(parent, datascrollers);
+ }
+
+ return datascrollers;
+ }
+
+
+ protected static void findBelow(UIComponent component, List<UIDataScroller> result) {
+ if((component instanceof UIDataScroller) && component.isRendered()) {
+ result.add((UIDataScroller)component);
+ } else {
+
+ for(UIComponent child: component.getChildren()) {
+ if(!(child instanceof NamingContainer)) {
+ findBelow(child, result);
+ }
+ }
+
+ }
+ }
+
+
+}
14 years, 9 months
JBoss Rich Faces SVN: r16696 - root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-03-31 11:22:32 -0400 (Wed, 31 Mar 2010)
New Revision: 16696
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
Log:
add jQuery script encoding
Modified: root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
===================================================================
--- root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-03-31 15:21:40 UTC (rev 16695)
+++ root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-03-31 15:22:32 UTC (rev 16696)
@@ -43,7 +43,8 @@
import org.richfaces.event.DataScrollerEvent;
-@ResourceDependencies( {@ResourceDependency(library = "javax.faces", name = "jsf-uncompressed.js"),
+@ResourceDependencies( {@ResourceDependency(library = "javax.faces", name = "jsf-uncompressed.js"),
+ @ResourceDependency(name = "jquery.js"),
@ResourceDependency(name = "richfaces.js"),
@ResourceDependency(name = "richfaces-queue.js"),
@ResourceDependency(name = "richfaces-base-component.js"),
@@ -71,7 +72,7 @@
}
}
}
-
+
public ControlsState getControlsState(FacesContext context, UIComponent component) {
int fastStep = (Integer)component.getAttributes().get("fastStep");
14 years, 9 months
JBoss Rich Faces SVN: r16695 - in root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces: event and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-03-31 11:21:40 -0400 (Wed, 31 Mar 2010)
New Revision: 16695
Added:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/event/
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/event/DataTablePreRenderListener.java
Log:
add dataTable's PreRenderEvent listener.
Added: root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/event/DataTablePreRenderListener.java
===================================================================
--- root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/event/DataTablePreRenderListener.java (rev 0)
+++ root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/event/DataTablePreRenderListener.java 2010-03-31 15:21:40 UTC (rev 16695)
@@ -0,0 +1,182 @@
+package org.richfaces.event;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.el.ValueExpression;
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIData;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+
+import org.ajax4jsf.Messages;
+import org.richfaces.DataScrollerUtils;
+import org.richfaces.component.UIDataAdaptor;
+import org.richfaces.component.UIDataScroller;
+import org.richfaces.component.UIDataScroller.PageMode;
+import org.richfaces.component.util.MessageUtil;
+import org.richfaces.log.RichfacesLogger;
+import org.slf4j.Logger;
+
+public class DataTablePreRenderListener implements SystemEventListener {
+
+ private static final Logger log = RichfacesLogger.COMPONENTS.getLogger();
+
+ @Override
+ public boolean isListenerForSource(Object source) {
+ return ((source instanceof UIDataAdaptor) || (source instanceof UIData));
+ }
+
+
+ public UIDataScroller processActiveDatascroller(FacesContext facesContext, List<UIDataScroller> dataScrollers, UIComponent dataTable) {
+
+ UIDataScroller activeComponent = null;
+ List<Object> values = new ArrayList<Object>(dataScrollers.size());
+
+ String stateKey = dataTable.getClientId(facesContext) + UIDataScroller.SCROLLER_STATE_ATTRIBUTE;
+ Map<String, Object> attributes = dataTable.getAttributes();
+ Object pageValue = attributes.get(stateKey);
+
+ boolean valid = true;
+
+ if(pageValue == null) {
+
+ for (UIDataScroller datascroller : dataScrollers) {
+ Object nextPageValue = null;
+
+ if (datascroller.isLocalPageSet()) {
+ nextPageValue = datascroller.getPage();
+ attributes.put(stateKey, nextPageValue);
+ datascroller.resetLocalPage();
+ } else {
+ nextPageValue = datascroller.getValueExpression("page");
+ }
+
+ if (!values.isEmpty() && !same(values.get(values.size() - 1), nextPageValue)) {
+ valid = false;
+ }
+
+ values.add(nextPageValue);
+
+ if (nextPageValue != null) {
+ activeComponent = datascroller;
+ }
+ }
+
+ }
+
+ if(activeComponent == null) {
+ activeComponent = dataScrollers.get(dataScrollers.size()-1);
+ }
+
+ if (!valid) {
+ //TODO: anton - test debug
+ String formattedMessage = getPageDifferentMessage(facesContext, activeComponent, dataScrollers, values);
+ log.error(formattedMessage);
+ }
+
+ return activeComponent;
+ }
+
+ @Override
+ public void processEvent(SystemEvent event) throws AbortProcessingException {
+ UIComponent dataTable = (UIComponent)event.getSource();
+ List<UIDataScroller> dataScrollers = DataScrollerUtils.findDataScrollers(dataTable);
+
+ if(!dataScrollers.isEmpty()) {
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ UIDataScroller activeComponent = processActiveDatascroller(facesContext, dataScrollers, dataTable);
+
+ int rowCount = DataScrollerUtils.getRowCount(dataTable);
+ int rows = DataScrollerUtils.getRows(dataTable);
+
+ Integer pageCount = DataScrollerUtils.getPageCount(dataTable, rowCount, rows);
+
+ int page = activeComponent.getPage();
+ int newPage = -1;
+
+ if (page < 1) {
+ newPage = 1;
+ } else if (page > pageCount) {
+ newPage = (pageCount != 0 ? pageCount : 1);
+ }
+
+ if (newPage != -1) {
+ Object label = MessageUtil.getLabel(facesContext, activeComponent);
+ String formattedMessage = Messages.getMessage(Messages.DATASCROLLER_PAGE_MISSING, new Object[] {label, page, pageCount, newPage});
+ //TODO: anton - test debug
+ log.warn(formattedMessage);
+
+ page = newPage;
+ dataTable.getAttributes().put(dataTable.getClientId(facesContext) + UIDataScroller.SCROLLER_STATE_ATTRIBUTE, page);
+ }
+
+
+ int first;
+
+ String lastPageMode = activeComponent.getLastPageMode();
+
+ if (lastPageMode == null) {
+ lastPageMode = PageMode.part.toString();
+ } else if (!PageMode.part.equals(lastPageMode) && !PageMode.full.equals(lastPageMode)) {
+ throw new IllegalArgumentException("Illegal value of 'lastPageMode' attribute: '" + lastPageMode + "'");
+ }
+
+ if (page != pageCount || PageMode.part.equals(lastPageMode)) {
+ first = (page - 1) * rows;
+ } else {
+ first = rowCount - rows;
+ if (first < 0) {
+ first = 0;
+ }
+ }
+ dataTable.getAttributes().put("first", first);
+ }
+ }
+
+ private String getPageDifferentMessage(FacesContext facesContext, UIDataScroller activeComponent, List<UIDataScroller> dataScrollers, List<Object> values) {
+ StringBuilder builder = new StringBuilder("\n[");
+ Iterator<UIDataScroller> scrollerItr = dataScrollers.iterator();
+ Iterator<Object> valueItr = values.iterator();
+
+ while (scrollerItr.hasNext()) {
+ UIDataScroller next = scrollerItr.next();
+ builder.append(MessageUtil.getLabel(facesContext, next));
+ builder.append(": ");
+
+ Object value = valueItr.next();
+ if (value instanceof ValueExpression) {
+ builder.append(((ValueExpression) value).getExpressionString());
+ } else {
+ builder.append(value);
+ }
+
+ builder.append(scrollerItr.hasNext() ? ",\n" : "]");
+ }
+
+ return Messages.getMessage(Messages.DATASCROLLER_PAGES_DIFFERENT, new Object[] {MessageUtil.getLabel(facesContext, activeComponent), builder});
+
+ }
+
+ private static boolean same(Object o1, Object o2) {
+ if (o1 instanceof ValueExpression && o2 instanceof ValueExpression) {
+ ValueExpression ve1 = (ValueExpression) o1;
+ ValueExpression ve2 = (ValueExpression) o2;
+
+ if (same(ve1.getExpressionString(), ve2.getExpressionString()) && same(ve1.getExpectedType(), ve2.getExpectedType())) {
+ return true;
+ }
+ }
+
+ return (o1 != null && o1.equals(o2)) || (o1 == null && o2 == null);
+ }
+}
14 years, 9 months
JBoss Rich Faces SVN: r16694 - root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-03-31 11:20:50 -0400 (Wed, 31 Mar 2010)
New Revision: 16694
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java
Log:
add setter/getter for the lastPageMode, move methods getRows, getRowCount to the util class
Modified: root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java
===================================================================
--- root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java 2010-03-31 15:19:29 UTC (rev 16693)
+++ root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/UIDataScroller.java 2010-03-31 15:20:50 UTC (rev 16694)
@@ -1,5 +1,6 @@
package org.richfaces.component;
+import java.util.List;
import java.util.Map;
import javax.el.ELException;
@@ -13,19 +14,17 @@
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
-import javax.faces.event.ComponentSystemEvent;
import javax.faces.event.FacesEvent;
-import org.ajax4jsf.Messages;
import org.ajax4jsf.component.IterationStateHolder;
import org.ajax4jsf.renderkit.RendererUtils;
+import org.richfaces.DataScrollerUtils;
import org.richfaces.component.util.MessageUtil;
import org.richfaces.event.DataScrollerEvent;
import org.richfaces.event.DataScrollerListener;
import org.richfaces.event.DataScrollerSource;
-import org.richfaces.log.RichfacesLogger;
-import org.slf4j.Logger;
+
public class UIDataScroller extends UIComponentBase implements DataScrollerSource, IterationStateHolder {
public static final String COMPONENT_TYPE = "org.richfaces.DataScroller";
@@ -34,10 +33,6 @@
public static final String SCROLLER_STATE_ATTRIBUTE = COMPONENT_TYPE + ":page";
- private static final Logger log = RichfacesLogger.COMPONENTS.getLogger();
-
- private Integer page;
-
public static final String FIRST_FACET_NAME = "first";
public static final String LAST_FACET_NAME = "last";
@@ -49,18 +44,27 @@
public static final String FIRST_DISABLED_FACET_NAME = "first_disabled";
public static final String LAST_DISABLED_FACET_NAME = "last_disabled";
-
+ private Integer page;
+
protected enum PropertyKeys {
boundaryControls, data, fastControls, fastStep, forComponent, handleValue, inactiveStyle, selectStyle,
inactiveStyleClass, selectStyleClass, scrollerListener, lastPageMode, maxPages, pageIndexVar, pagesVar, renderIfSinglePage,
style, styleClass, stepControls
}
- protected enum PageMode {
- full, part //part - prev short
+ public enum PageMode {
+ full, part
}
+ public String getLastPageMode() {
+ return (String)getStateHelper().eval(PropertyKeys.lastPageMode);
+ }
+
+ public void setLastPageMode(String lastPageMode) {
+ getStateHelper().put(PropertyKeys.lastPageMode, lastPageMode);
+ }
+
public void addScrollerListener(DataScrollerListener listener) {
addFacesListener(listener);
}
@@ -89,9 +93,13 @@
scrollerListener.invoke(facesContext.getELContext(), new Object[]{event});
}
- facesContext.getPartialViewContext().getRenderIds().add(dataScrollerEvent.getComponent().getClientId(facesContext));
+ UIComponent dataTable = getDataTable();
- UIComponent dataTable = getDataTable();
+ List <UIDataScroller> dataScrollers = DataScrollerUtils.findDataScrollers(dataTable);
+ for(UIDataScroller dataScroller: dataScrollers) {
+ facesContext.getPartialViewContext().getRenderIds().add(dataScroller.getClientId(facesContext));
+ }
+
String dataTableId = dataTable.getClientId(facesContext);
if(dataTable instanceof PartiallyEncodedComponent) {
dataTableId += "@body";
@@ -150,8 +158,7 @@
int newPage = 1;
int pageCount = getPageCount();
-
-
+
if (FIRST_FACET_NAME.equals(facetName)) {
newPage = 1;
} else if (LAST_FACET_NAME.equals(facetName)) {
@@ -182,20 +189,7 @@
}
public int getPageCount(UIComponent data, int rowCount, int rows) {
- int pageCount;
- if (rows > 0) {
- pageCount = rows <= 0 ? 1 : rowCount / rows;
- if (rowCount % rows > 0) {
- pageCount++;
- }
- if (pageCount == 0) {
- pageCount = 1;
- }
- } else {
- rows = 1;
- pageCount = 1;
- }
- return pageCount;
+ return DataScrollerUtils.getPageCount(data, rowCount, rows);
}
/** @return the page count of the uidata */
@@ -204,33 +198,16 @@
}
public int getRowCount(UIComponent data) {
- int rowCount = (Integer)data.getAttributes().get("rowCount");
- if (rowCount >= 0) {
- return rowCount;
- }
-
- return BinarySearch.search(data);
+ return (Integer)data.getAttributes().get("rowCount");
}
/** @return int */
public int getRowCount() {
- //xxx nick -> alex - scrollable models can return -1 here
- //let's implement "dychotomic" discovery
- // setPage(1)... if isPageAvailable() setPage(2) then 4, 8, etc.
- // setPage() { setRowIndex(pageIdx * rows); }
- // isPageAvailable() { return isRowAvailable() }
- //return getUIData().getRowCount();
return getRowCount(getDataTable());
}
public int getRows(UIComponent data) {
- int row = 0;
- row = (Integer)data.getAttributes().get("rows");
- if (row == 0) {
- row = getRowCount(data);
- }
-
- return row;
+ return DataScrollerUtils.getRows(data);
}
// facet getter methods
@@ -265,67 +242,15 @@
return true;
}
-
- public void setupFirstRowValue() {
- UIComponent dataTable = getDataTable();
- if (isRendered()) {
- int rowCount = getRowCount(dataTable);
- int rows = getRows(dataTable);
-
- Integer pageCount = getPageCount(dataTable, rowCount, rows);
-
- int page = getPage();
- int newPage = -1;
- if (page < 1) {
- newPage = 1;
- } else if (page > pageCount) {
- newPage = (pageCount != 0 ? pageCount : 1);
- }
-
- if (newPage != -1) {
- FacesContext facesContext = getFacesContext();
- Object label = MessageUtil.getLabel(facesContext, this);
- String formattedMessage = Messages.getMessage(Messages.DATASCROLLER_PAGE_MISSING,
- new Object[] {label, page, pageCount, newPage});
-
- log.warn(formattedMessage);
-
- page = newPage;
- dataTable.getAttributes().put(dataTable.getClientId(facesContext)+ SCROLLER_STATE_ATTRIBUTE, page);
- }
-
- if (isRendered(dataTable)) {
- int first;
-
- String lastPageMode = (String)getStateHelper().get(PropertyKeys.lastPageMode);
-
- if (lastPageMode == null) {
- lastPageMode = PageMode.part.toString();
- } else if (!PageMode.part.equals(lastPageMode) && !PageMode.full.equals(lastPageMode)) {
- throw new IllegalArgumentException("Illegal value of 'lastPageMode' attribute: '" + lastPageMode + "'");
- }
-
- if (page != pageCount || PageMode.part.equals(lastPageMode)) {
- first = (page - 1) * rows;
- } else {
- first = rowCount - rows;
- if (first < 0) {
- first = 0;
- }
- }
-
- dataTable.getAttributes().put("first", first);
- }
- }
- }
-
+
public void setPage(int newPage) {
this.page = newPage;
}
public int getPage() {
+
UIComponent dataTable = getDataTable();
- Map<String, Object> attributes = getDataTable().getAttributes();
+ Map<String, Object> attributes = dataTable.getAttributes();
FacesContext facesContext = getFacesContext();
Integer state = (Integer) attributes.get(dataTable.getClientId(facesContext)+ SCROLLER_STATE_ATTRIBUTE);
@@ -336,12 +261,12 @@
if (this.page != null) {
return page;
- }
-
+ }
+
ValueExpression ve = getValueExpression("page");
if (ve != null) {
try {
- Integer pageObject = (Integer) ve.getValue(facesContext.getELContext());
+ Integer pageObject = (Integer) ve.getValue(getFacesContext().getELContext());
if (pageObject != null) {
return pageObject;
@@ -413,55 +338,6 @@
}
}
- static class BinarySearch {
-
- public static int search(UIComponent data) {
- int rowIndex = (Integer)data.getAttributes().get("rowIndex");
- try {
- int n = 1;
- int k = 2;
- for (; ;) {
- data.getAttributes().put("rowIndex", k-1);
- if ((Boolean)data.getAttributes().get("rowAvailable")) {
- n = k;
- k = k * 2;
- } else {
- break;
- }
- }
-
- while (n < k) {
- int kk = Math.round((n + k) / 2) + 1;
- data.getAttributes().put("rowIndex", kk-1);
- if ((Boolean)data.getAttributes().get("rowAvailable")) {
- n = kk;
- } else {
- k = kk - 1;
- }
- }
-
- data.getAttributes().put("rowIndex", k-1);
- if ((Boolean)data.getAttributes().get("rowAvailable")) {
- return k;
- } else {
- return 0;
- }
- } finally {
- data.getAttributes().put("rowIndex",rowIndex);
- }
- }
- }
-
- public Object saveState(FacesContext facesContext) {
- return new Object[] { super.saveState(facesContext), page };
- }
-
- public void restoreState(FacesContext facesContext, Object object) {
- Object[] state = (Object[]) object;
- super.restoreState(facesContext, state[0]);
- page = (Integer) state[1];
- }
-
public boolean isLocalPageSet() {
return page != null;
}
@@ -475,28 +351,19 @@
return COMPONENT_FAMILY;
}
- @Override
- public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
- super.processEvent(event);
- }
-
- @Override
- public Object getIterationState() {
- FacesContext facesContext = getFacesContext();
- UIComponent dataTable = getDataTable();
- Integer page = (Integer)dataTable.getAttributes().get(dataTable.getClientId(facesContext) + SCROLLER_STATE_ATTRIBUTE);
- Object [] stateObject = page != null ? new Object[]{page} : null;
- return stateObject;
+ @Override
+ public Object getIterationState(FacesContext context) {
+ return new Object[] {this.page};
}
@Override
- public void setIterationState(Object stateObject) {
- if (stateObject != null) {
- Object[] state = (Object[]) stateObject;
- FacesContext facesContext = getFacesContext();
- UIComponent dataTable = getDataTable();
- dataTable.getAttributes().put(dataTable.getClientId(facesContext) + SCROLLER_STATE_ATTRIBUTE, state[0]);
- }
+ public void setIterationState(FacesContext context, Object state) {
+ if(state != null) {
+ Object [] stateObject = (Object[])state;
+ this.page = (Integer)stateObject[0];
+ } else {
+ this.page = null;
+ }
}
}
14 years, 9 months
JBoss Rich Faces SVN: r16693 - root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-03-31 11:19:29 -0400 (Wed, 31 Mar 2010)
New Revision: 16693
Modified:
root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/HtmlDataScroller.java
Log:
move lastPageMode methods to the UI class
Modified: root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/HtmlDataScroller.java
===================================================================
--- root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/HtmlDataScroller.java 2010-03-31 15:12:11 UTC (rev 16692)
+++ root/ui-sandbox/trunk/components/datascroller/ui/src/main/java/org/richfaces/component/html/HtmlDataScroller.java 2010-03-31 15:19:29 UTC (rev 16693)
@@ -30,10 +30,6 @@
return (String)getStateHelper().eval(PropertyKeys.inactiveStyleClass);
}
- public String getLastPageMode() {
- return (String)getStateHelper().eval(PropertyKeys.lastPageMode);
- }
-
public int getMaxPages() {
return (Integer)getStateHelper().eval(PropertyKeys.maxPages,0);
}
@@ -86,10 +82,6 @@
getStateHelper().put(PropertyKeys.inactiveStyleClass, inactiveStyleClass);
}
- public void setLastPageMode(String lastPageMode) {
- getStateHelper().put(PropertyKeys.inactiveStyle, lastPageMode);
- }
-
public void setMaxPages(int maxPages) {
getStateHelper().put(PropertyKeys.maxPages, maxPages);
}
14 years, 9 months
JBoss Rich Faces SVN: r16692 - root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-03-31 11:12:11 -0400 (Wed, 31 Mar 2010)
New Revision: 16692
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java
Log:
remove iteration state saving methods
Modified: root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java
===================================================================
--- root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2010-03-31 11:56:19 UTC (rev 16691)
+++ root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2010-03-31 15:12:11 UTC (rev 16692)
@@ -29,7 +29,6 @@
import java.util.List;
import java.util.Map;
-import javax.faces.component.StateHelper;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -165,22 +164,4 @@
public void setSortMode(SortMode sortMode) {
getStateHelper().put(PropertyKeys.sortMode, sortMode);
}
-
- @Override
- public Object getIterationState() {
- Object stateObject = super.getIterationState();
- StateHelper stateHelper = getStateHelper();
- return new Object []{stateObject, stateHelper.get(PropertyKeys.first), stateHelper.get(PropertyKeys.rows)};
- }
-
- @Override
- public void setIterationState(Object stateObject) {
- StateHelper stateHelper = getStateHelper();
- if (stateObject != null) {
- Object[] state = (Object[]) stateObject;
- super.setIterationState(state[0]);
- stateHelper.put(PropertyKeys.first, state[1]);
- stateHelper.put(PropertyKeys.rows, state[2]);
- }
- }
}
14 years, 9 months
JBoss Rich Faces SVN: r16691 - in root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces: renderkit and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2010-03-31 07:56:19 -0400 (Wed, 31 Mar 2010)
New Revision: 16691
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIExtendedDataTable.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
Log:
RF-8484
Modified: root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIExtendedDataTable.java
===================================================================
--- root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIExtendedDataTable.java 2010-03-31 11:55:08 UTC (rev 16690)
+++ root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIExtendedDataTable.java 2010-03-31 11:56:19 UTC (rev 16691)
@@ -24,12 +24,16 @@
import java.io.IOException;
import java.util.Collection;
+import java.util.Map;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
+import javax.faces.context.FacesContext;
import javax.faces.render.Renderer;
import org.ajax4jsf.model.DataComponentState;
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.Range;
import org.ajax4jsf.model.RepeatState;
import org.richfaces.renderkit.PartialEncodingRenderer;
@@ -42,6 +46,7 @@
public static final String SCROLL = "scroll";
public static final String SUBMITTED_CLIENT_FIRST = "submittedClientFirst";
+ public static final String OLD_CLIENT_FIRST = "oldClientFirst";
protected enum PropertyKeys {
clientFirst, clientRows
@@ -52,8 +57,10 @@
Collection<String> subComponentIdentifiers)
throws IOException {
if (subComponentIdentifiers.contains(SCROLL)) {
- Integer submittedClientFirst = (Integer) getAttributes().remove(SUBMITTED_CLIENT_FIRST);
+ Map<String, Object> attributes = getAttributes();
+ Integer submittedClientFirst = (Integer) attributes.remove(SUBMITTED_CLIENT_FIRST);
if (submittedClientFirst != null) {
+ attributes.put(OLD_CLIENT_FIRST, getClientFirst());
setClientFirst(submittedClientFirst);
}
}
@@ -61,6 +68,16 @@
((PartialEncodingRenderer) renderer).encodePartially(this, context, callback, subComponentIdentifiers);
}
+ public void partiallyWalk(FacesContext faces, DataVisitor visitor, Range range, Object argument) {
+ Object key = getRowKey();
+ captureOrigValue(faces);
+
+ getExtendedDataModel().walk(faces, visitor, range, argument);
+
+ setRowKey(faces, key);
+ restoreOrigValue(faces);
+ }
+
@Override
protected DataComponentState createComponentState() {
return new RepeatState() {
@@ -71,14 +88,7 @@
@Override
public int getRows() {
- int rows = UIExtendedDataTable.this.getClientRows();
- if (rows > 0) {
- rows = Math.min(rows, UIExtendedDataTable.this.getRows());
- } else {
- rows = UIExtendedDataTable.this.getRows();
- }
-
- return rows;
+ return UIExtendedDataTable.this.getRealClientRows();
}
};
}
@@ -97,6 +107,16 @@
setClientFirst(0);
}
+ public int getRealClientRows() {
+ int rows = getClientRows();
+ if (rows > 0) {
+ rows = Math.min(rows, getRows());
+ } else {
+ rows = getRows();
+ }
+ return rows;
+ }
+
public int getClientRows() {
return (Integer) getStateHelper().eval(PropertyKeys.clientRows, 0);
}
Modified: root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
===================================================================
--- root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2010-03-31 11:55:08 UTC (rev 16690)
+++ root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2010-03-31 11:56:19 UTC (rev 16691)
@@ -28,8 +28,10 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -44,27 +46,57 @@
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSReference;
+import org.ajax4jsf.model.DataVisitResult;
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.SequenceRange;
import org.ajax4jsf.renderkit.AjaxEventOptions;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.UIExtendedDataTable;
import org.richfaces.component.util.HtmlUtil;
-@ResourceDependencies({ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
+@ResourceDependencies({ @ResourceDependency(library = "javax.faces", name = "jsf-uncompressed.js"),
@ResourceDependency(name = "jquery.js"), @ResourceDependency(name = "jquery.position.js"),
@ResourceDependency(name = "richfaces.js"), @ResourceDependency(name = "extendedDataTable.js"),
@ResourceDependency(name = "extendedDataTable.css") })
public class ExtendedDataTableRenderer extends AbstractRowsRenderer implements PartialEncodingRenderer {
- private class RendererState extends RowHolderBase {
+ private static enum PartName {
+ frozen, normal
+ }
+
+ private class Part {
+ private PartName name;
+ private List<UIComponent> columns;
+
+ public Part(PartName name, List<UIComponent> columns) {
+ this.name = name;
+ this.columns = columns;
+ }
+
+ public PartName getName() {
+ return name;
+ }
+ public List<UIComponent> getColumns() {
+ return columns;
+ }
+
+ }
+
+ private class RendererState extends RowHolderBase{
+
private UIExtendedDataTable table;
- private List<UIComponent> frozenColumns;
- private List<UIComponent> columns;
- private boolean frozen;
-
+ private List<Part> parts;
+ private Part current;
+ private Iterator<Part> partIterator;
+
+
+
public RendererState(FacesContext context, UIExtendedDataTable table) {
super(context);
this.table = table;
+ List<UIComponent> frozenColumns;
+ List<UIComponent> columns;
columns = new ArrayList<UIComponent>();
Iterator<UIComponent> iterator = table.columns();
Map<String, UIComponent> columnsMap = new LinkedHashMap<String, UIComponent>();
@@ -88,27 +120,36 @@
int count = Math.min(((Integer) table.getAttributes().get("frozenColumns")).intValue(), columns.size());
frozenColumns = columns.subList(0, count);
columns = columns.subList(count, columns.size());
+ parts = new ArrayList<Part>(PartName.values().length);
+ if (frozenColumns.size() > 0) {
+ parts.add(new Part(PartName.frozen, frozenColumns));
+ }
+ if (columns.size() > 0) {
+ parts.add(new Part(PartName.normal, columns));
+ }
}
public UIExtendedDataTable getRow() {
return table;
}
- public List<UIComponent> getFrozenColumns() {
- return frozenColumns;
+ public void startIterate() {
+ partIterator = parts.iterator();
}
- public List<UIComponent> getColumns() {
- return columns;
+ public Part nextPart() {
+ current = partIterator.next();
+ return current;
}
- public void setFrozen(boolean frozen) {
- this.frozen = frozen;
+ public Part getPart() {
+ return current;
}
+
+ public boolean hasNextPart() {
+ return partIterator.hasNext();
+ }
- public boolean isFrozen() {
- return frozen;
- }
}
@Override
@@ -121,31 +162,89 @@
Collection<String> subComponentIdentifiers) throws IOException {
if (subComponentIdentifiers.size() == 1 && subComponentIdentifiers.contains(UIExtendedDataTable.SCROLL)) {
FacesContext context = visitContext.getFacesContext();
- PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter();
+ final PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter();
UIExtendedDataTable table = (UIExtendedDataTable) component;
- Object key = table.getRowKey();
- table.captureOrigValue(context);
- table.setRowKey(context, null);
- RendererState state = createRowHolder(context, table);
- state.setFrozen(true);
- // TODO 1. Encode fixed children 2. Load necessary rows only
- for (int i = 0; i < 2; i++) { // TODO 1. Replace 2 with constant 2. Empty frozen part shouldn't be rendered
- if (i == 0) {
- writer.startUpdate(table.getClientId(context) + ":ftb");
- } else {
- writer.startUpdate(table.getClientId(context) + ":ntb");
+ int clientFirst = table.getClientFirst();
+ Integer oldClientFirst = (Integer) table.getAttributes().remove(UIExtendedDataTable.OLD_CLIENT_FIRST);
+ if (oldClientFirst == null) {
+ oldClientFirst = clientFirst;
+ }
+ int clientRows = table.getRealClientRows();
+ int difference = clientFirst - oldClientFirst;
+ SequenceRange addRange = null;
+ SequenceRange removeRange = null;
+ if (Math.abs(difference) >= clientRows) {
+ difference = 0;
+ addRange = new SequenceRange(clientFirst, clientRows);
+ removeRange = new SequenceRange(oldClientFirst, clientRows);
+ } else if (difference < 0) {
+ clientFirst += table.getFirst();
+ addRange = new SequenceRange(clientFirst, -difference);
+ removeRange = new SequenceRange(clientFirst + clientRows, -difference);
+ } else if (difference > 0) {
+ oldClientFirst += table.getFirst();
+ removeRange = new SequenceRange(oldClientFirst, difference);
+ int last = oldClientFirst + clientRows;
+ addRange = new SequenceRange(last, difference);
+ }
+ if (addRange != null) {
+ Object key = table.getRowKey();
+ table.captureOrigValue(context);
+ table.setRowKey(context, null);
+ final RendererState state = createRowHolder(context, table);
+ // TODO 1. Encode fixed children
+ for (state.startIterate(); state.hasNextPart();) {
+ char partNameFirstChar = state.nextPart().getName().toString().charAt(0);
+ final List<String> ids = new LinkedList<String>();
+ table.partiallyWalk(context, new DataVisitor() {
+ @Override
+ public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
+ UIExtendedDataTable dataTable = state.getRow();
+ dataTable.setRowKey(context, rowKey);
+ ids.add(dataTable.getClientId(context) + ":"
+ + state.getPart().getName().toString().charAt(0));
+ return DataVisitResult.CONTINUE;
+ }
+ }, removeRange, null);
+ table.partiallyWalk(context, new DataVisitor() {
+ @Override
+ public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
+ UIExtendedDataTable dataTable = state.getRow();
+ dataTable.setRowKey(context, rowKey);
+ HashMap<String, String> attributes = new HashMap<String, String>(1);
+ String id = dataTable.getClientId(context) + ":"
+ + state.getPart().getName().toString().charAt(0);
+ attributes.put("id", id);
+ try {
+ writer.updateAttributes(ids.remove(0), attributes);
+ writer.startUpdate(id);
+ encodeRow(state);
+ writer.endUpdate();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return DataVisitResult.CONTINUE;
+ }
+ }, addRange, null);
+ writer.startEval();
+ if (difference < 0) {
+ difference += clientRows;
+ }
+ writer.write("var richTBody = document.getElementById('" + component.getClientId(context) + ":tb"
+ + partNameFirstChar + "');");
+ writer.write("var richRows = richTBody.rows;");
+ writer.write("for (var i = 0; i < " + difference
+ + "; i++ ) richTBody.appendChild(richTBody.removeChild(richRows[0]));");
+ writer.endEval();
}
- encodeTBody(state, i);
- writer.endUpdate();
- state.setFrozen(false);
+ writer.startEval();
+ writer.write("jQuery('#" + component.getClientId(context).replace(":", "\\\\:")
+ + "').triggerHandler('rich:onscrollcomplete', " + table.getClientFirst() + ");");
+ writer.endEval();
+ table.setRowKey(context, key);
+ table.restoreOrigValue(context);
}
- writer.startEval();
- writer.write("jQuery('#" + component.getClientId(context).replace(":", "\\\\:")
- + "').triggerHandler('rich:onscrollcomplete', " + table.getClientFirst() + ");");
- writer.endEval();
- table.setRowKey(context, key);
- table.restoreOrigValue(context);
-
} else {
throw new IllegalArgumentException("Incorect subComponentIdentifiers: " + subComponentIdentifiers);
}
@@ -303,15 +402,17 @@
writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0", null);
writer.startElement(HTML.TBOBY_ELEMENT, table);
writer.startElement(HTML.TR_ELEMENT, table);
- Iterator<UIComponent> columns = state.getFrozenColumns().iterator();
- for (int i = 0; i < 2; i++) { // TODO Replace 2 with constant
+ for (state.startIterate(); state.hasNextPart();) {
+ Part part = state.nextPart();
+ PartName partName = part.getName();
+ Iterator<UIComponent> columns = part.getColumns().iterator();
if (columns.hasNext()) {
writer.startElement(HTML.TD_ELEM, table);
- if (i == 0 && "footer".equals(name)) {
+ if (PartName.frozen.equals(partName) && "footer".equals(name)) {
writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-extable-footer-align", null);
}
writer.startElement(HTML.DIV_ELEM, table);
- if (i == 0) {
+ if (PartName.frozen.equals(partName)) {
if ("header".equals(name)) {
writer
.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) + ":frozenHeader", null);
@@ -335,7 +436,6 @@
writer.endElement(HTML.DIV_ELEM);
writer.endElement(HTML.TD_ELEM);
}
- columns = state.getColumns().iterator();
}
writer.endElement(HTML.TR_ELEMENT);
writer.endElement(HTML.TBOBY_ELEMENT);
@@ -371,22 +471,25 @@
writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0", null);
writer.startElement(HTML.TBOBY_ELEMENT, table);
writer.startElement(HTML.TR_ELEMENT, table);
- state.setFrozen(true);
- for (int i = 0; i < 2; i++) { // TODO 1. Replace 2 with constant 2. Empty frozen part shouldn't be rendered
+ for (state.startIterate(); state.hasNextPart();) {
writer.startElement(HTML.TD_ELEM, table);
writer.startElement(HTML.DIV_ELEM, table);
- if (i == 1) {
+ PartName partName = state.nextPart().getName();
+ if (PartName.normal.equals(partName)) {
writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) + ":body", null);
writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-extable-part rich-extable-part-width", null);
}
writer.startElement(HTML.TABLE_ELEMENT, table);
writer.writeAttribute(HTML.CELLPADDING_ATTRIBUTE, "0", null);
writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0", null);
- encodeTBody(state, i);
+ writer.startElement(HTML.TBOBY_ELEMENT, table);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) + ":tb"
+ + partName.toString().charAt(0), null);
+ table.walk(context, this, state); // TODO encodeRows(context, table);
+ writer.endElement(HTML.TBOBY_ELEMENT);
writer.endElement(HTML.TABLE_ELEMENT);
writer.endElement(HTML.DIV_ELEM);
writer.endElement(HTML.TD_ELEM);
- state.setFrozen(false);
}
writer.endElement(HTML.TR_ELEMENT);
writer.endElement(HTML.TBOBY_ELEMENT);
@@ -396,20 +499,6 @@
writer.endElement(HTML.DIV_ELEM);
}
- private void encodeTBody(RendererState state, int i) throws IOException {
- FacesContext context = state.getContext();
- ResponseWriter writer = context.getResponseWriter();
- UIExtendedDataTable table = state.getRow();
- writer.startElement(HTML.TBOBY_ELEMENT, table);
- if (i == 0) {
- writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) + ":ftb", null);
- } else {
- writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) + ":ntb", null);
- }
- table.walk(context, this, state); // TODO encodeRows(context, table);
- writer.endElement(HTML.TBOBY_ELEMENT);
- }
-
private void encodeHeaderOrFooterCell(FacesContext context, ResponseWriter writer, UIComponent column,
String facetName) throws IOException {
if (column.isRendered()) {
@@ -450,11 +539,10 @@
UIExtendedDataTable table = state.getRow();
writer.startElement(HTML.TR_ELEMENT, table);
Iterator<UIComponent> columns = null;
- if (state.isFrozen()) {
- columns = state.getFrozenColumns().iterator();
- } else {
- columns = state.getColumns().iterator();
- }
+ Part part = state.getPart();
+ writer.writeAttribute(HTML.ID_ATTRIBUTE,
+ table.getClientId(context) + ":" + part.getName().toString().charAt(0), null);
+ columns = part.getColumns().iterator();
while (columns.hasNext()) {
UIComponent column = (UIComponent) columns.next();
if (column.isRendered()) {
@@ -517,7 +605,8 @@
if (clientFirst != null && clientFirst.length() > 0) {
int value = Integer.parseInt(clientFirst);
component.getAttributes().put(UIExtendedDataTable.SUBMITTED_CLIENT_FIRST, value);
- context.getPartialViewContext().getRenderIds().add(component.getClientId(context) + "@" + UIExtendedDataTable.SCROLL);
+ context.getPartialViewContext().getRenderIds().add(
+ component.getClientId(context) + "@" + UIExtendedDataTable.SCROLL);
}
}
14 years, 9 months