Author: nbelaevski
Date: 2011-04-14 13:54:15 -0400 (Thu, 14 Apr 2011)
New Revision: 22420
Added:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/RF10888.java
trunk/examples/iteration-demo/src/main/webapp/rf10888.xhtml
trunk/ui/common/ui/src/main/java/org/richfaces/component/DataComponentsContextUtil.java
Modified:
trunk/examples/iteration-demo/pom.xml
trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractDataScroller.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/event/DataTablePreRenderListener.java
Log:
https://issues.jboss.org/browse/RF-10888
Modified: trunk/examples/iteration-demo/pom.xml
===================================================================
--- trunk/examples/iteration-demo/pom.xml 2011-04-14 11:53:42 UTC (rev 22419)
+++ trunk/examples/iteration-demo/pom.xml 2011-04-14 17:54:15 UTC (rev 22420)
@@ -84,7 +84,6 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
- <scope>provided</scope>
</dependency>
<dependency>
Added: trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/RF10888.java
===================================================================
--- trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/RF10888.java
(rev 0)
+++ trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/RF10888.java 2011-04-14
17:54:15 UTC (rev 22420)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo;
+
+import java.util.List;
+import java.util.regex.Pattern;
+
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.ManagedProperty;
+import javax.faces.bean.SessionScoped;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.base.Strings;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@ManagedBean(name = "rf10888")
+@SessionScoped
+public class RF10888 {
+
+ private String name;
+
+ private String surname;
+
+ private String email;
+
+ @ManagedProperty(value = "#{persistenceService}")
+ private PersistenceService persistenceService;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getSurname() {
+ return surname;
+ }
+
+ public void setSurname(String surname) {
+ this.surname = surname;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public void setPersistenceService(PersistenceService persistenceService) {
+ this.persistenceService = persistenceService;
+ }
+
+ private Predicate<Person> contains(String value, Function<Person,
CharSequence> accessor) {
+ return
Predicates.compose(Predicates.contains(Pattern.compile(Pattern.quote(value),
Pattern.CASE_INSENSITIVE)), accessor);
+ }
+
+ public Object getFilteredData() {
+ @SuppressWarnings("unchecked")
+ List<Person> resultList = (List<Person>)
persistenceService.getEntityManager().createQuery("SELECT p from Person as
p").getResultList();
+
+ List<Predicate<Person>> predicates = Lists.newArrayList();
+
+ if (!Strings.isNullOrEmpty(name)) {
+ predicates.add(contains(name, new Function<Person, CharSequence>() {
+ public CharSequence apply(Person input) {
+ return input.getName();
+ }
+ }));
+ }
+ if (!Strings.isNullOrEmpty(surname)) {
+ predicates.add(contains(surname, new Function<Person, CharSequence>()
{
+ public CharSequence apply(Person input) {
+ return input.getSurname();
+ }
+ }));
+ }
+ if (!Strings.isNullOrEmpty(email)) {
+ predicates.add(contains(email, new Function<Person, CharSequence>() {
+ public CharSequence apply(Person input) {
+ return input.getEmail();
+ }
+ }));
+ }
+
+ return Lists.newArrayList(Collections2.filter(resultList,
Predicates.and(predicates)));
+ }
+
+}
Added: trunk/examples/iteration-demo/src/main/webapp/rf10888.xhtml
===================================================================
--- trunk/examples/iteration-demo/src/main/webapp/rf10888.xhtml
(rev 0)
+++ trunk/examples/iteration-demo/src/main/webapp/rf10888.xhtml 2011-04-14 17:54:15 UTC
(rev 22420)
@@ -0,0 +1,60 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:it="http://richfaces.org/iteration"
+
xmlns:a4j="http://richfaces.org/a4j">
+<ui:composition>
+ <h:head></h:head>
+ <h:body>
+ <h:form>
+ <h:panelGrid columns="2">
+ Name
+ <h:inputText value="#{rf10888.name}">
+ <f:ajax render="table scroller" event="keyup" />
+ </h:inputText>
+
+ Surname
+ <h:inputText value="#{rf10888.surname}">
+ <f:ajax render="table scroller" event="keyup" />
+ </h:inputText>
+
+ E-mail
+ <h:inputText value="#{rf10888.email}">
+ <f:ajax render="table scroller" event="keyup" />
+ </h:inputText>
+ </h:panelGrid>
+
+ <it:dataScroller id="scroller" for="table" />
+ <h:dataTable value="#{rf10888.filteredData}" id="table"
var="record" rows="20">
+ <h:column>
+ <f:facet name="header">
+ Name
+ </f:facet>
+ #{record.name}
+ </h:column>
+
+ <h:column>
+ <f:facet name="header">
+ Surname
+ </f:facet>
+ #{record.surname}
+ </h:column>
+
+ <h:column>
+ <f:facet name="header">
+ E-mail
+ </f:facet>
+ #{record.email}
+ </h:column>
+
+ <f:facet name="footer">
+ <it:dataScroller />
+ </f:facet>
+ </h:dataTable>
+ </h:form>
+ </h:body>
+</ui:composition>
+</html>
Added:
trunk/ui/common/ui/src/main/java/org/richfaces/component/DataComponentsContextUtil.java
===================================================================
---
trunk/ui/common/ui/src/main/java/org/richfaces/component/DataComponentsContextUtil.java
(rev 0)
+++
trunk/ui/common/ui/src/main/java/org/richfaces/component/DataComponentsContextUtil.java 2011-04-14
17:54:15 UTC (rev 22420)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIData;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class DataComponentsContextUtil {
+
+ private static final String MODEL_RESET_ATTRIBUTE_SUFFIX = "#" +
DataComponentsContextUtil.class.getName();
+
+ private DataComponentsContextUtil() {}
+
+ private static String getAttributeName(FacesContext context, UIComponent component)
{
+ return component.getClientId(context) + MODEL_RESET_ATTRIBUTE_SUFFIX;
+ }
+
+ public static void resetDataModelOncePerPhase(FacesContext context, UIComponent
component) {
+ String attributeName = getAttributeName(context, component);
+ if (context.getCurrentPhaseId() != context.getAttributes().put(attributeName,
context.getCurrentPhaseId())) {
+ resetDataModel(context, component);
+ }
+ }
+
+ private static void resetDataModel(FacesContext context, UIComponent component) {
+ if (component instanceof UIDataAdaptor) {
+ ((UIDataAdaptor) component).resetDataModel();
+ } else if (component instanceof UIData) {
+ //hack to reset cached data model
+ component.setValueExpression("value",
component.getValueExpression("value"));
+ } else {
+ throw new IllegalArgumentException(component.toString());
+ }
+ }
+}
Modified: trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java
===================================================================
--- trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java 2011-04-14
11:53:42 UTC (rev 22419)
+++ trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java 2011-04-14
17:54:15 UTC (rev 22420)
@@ -922,7 +922,7 @@
}
protected void preEncodeBegin(FacesContext context) {
- resetDataModel();
+ DataComponentsContextUtil.resetDataModelOncePerPhase(context, this);
if (!isKeepSaved()) {
//TODO - this also resets state for the nested iteration components - is it
correct?
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractDataScroller.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractDataScroller.java 2011-04-14
11:53:42 UTC (rev 22419)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractDataScroller.java 2011-04-14
17:54:15 UTC (rev 22420)
@@ -37,9 +37,9 @@
import org.ajax4jsf.component.IterationStateHolder;
import org.richfaces.DataScrollerUtils;
+import org.richfaces.application.FacesMessages;
import org.richfaces.application.MessageFactory;
import org.richfaces.application.ServiceTracker;
-import org.richfaces.application.FacesMessages;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.Facet;
import org.richfaces.cdk.annotations.JsfComponent;
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/event/DataTablePreRenderListener.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/event/DataTablePreRenderListener.java 2011-04-14
11:53:42 UTC (rev 22419)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/event/DataTablePreRenderListener.java 2011-04-14
17:54:15 UTC (rev 22420)
@@ -38,10 +38,11 @@
import org.ajax4jsf.Messages;
import org.richfaces.DataScrollerUtils;
import org.richfaces.component.AbstractDataScroller;
+import org.richfaces.component.DataComponentsContextUtil;
import org.richfaces.component.UIDataAdaptor;
import org.richfaces.component.util.MessageUtil;
+import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
-import org.richfaces.log.Logger;
public class DataTablePreRenderListener implements SystemEventListener {
@@ -120,8 +121,10 @@
dataTable = activeDataScroller.getDataTable();
}
- String scrollerStateKey = dataTable.getClientId(facesContext) +
AbstractDataScroller.SCROLLER_STATE_ATTRIBUTE;
if ((activeDataScroller != null) && (dataTable != null)) {
+ DataComponentsContextUtil.resetDataModelOncePerPhase(facesContext,
dataTable);
+
+ String scrollerStateKey = dataTable.getClientId(facesContext) +
AbstractDataScroller.SCROLLER_STATE_ATTRIBUTE;
int rowCount = DataScrollerUtils.getRowCount(dataTable);
int rows = DataScrollerUtils.getRows(dataTable);
int pageCount = DataScrollerUtils.getPageCount(dataTable, rowCount, rows);