Author: lfryc(a)redhat.com
Date: 2011-05-06 08:51:46 -0400 (Fri, 06 May 2011)
New Revision: 22477
Added:
trunk/ui/core/ui/src/test/java/org/richfaces/component/NestedRepeatTest.java
trunk/ui/core/ui/src/test/resources/org/richfaces/component/NestedRepeatTest.xhtml
trunk/ui/core/ui/src/test/resources/org/richfaces/component/faces-config.xml
Modified:
trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java
Log:
fixed UIDataAdaptor - broken resetting childState for nested components (RF-10859)
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-05-06
12:45:22 UTC (rev 22476)
+++ trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java 2011-05-06
12:51:46 UTC (rev 22477)
@@ -52,7 +52,9 @@
*
* @author shura
*/
-@ListenerFor(systemEventClass = PreRenderComponentEvent.class)
+@ListenersFor({ @ListenerFor(systemEventClass = PostAddToViewEvent.class),
+ @ListenerFor(systemEventClass = PostRestoreStateEvent.class),
+ @ListenerFor(systemEventClass = PreRenderViewEvent.class) })
public abstract class UIDataAdaptor extends UIComponentBase implements NamingContainer,
UniqueIdVendor, IterationStateHolder, ComponentSystemEventListener {
@@ -796,7 +798,6 @@
}
pushComponentToEL(faces, this);
- preDecode(faces);
processDecodesChildren(faces);
this.decode(faces);
popComponentFromEL(faces);
@@ -891,17 +892,19 @@
protected void resetChildState() {
getStateHelper().remove(PropertyKeys.childState);
}
+
+ private void resetState() {
+ DataComponentsContextUtil.resetDataModelOncePerPhase(getFacesContext(), this);
- protected void preDecode(FacesContext context) {
- resetDataModel();
-
- Object savedChildState = getStateHelper().get(PropertyKeys.childState);
- // TODO - verify the check for null: savedChildState == null
- if (savedChildState == null || !isKeepSaved()) {
+ if (!isKeepSaved()) {
resetChildState();
}
}
+ protected void preDecode(FacesContext context) {
+ resetState();
+ }
+
// TODO - do we need this method?
protected void preValidate(FacesContext context) {
}
@@ -911,12 +914,7 @@
}
protected void preEncodeBegin(FacesContext context) {
- DataComponentsContextUtil.resetDataModelOncePerPhase(context, this);
-
- if (!isKeepSaved()) {
- //TODO - this also resets state for the nested iteration components - is it
correct?
- resetChildState();
- }
+ resetState();
}
@Override
@@ -1417,12 +1415,21 @@
public abstract void processComponent(FacesContext context, UIComponent c, Object
argument);
}
-
+
@Override
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException
{
super.processEvent(event);
- if (event instanceof PreRenderComponentEvent) {
+ if (event instanceof PostAddToViewEvent) {
+ getFacesContext().getViewRoot().subscribeToEvent(PreRenderViewEvent.class,
this);
+ }
+
+ if (event instanceof PostRestoreStateEvent) {
+ getFacesContext().getViewRoot().subscribeToEvent(PreRenderViewEvent.class,
this);
+ preDecode(getFacesContext());
+ }
+
+ if (event instanceof PreRenderViewEvent) {
preEncodeBegin(getFacesContext());
}
}
Added: trunk/ui/core/ui/src/test/java/org/richfaces/component/NestedRepeatTest.java
===================================================================
--- trunk/ui/core/ui/src/test/java/org/richfaces/component/NestedRepeatTest.java
(rev 0)
+++
trunk/ui/core/ui/src/test/java/org/richfaces/component/NestedRepeatTest.java 2011-05-06
12:51:46 UTC (rev 22477)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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 static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.jboss.test.faces.htmlunit.HtmlUnitEnvironment;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+public class NestedRepeatTest {
+
+ private HtmlUnitEnvironment environment;
+
+ @Before
+ public void setUp() throws Exception {
+ environment = new HtmlUnitEnvironment();
+ environment.withWebRoot(new
File(this.getClass().getResource(".").toURI()));
+ environment.withResource("/WEB-INF/faces-config.xml",
"org/richfaces/component/faces-config.xml");
+ environment.start();
+
+ environment.getServer().getSession().setAttribute("dataBean", new
DataBean());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ environment.release();
+ environment = null;
+ }
+
+ @Test
+ public void testRendering() throws Exception {
+ HtmlPage page = environment.getPage("/NestedRepeatTest.jsf");
+
+
+ for (int i = 0; i < 3; i++) {
+ HtmlElement input = page.getElementById("form:outer:" + i +
":inner:0:input");
+ input.type(Integer.toString(i));
+ }
+
+ HtmlElement ajax = page.getElementById("form:ajax");
+ page = ajax.click();
+
+ for (int i = 0; i < 3; i++) {
+ HtmlElement input = page.getElementById("form:outer:" + i +
":inner:0:input");
+ assertEquals(Integer.toString(i), input.getAttribute("value"));
+ }
+ }
+
+ public static class DataBean implements Serializable {
+
+ private List<DataItem> listDataItems = new LinkedList<DataItem>() {
+ {
+ add(new DataItem());
+ add(new DataItem());
+ add(new DataItem());
+ }
+ };
+
+ public List<DataItem> getListDataItems() {
+ return listDataItems;
+ }
+
+ public void setListDataItems(List<DataItem> listDataItems) {
+ this.listDataItems = listDataItems;
+ }
+ }
+
+ public static class DataItem implements Serializable {
+ private List<Inner> list = new LinkedList<Inner>() {
+ {
+ add(new Inner());
+ }
+ };
+
+ public List<Inner> getList() {
+ return list;
+ }
+
+ public void setList(List<Inner> list) {
+ this.list = list;
+ }
+
+ }
+
+ public static class Inner implements Serializable {
+ private String status;
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+ }
+
+}
Added: trunk/ui/core/ui/src/test/resources/org/richfaces/component/NestedRepeatTest.xhtml
===================================================================
--- trunk/ui/core/ui/src/test/resources/org/richfaces/component/NestedRepeatTest.xhtml
(rev 0)
+++
trunk/ui/core/ui/src/test/resources/org/richfaces/component/NestedRepeatTest.xhtml 2011-05-06
12:51:46 UTC (rev 22477)
@@ -0,0 +1,31 @@
+<!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:a4j="http://richfaces.org/a4j">
+<f:view contentType="text/html" />
+
+<h:head>
+ <title>Richfaces Calendar</title>
+</h:head>
+
+<h:body>
+ <h:form id="form">
+ <h:messages/>
+
+
+ <a4j:repeat id="outer" value="#{dataBean.listDataItems}"
var="item">
+ <a4j:repeat id="inner" value="#{item.list}"
var="inner">
+ <h:inputText id="input" value="#{inner.status}" />
+ </a4j:repeat>
+ <br/>
+ </a4j:repeat>
+
+ <h:commandLink id="regular" value="Regular submit" />
+ <br/>
+ <a4j:commandLink id="ajax" value="Ajax submit"
render="form" />
+
+ </h:form>
+</h:body>
+</html>
Added: trunk/ui/core/ui/src/test/resources/org/richfaces/component/faces-config.xml
===================================================================
--- trunk/ui/core/ui/src/test/resources/org/richfaces/component/faces-config.xml
(rev 0)
+++
trunk/ui/core/ui/src/test/resources/org/richfaces/component/faces-config.xml 2011-05-06
12:51:46 UTC (rev 22477)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+ version="2.0">
+
+</faces-config>
\ No newline at end of file