Author: nbelaevski
Date: 2009-12-29 11:53:57 -0500 (Tue, 29 Dec 2009)
New Revision: 16221
Added:
root/framework/trunk/impl/src/test/java/org/richfaces/component/DataAdaptorTestCase.java
root/framework/trunk/impl/src/test/java/org/richfaces/component/MockDataAdaptor.java
root/framework/trunk/impl/src/test/java/org/richfaces/component/MockDataAdaptorComponentState.java
Modified:
root/framework/trunk/api/src/main/java/org/ajax4jsf/model/SequenceDataModel.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java
root/framework/trunk/test-base/
Log:
Fixes & refactoring for:
- UIDataAdaptor and related code
- PartialViewContextImpl
JUnit tests for UIDataAdaptor
Modified:
root/framework/trunk/api/src/main/java/org/ajax4jsf/model/SequenceDataModel.java
===================================================================
---
root/framework/trunk/api/src/main/java/org/ajax4jsf/model/SequenceDataModel.java 2009-12-29
16:52:35 UTC (rev 16220)
+++
root/framework/trunk/api/src/main/java/org/ajax4jsf/model/SequenceDataModel.java 2009-12-29
16:53:57 UTC (rev 16221)
@@ -30,13 +30,14 @@
* @author shura
*
*/
-public class SequenceDataModel extends ExtendedDataModel {
- private DataModel wrappedModel;
+public class SequenceDataModel<E> extends ExtendedDataModel<E> {
+
+ private DataModel<E> wrappedModel;
/**
* @param wrapped
*/
- public SequenceDataModel(DataModel wrapped) {
+ public SequenceDataModel(DataModel<E> wrapped) {
super();
this.wrappedModel = wrapped;
}
@@ -160,7 +161,7 @@
* (non-Javadoc)
* @see javax.faces.model.DataModel#getRowData()
*/
- public Object getRowData() {
+ public E getRowData() {
// TODO Auto-generated method stub
return wrappedModel.getRowData();
@@ -215,14 +216,14 @@
/**
* @return the wrappedModel
*/
- protected DataModel getWrappedModel() {
+ protected DataModel<E> getWrappedModel() {
return this.wrappedModel;
}
/**
* @param wrappedModel the wrappedModel to set
*/
- protected void setWrappedModel(DataModel wrappedModel) {
+ protected void setWrappedModel(DataModel<E> wrappedModel) {
this.wrappedModel = wrappedModel;
}
}
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java 2009-12-29
16:52:35 UTC (rev 16220)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/HandlersChain.java 2009-12-29
16:53:57 UTC (rev 16221)
@@ -116,17 +116,17 @@
addInlineHandlerAsValue(context, (String)
component.getAttributes().get(attributeName));
}
- public void addBehaviors(FacesContext context, String evantName) {
- addBehaviors(context, evantName, null);
+ public void addBehaviors(FacesContext context, String domEventName) {
+ addBehaviors(context, domEventName, null);
}
- public void addBehaviors(FacesContext context, String evantName, String
defaultEventName) {
- String name = evantName;
- List<ClientBehavior> behaviorsList = getBehaviorsList(evantName);
+ public void addBehaviors(FacesContext context, String domEventName, String
logicalEventName) {
+ String name = domEventName;
+ List<ClientBehavior> behaviorsList = getBehaviorsList(domEventName);
- if ((behaviorsList == null) && (defaultEventName != null)) {
- behaviorsList = getBehaviorsList(defaultEventName);
- name = defaultEventName;
+ if ((behaviorsList == null) && (logicalEventName != null)) {
+ behaviorsList = getBehaviorsList(logicalEventName);
+ name = logicalEventName;
}
if (behaviorsList == null) {
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java 2009-12-29
16:52:35 UTC (rev 16220)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java 2009-12-29
16:53:57 UTC (rev 16221)
@@ -22,16 +22,15 @@
package org.richfaces.component;
-import org.ajax4jsf.component.AjaxDataEncoder;
-import org.ajax4jsf.component.IterationStateHolder;
-import org.ajax4jsf.model.DataComponentState;
-import org.ajax4jsf.model.DataVisitResult;
-import org.ajax4jsf.model.DataVisitor;
-import org.ajax4jsf.model.ExtendedDataModel;
-import org.ajax4jsf.model.Range;
-import org.ajax4jsf.model.SerializableDataModel;
-import org.richfaces.log.RichfacesLogger;
-import org.slf4j.Logger;
+import java.io.IOException;
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
import javax.el.ValueExpression;
import javax.faces.FacesException;
@@ -58,16 +57,18 @@
import javax.faces.event.BehaviorEvent;
import javax.faces.event.FacesEvent;
import javax.faces.render.Renderer;
-import java.io.IOException;
-import java.io.Serializable;
-import java.text.MessageFormat;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
+import org.ajax4jsf.component.AjaxDataEncoder;
+import org.ajax4jsf.component.IterationStateHolder;
+import org.ajax4jsf.model.DataComponentState;
+import org.ajax4jsf.model.DataVisitResult;
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.SerializableDataModel;
+import org.richfaces.log.RichfacesLogger;
+import org.slf4j.Logger;
+
/**
* Base class for iterable components, like dataTable, Tomahawk dataList,
* Facelets repeat, tree etc., with support for partial rendering on AJAX
@@ -505,7 +506,7 @@
getStateHelper().put(PropertyKeys.stateVar, stateVar);
}
- // TODO - review and probably remove
+ //XXX - review and probably remove - useful method, should be left
public int getRowCount() {
return getExtendedDataModel().getRowCount();
}
@@ -631,6 +632,7 @@
// Store converter for a invokeOnComponents call.
if (null != rowKeyConverter) {
+ //TODO - review
setRowKeyConverter(rowKeyConverter);
}
}
@@ -1005,6 +1007,7 @@
// Call for a child component - try to detect row key
// baseId.length() + 1 expression skips SEPARATOR_CHAR
+ //TODO - convertKeyString
String rowKeyString = extractKeySegment(context,
clientId.substring(baseId.length() + 1));
if (rowKeyString != null) {
@@ -1012,6 +1015,7 @@
if (null != keyConverter) {
try {
+ //TODO: review
newRowKey = keyConverter.getAsObject(context, this,
rowKeyString);
} catch (ConverterException e) {
@@ -1050,28 +1054,6 @@
return found;
}
- // Performs pre-phase initialization before visiting children
- // (if necessary).
- // TODO - do we need this?
- private void preVisitChildren(VisitContext visitContext) {
-
-// // If EXECUTE_LIFECYCLE hint is set, we need to do
-// // lifecycle-related initialization before visiting children
-// if (visitContext.getHints().contains(VisitHint.EXECUTE_LIFECYCLE)) {
-// FacesContext facesContext = visitContext.getFacesContext();
-// PhaseId phaseId = facesContext.getCurrentPhaseId();
-//
-// if (phaseId == PhaseId.APPLY_REQUEST_VALUES)
-// preDecode(facesContext);
-// else if (phaseId == PhaseId.PROCESS_VALIDATIONS)
-// preValidate(facesContext);
-// else if (phaseId == PhaseId.UPDATE_MODEL_VALUES)
-// preUpdate(facesContext);
-// else if (phaseId == PhaseId.RENDER_RESPONSE)
-// preEncode(facesContext);
-// }
- }
-
// Tests whether we need to visit our children as part of
// a tree visit
private boolean doVisitChildren(VisitContext context) {
@@ -1200,6 +1182,7 @@
* @param substring
* @return
*/
+ //TODO review!
protected String extractKeySegment(FacesContext context, String substring) {
return null;
}
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java 2009-12-29
16:52:35 UTC (rev 16220)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java 2009-12-29
16:53:57 UTC (rev 16221)
@@ -204,7 +204,8 @@
try {
processComponents(viewRoot, phaseId, ids, facesContext);
} catch (Exception e) {
- // RELEASE_PENDING LOG EXCEPTION
+ //TODO log exception
+ e.printStackTrace();
}
// If we have just finished APPLY_REQUEST_VALUES phase, install the
@@ -250,6 +251,7 @@
writer.endDocument();
} catch (IOException ex) {
+ ex.printStackTrace();
//TODO - review?
this.cleanupAfterView();
} catch (RuntimeException ex) {
Added:
root/framework/trunk/impl/src/test/java/org/richfaces/component/DataAdaptorTestCase.java
===================================================================
---
root/framework/trunk/impl/src/test/java/org/richfaces/component/DataAdaptorTestCase.java
(rev 0)
+++
root/framework/trunk/impl/src/test/java/org/richfaces/component/DataAdaptorTestCase.java 2009-12-29
16:53:57 UTC (rev 16221)
@@ -0,0 +1,503 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, 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 java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.component.ContextCallback;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UINamingContainer;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.component.html.HtmlOutputText;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitHint;
+import javax.faces.component.visit.VisitResult;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.PhaseId;
+import javax.faces.event.ValueChangeEvent;
+import javax.faces.event.ValueChangeListener;
+import javax.faces.model.ListDataModel;
+
+import org.ajax4jsf.component.IterationStateHolder;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.SequenceDataModel;
+import org.jboss.test.faces.AbstractFacesTest;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class DataAdaptorTestCase extends AbstractFacesTest {
+
+ private static final String VAR_NAME = "item";
+
+ private static class TestCallback {
+
+ private int value;
+
+ public void handle() {
+
+ }
+
+ public void reset() {
+ value = 0;
+ }
+
+ public int getAndIncrement() {
+ return value++;
+ }
+
+ public int get() {
+ return value;
+ }
+ }
+
+ private MockDataAdaptor mockDataAdaptor;
+
+ private List<String> data;
+
+ private ExtendedDataModel<String> createDataModel() {
+ return new SequenceDataModel<String>(new ListDataModel<String>(new
ArrayList<String>(data)));
+ }
+
+ private Object getVarValue() {
+ return facesContext.getApplication().evaluateExpressionGet(facesContext,
+ MessageFormat.format("#'{'{0}'}'", VAR_NAME),
Object.class);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ data = Arrays.asList("a", "b", "c",
"d");
+
+ setupFacesRequest();
+
+ mockDataAdaptor = new MockDataAdaptor();
+ mockDataAdaptor.setDataModel(createDataModel());
+ mockDataAdaptor.setVar(VAR_NAME);
+
+ facesContext.getViewRoot().getChildren().add(mockDataAdaptor);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ data = null;
+ mockDataAdaptor = null;
+ }
+
+ private void resetCallbacks(TestCallback... callbacks) {
+ for (TestCallback callback : callbacks) {
+ callback.reset();
+ assertEquals(0, callback.get());
+ }
+ }
+
+ private UIComponent createCallbackComponent(final TestCallback callback) throws
Exception {
+ return new HtmlOutputText() {
+
+ private void notifyCallbacks() {
+ callback.handle();
+ }
+
+ @Override
+ public void processDecodes(FacesContext context) {
+ super.processDecodes(context);
+ notifyCallbacks();
+ }
+
+ @Override
+ public void processValidators(FacesContext context) {
+ super.processValidators(context);
+ notifyCallbacks();
+ }
+
+ @Override
+ public void processUpdates(FacesContext context) {
+ super.processUpdates(context);
+ notifyCallbacks();
+ }
+ };
+ }
+
+ public void testProcessChildren() throws Exception {
+
+ TestCallback childCallback = new TestCallback() {
+ @Override
+ public void handle() {
+ assertEquals(getVarValue(), data.get(getAndIncrement()));
+ }
+ };
+ UIComponent child = createCallbackComponent(childCallback);
+ child.setId("child");
+
+ TestCallback facetCallback = new TestCallback() {
+ @Override
+ public void handle() {
+ assertEquals(getVarValue(), data.get(getAndIncrement()));
+ }
+ };
+ UIComponent facet = createCallbackComponent(facetCallback);
+ child.getFacets().put("f", facet);
+ facet.setId("facet");
+
+ TestCallback immediateFacetCallback = new TestCallback() {
+ @Override
+ public void handle() {
+ getAndIncrement();
+ assertNull(getVarValue());
+ }
+ };
+ UIComponent immediateFacet = createCallbackComponent(immediateFacetCallback);
+ immediateFacet.setId("immediateFacet");
+
+ mockDataAdaptor.getChildren().add(child);
+ mockDataAdaptor.getFacets().put("facet", immediateFacet);
+
+ mockDataAdaptor.processDecodes(facesContext);
+
+ assertEquals(data.size(), facetCallback.get());
+ assertEquals(data.size(), childCallback.get());
+ assertEquals(1, immediateFacetCallback.get());
+
+ resetCallbacks(childCallback, facetCallback, immediateFacetCallback);
+
+ mockDataAdaptor.processValidators(facesContext);
+
+ assertEquals(data.size(), facetCallback.get());
+ assertEquals(data.size(), childCallback.get());
+ assertEquals(1, immediateFacetCallback.get());
+
+ resetCallbacks(childCallback, facetCallback, immediateFacetCallback);
+
+ mockDataAdaptor.processUpdates(facesContext);
+
+ assertEquals(data.size(), facetCallback.get());
+ assertEquals(data.size(), childCallback.get());
+ assertEquals(1, immediateFacetCallback.get());
+
+ resetCallbacks(childCallback, facetCallback, immediateFacetCallback);
+ }
+
+ public void testSaveRestoreChildrenState() throws Exception {
+ HtmlForm form = new HtmlForm();
+ HtmlInputText input = new HtmlInputText();
+ IterationStateHolderComponent stateHolder = new IterationStateHolderComponent();
+
+ List<UIComponent> children = mockDataAdaptor.getChildren();
+ children.add(form);
+ form.getChildren().add(input);
+ form.getFacets().put("facet", stateHolder);
+
+ mockDataAdaptor.setRowKey(Integer.valueOf(0));
+
+ assertFalse(form.isSubmitted());
+ assertNull(input.getSubmittedValue());
+ assertNull(input.getLocalValue());
+ assertTrue(input.isValid());
+ assertFalse(input.isLocalValueSet());
+ assertNull(stateHolder.getIterationState());
+
+ form.setSubmitted(true);
+ input.setSubmittedValue("user input");
+ input.setValue("component value");
+ input.setValid(false);
+ input.setLocalValueSet(true);
+ stateHolder.setIterationState("state");
+
+ mockDataAdaptor.setRowKey(Integer.valueOf(1));
+
+ assertFalse(form.isSubmitted());
+ assertNull(input.getSubmittedValue());
+ assertNull(input.getLocalValue());
+ assertTrue(input.isValid());
+ assertFalse(input.isLocalValueSet());
+ assertNull(stateHolder.getIterationState());
+
+ input.setSubmittedValue("another input from user");
+ input.setValue("123");
+ assertTrue(input.isLocalValueSet());
+ stateHolder.setIterationState("456");
+
+ mockDataAdaptor.setRowKey(Integer.valueOf(0));
+ assertTrue(form.isSubmitted());
+ assertEquals("user input", input.getSubmittedValue());
+ assertEquals("component value", input.getLocalValue());
+ assertFalse(input.isValid());
+ assertTrue(input.isLocalValueSet());
+ assertEquals("state", stateHolder.getIterationState());
+
+ mockDataAdaptor.setRowKey(Integer.valueOf(1));
+ assertFalse(form.isSubmitted());
+ assertEquals("another input from user", input.getSubmittedValue());
+ assertEquals("123", input.getLocalValue());
+ assertTrue(input.isValid());
+ assertTrue(input.isLocalValueSet());
+ assertEquals("456", stateHolder.getIterationState());
+
+ mockDataAdaptor.setRowKey(null);
+ assertFalse(form.isSubmitted());
+ assertNull(input.getSubmittedValue());
+ assertNull(input.getLocalValue());
+ assertTrue(input.isValid());
+ assertFalse(input.isLocalValueSet());
+ assertNull(stateHolder.getIterationState());
+ }
+
+ public void testSaveRestoreChildrenStateNestedDataAdaptors() throws Exception {
+ MockDataAdaptor childAdaptor = new MockDataAdaptor();
+ childAdaptor.setDataModel(createDataModel());
+
+ HtmlInputText input = new HtmlInputText();
+
+ mockDataAdaptor.getChildren().add(childAdaptor);
+ childAdaptor.getChildren().add(input);
+
+ Integer rowKey = Integer.valueOf(2);
+ Integer childKey = Integer.valueOf(1);
+
+ mockDataAdaptor.setRowKey(rowKey);
+ childAdaptor.setRowKey(childKey);
+
+ assertNull(input.getSubmittedValue());
+ assertNull(input.getLocalValue());
+ assertTrue(input.isValid());
+ assertFalse(input.isLocalValueSet());
+
+ input.setSubmittedValue("submittedValue");
+ input.setValue("value");
+
+ childAdaptor.setRowKey(null);
+ mockDataAdaptor.setRowKey(Integer.valueOf(3));
+ childAdaptor.setRowKey(Integer.valueOf(0));
+
+ assertNull(input.getSubmittedValue());
+ assertNull(input.getLocalValue());
+ assertFalse(input.isLocalValueSet());
+
+ childAdaptor.setRowKey(null);
+ mockDataAdaptor.setRowKey(rowKey);
+ childAdaptor.setRowKey(childKey);
+
+ assertEquals("submittedValue", input.getSubmittedValue());
+ assertEquals("value", input.getLocalValue());
+ assertTrue(input.isValid());
+ assertTrue(input.isLocalValueSet());
+ }
+
+ public void testEventsQueueing() throws Exception {
+ HtmlInputText input = new HtmlInputText();
+
+ final TestCallback testCallback = new TestCallback();
+ input.addValueChangeListener(new ValueChangeListener() {
+
+ public void processValueChange(ValueChangeEvent event) throws
AbortProcessingException {
+ testCallback.getAndIncrement();
+ assertEquals(data.get(1), getVarValue());
+ }
+ });
+
+ mockDataAdaptor.getChildren().add(input);
+ mockDataAdaptor.setRowKey(Integer.valueOf(1));
+ assertEquals(data.get(1), getVarValue());
+
+ new ValueChangeEvent(input, null, "testValue").queue();
+ mockDataAdaptor.setRowKey(null);
+
+ facesContext.getViewRoot().broadcastEvents(facesContext,
PhaseId.PROCESS_VALIDATIONS);
+ assertEquals(1, testCallback.get());
+ }
+
+ public void testInvokeOnComponent() throws Exception {
+ final HtmlInputText facet = new HtmlInputText();
+ final HtmlInputText child = new HtmlInputText();
+
+ mockDataAdaptor.getFacets().put("facet", facet);
+ mockDataAdaptor.getChildren().add(child);
+
+ mockDataAdaptor.setId("_data");
+ facet.setId("_facet");
+ child.setId("_child");
+
+ boolean invocationResult;
+ final TestCallback callback = new TestCallback();
+ invocationResult = mockDataAdaptor.invokeOnComponent(facesContext,
"_data", new ContextCallback() {
+
+ public void invokeContextCallback(FacesContext context, UIComponent target)
{
+ callback.getAndIncrement();
+ assertEquals(mockDataAdaptor, target);
+ assertEquals("_data", target.getClientId());
+ }
+ });
+
+ assertTrue(invocationResult);
+ assertEquals(1, callback.get());
+ callback.reset();
+
+ final char separatorChar = UINamingContainer.getSeparatorChar(facesContext);
+ invocationResult = mockDataAdaptor.invokeOnComponent(facesContext,
"_data" + separatorChar + "_facet",
+ new ContextCallback() {
+
+ public void invokeContextCallback(FacesContext context, UIComponent
target) {
+ callback.getAndIncrement();
+ assertEquals(facet, target);
+ assertEquals("_data" + separatorChar + "_facet",
target.getClientId());
+ }
+ });
+
+ assertTrue(invocationResult);
+ assertEquals(1, callback.get());
+ callback.reset();
+
+ invocationResult = mockDataAdaptor.invokeOnComponent(facesContext,
"_data" + separatorChar + "2"
+ + separatorChar + "_child", new ContextCallback() {
+
+ public void invokeContextCallback(FacesContext context, UIComponent target)
{
+ callback.getAndIncrement();
+ assertEquals(child, target);
+ assertEquals(data.get(2), getVarValue());
+ assertEquals("_data" + separatorChar + "2" +
separatorChar + "_child", target.getClientId());
+ }
+ });
+
+ assertTrue(invocationResult);
+ assertEquals(1, callback.get());
+ callback.reset();
+
+ invocationResult = mockDataAdaptor.invokeOnComponent(facesContext,
"_data" + separatorChar + "100"
+ + separatorChar + "_child", new ContextCallback() {
+
+ public void invokeContextCallback(FacesContext context, UIComponent target)
{
+ fail();
+ }
+ });
+ assertFalse(invocationResult);
+
+ invocationResult = mockDataAdaptor.invokeOnComponent(facesContext,
"_data" + separatorChar
+ + "nonExistentComponent", new ContextCallback() {
+
+ public void invokeContextCallback(FacesContext context, UIComponent target)
{
+ fail();
+ }
+ });
+ assertFalse(invocationResult);
+ }
+
+ public void testVisitChildren() throws Exception {
+ final HtmlInputText facet = new HtmlInputText();
+ final HtmlInputText child = new HtmlInputText();
+
+ mockDataAdaptor.getFacets().put("facet", facet);
+ mockDataAdaptor.getChildren().add(child);
+
+ mockDataAdaptor.setId("_data");
+ facet.setId("_facet");
+ child.setId("_child");
+
+ VisitContext fullVisitContext = VisitContext.createVisitContext(facesContext);
+
+ final char separatorChar = UINamingContainer.getSeparatorChar(facesContext);
+ final Set<String> idsToVisit = new HashSet<String>();
+ idsToVisit.add("_data" + separatorChar + "_facet");
+ idsToVisit.add("_data" + separatorChar + "0" + separatorChar
+ "_child");
+ idsToVisit.add("_data" + separatorChar + "2" + separatorChar
+ "_child");
+
+ VisitContext partialVisitContext = VisitContext.createVisitContext(facesContext,
idsToVisit, EnumSet
+ .of(VisitHint.SKIP_UNRENDERED));
+
+ final TestCallback callback = new TestCallback();
+ mockDataAdaptor.visitTree(fullVisitContext, new VisitCallback() {
+
+ public VisitResult visit(VisitContext context, UIComponent target) {
+ callback.getAndIncrement();
+ assertNotNull(target);
+
+ return VisitResult.ACCEPT;
+ }
+ });
+
+ assertEquals(1 /* adaptor itself */+ 1 /* facet */+ data.size(),
callback.get());
+
+ callback.reset();
+
+ mockDataAdaptor.visitTree(partialVisitContext, new VisitCallback() {
+
+ public VisitResult visit(VisitContext context, UIComponent target) {
+ callback.getAndIncrement();
+ assertNotNull(target);
+ assertTrue(idsToVisit.contains(target.getClientId()));
+ return VisitResult.ACCEPT;
+ }
+ });
+
+ assertEquals(idsToVisit.size(), callback.get());
+
+ callback.reset();
+
+ mockDataAdaptor.visitTree(fullVisitContext, new VisitCallback() {
+
+ public VisitResult visit(VisitContext context, UIComponent target) {
+ callback.getAndIncrement();
+
+ if (child.equals(target)
+ && child.getClientId().equals("_data" +
separatorChar + "1" + separatorChar + "_child")) {
+ return VisitResult.COMPLETE;
+ }
+
+ return VisitResult.ACCEPT;
+ }
+ });
+
+ assertEquals(1 /* data adaptor */+ 1 /* facet */+ 2 /* [0..1] children */,
callback.get());
+ }
+}
+
+class IterationStateHolderComponent extends UIComponentBase implements
IterationStateHolder {
+
+ private Object iterationState;
+
+ @Override
+ public String getFamily() {
+ return "test.Component";
+ }
+
+ public Object getIterationState() {
+ return iterationState;
+ }
+
+ public void setIterationState(Object state) {
+ iterationState = state;
+ }
+
+}
Added:
root/framework/trunk/impl/src/test/java/org/richfaces/component/MockDataAdaptor.java
===================================================================
--- root/framework/trunk/impl/src/test/java/org/richfaces/component/MockDataAdaptor.java
(rev 0)
+++
root/framework/trunk/impl/src/test/java/org/richfaces/component/MockDataAdaptor.java 2009-12-29
16:53:57 UTC (rev 16221)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.UINamingContainer;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+import org.ajax4jsf.model.DataComponentState;
+import org.ajax4jsf.model.ExtendedDataModel;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class MockDataAdaptor extends UIDataAdaptor {
+
+ private ExtendedDataModel<?> dataModel;
+
+ @Override
+ protected DataComponentState createComponentState() {
+ return new MockDataAdaptorComponentState();
+ }
+
+ @Override
+ protected ExtendedDataModel<?> createExtendedDataModel() {
+ return dataModel;
+ }
+
+ public ExtendedDataModel<?> getDataModel() {
+ return dataModel;
+ }
+
+ public void setDataModel(ExtendedDataModel<?> dataModel) {
+ this.dataModel = dataModel;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.UIDataAdaptor#getRowKeyConverter()
+ */
+ @Override
+ public Converter getRowKeyConverter() {
+ // TODO Auto-generated method stub
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ return facesContext.getApplication().createConverter(Integer.class);
+ }
+
+ @Override
+ protected String extractKeySegment(FacesContext context, String substring) {
+ char separatorChar = UINamingContainer.getSeparatorChar(context);
+ int separatorIdx = substring.indexOf(separatorChar);
+ if (separatorIdx >= 0) {
+ return substring.substring(0, separatorIdx);
+ } else {
+ return substring;
+ }
+ }
+}
Added:
root/framework/trunk/impl/src/test/java/org/richfaces/component/MockDataAdaptorComponentState.java
===================================================================
---
root/framework/trunk/impl/src/test/java/org/richfaces/component/MockDataAdaptorComponentState.java
(rev 0)
+++
root/framework/trunk/impl/src/test/java/org/richfaces/component/MockDataAdaptorComponentState.java 2009-12-29
16:53:57 UTC (rev 16221)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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 org.ajax4jsf.model.DataComponentState;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.SequenceRange;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class MockDataAdaptorComponentState implements DataComponentState {
+
+ private Range range = new SequenceRange(0, -1);
+
+ public Range getRange() {
+ return range;
+ }
+}
Property changes on: root/framework/trunk/test-base
___________________________________________________________________
Name: svn:ignore
- target
.settings
.project
.classpath
.clover
+ target
.settings
.project
.classpath
.clover
bin