Author: nbelaevski
Date: 2010-08-31 13:20:11 -0400 (Tue, 31 Aug 2010)
New Revision: 19052
Added:
branches/RF-7560/ui/common/api/src/main/java/org/richfaces/component/SequenceIterationStatus.java
branches/RF-7560/ui/common/api/src/main/java/org/richfaces/renderkit/
branches/RF-7560/ui/common/api/src/main/java/org/richfaces/renderkit/util/
branches/RF-7560/ui/common/api/src/main/java/org/richfaces/renderkit/util/EnclosingFormRequiredException.java
branches/RF-7560/ui/common/api/src/test/java/org/
branches/RF-7560/ui/common/api/src/test/java/org/richfaces/
branches/RF-7560/ui/common/api/src/test/java/org/richfaces/component/
branches/RF-7560/ui/common/api/src/test/java/org/richfaces/component/SequenceIterationStatusTest.java
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/RowKeyContextEventWrapper.java
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/SavedState.java
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/UISequence.java
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxChildrenRenderer.java
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxComponentRendererBase.java
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/ComponentAttribute.java
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/RendererBase.java
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/SequenceRendererHelper.java
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/view/facelets/EmptyHandler.java
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/view/facelets/RowKeyConverterRule.java
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/component/
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/component/DataAdaptorTestCase.java
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/component/MockDataAdaptor.java
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/component/MockDataAdaptorComponentState.java
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/MockClientBehaviorHolder.java
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java
branches/RF-7560/ui/input/ui/src/main/java/org/richfaces/renderkit/InputRendererBase.java
Removed:
branches/RF-7560/core/commons/src/main/java/org/richfaces/renderkit/ComponentAttribute.java
branches/RF-7560/core/commons/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/MockClientBehaviorHolder.java
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/exception/
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxComponentRendererBase.java
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/ComponentRendererBase.java
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/ComponentVariables.java
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/ComponentsVariableResolver.java
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/resource/cached/
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/util/style/
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/CacheContent.java
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/PollEventsManager.java
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/AjaxActionsRule.java
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/EmptyHandler.java
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/RowKeyConverterRule.java
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/package-info.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/EnclosingFormRequiredException.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/RowKeyContextEventWrapper.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/SavedState.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/SequenceIterationStatus.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/UISequence.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/CompositeRenderer.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/InputRendererBase.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/MacroDefinitionJSContentHandler.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/RendererContributor.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/SequenceRendererHelper.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/webapp/taglib/SimpleComponentTag.java
branches/RF-7560/core/impl/src/main/java/org/richfaces/webapp/taglib/UIComponentELTagBase.java
branches/RF-7560/core/impl/src/main/javacc/
branches/RF-7560/core/impl/src/test/java/org/ajax4jsf/resource/cached/
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/DataAdaptorTestCase.java
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/MockDataAdaptor.java
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/MockDataAdaptorComponentState.java
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/SequenceIterationStatusTest.java
branches/RF-7560/core/impl/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java
branches/RF-7560/core/impl/src/test/java/org/richfaces/renderkit/TemplateEncoderRendererBaseTest.java
branches/RF-7560/core/impl/src/test/java/org/richfaces/renderkit/TemplateUtilTest.java
Modified:
branches/RF-7560/core/impl/pom.xml
branches/RF-7560/core/impl/src/test/java/org/richfaces/context/AjaxTableComponentImpl.java
branches/RF-7560/core/impl/src/test/java/org/richfaces/context/ExtendedPartialVisitContextTest.java
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/util/FormUtil.java
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/util/FormUtilTest.java
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/LogRendererBase.java
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxOutputPanelRenderer.java
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/MediaOutputRenderer.java
branches/RF-7560/ui/iteration/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java
branches/RF-7560/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
branches/RF-7560/ui/iteration/ui/src/main/java/org/richfaces/renderkit/SubTableToggleControlRendererBase.java
branches/RF-7560/ui/output/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java
branches/RF-7560/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelBaseRenderer.java
branches/RF-7560/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java
Log:
RF-7560
Deleted:
branches/RF-7560/core/commons/src/main/java/org/richfaces/renderkit/ComponentAttribute.java
===================================================================
---
branches/RF-7560/core/commons/src/main/java/org/richfaces/renderkit/ComponentAttribute.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/commons/src/main/java/org/richfaces/renderkit/ComponentAttribute.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,142 +0,0 @@
-/*
- * 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.renderkit;
-
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * @author Nick Belaevski
- */
-public class ComponentAttribute implements Comparable<ComponentAttribute> {
-
- public enum Kind {
- BOOL,
- GENERIC,
- URI
- }
-
- private final String htmlAttributeName;
-
- private String componentAttributeName;
-
- private Object defaultValue;
-
- private String[] eventNames = {};
-
- private Kind kind = Kind.GENERIC;
-
- //TODO handling for aliases: "styleClass" -> "class"
-
- public ComponentAttribute(String htmlAttributeName) {
- super();
- this.htmlAttributeName = htmlAttributeName;
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @return the defaultValue
- */
- public Object getDefaultValue() {
- return this.defaultValue;
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param defaultValue the defaultValue to set
- */
- public void setDefaultValue(Object dafaultValue) {
- this.defaultValue = dafaultValue;
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @return the kind
- */
- public Kind getKind() {
- return this.kind;
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param kind the kind to set
- */
- public void setKind(Kind kind) {
- this.kind = kind;
- }
-
- public static final Map<String, ComponentAttribute>
createMap(ComponentAttribute... attributes) {
- Map<String,ComponentAttribute> result = new TreeMap<String,
ComponentAttribute>();
-
- for (ComponentAttribute componentAttribute : attributes) {
- result.put(componentAttribute.getComponentAttributeName(),
componentAttribute);
- }
-
- return result;
- }
-
- /**
- * @return the name
- */
- public String getHtmlAttributeName() {
- return htmlAttributeName;
- }
-
- /**
- * @return the componentAttributeName
- */
- public String getComponentAttributeName() {
- return (componentAttributeName == null) ? htmlAttributeName :
componentAttributeName;
- }
-
- /**
- * @param componentAttributeName the componentAttributeName to set
- * @return
- */
- public ComponentAttribute setComponentAttributeName(String componentAttributeName) {
- this.componentAttributeName = componentAttributeName;
-
- return this;
- }
-
- /**
- * @return the eventNames
- */
- public String[] getEventNames() {
- return eventNames;
- }
-
- /**
- * @param eventNames the eventNames to set
- * @return
- */
- public ComponentAttribute setEventNames(String... eventNames) {
- this.eventNames = eventNames;
-
- return this;
- }
-
- public int compareTo(ComponentAttribute o) {
- return getHtmlAttributeName().compareTo(o.getHtmlAttributeName());
- }
-}
Deleted:
branches/RF-7560/core/commons/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
===================================================================
---
branches/RF-7560/core/commons/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/commons/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,468 +0,0 @@
-/*
- * 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.renderkit;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIComponentBase;
-import javax.faces.component.behavior.ClientBehavior;
-import javax.faces.component.behavior.ClientBehaviorContext;
-import javax.faces.component.behavior.ClientBehaviorHint;
-import javax.faces.component.behavior.ClientBehaviorHolder;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
-import org.richfaces.renderkit.ComponentAttribute.Kind;
-
-/**
- * @author Nick Belaevski
- *
- */
-public final class RenderKitUtils {
-
- /**
- *
- */
- static final String BEHAVIOR_SOURCE_ID = "javax.faces.source";
-
- /**
- *
- */
- static final String BEHAVIOR_EVENT_NAME = "javax.faces.behavior.event";
-
- /**
- *
- */
- private static final String XHTML_ATTRIBUTE_PREFIX = "xml:";
-
- /**
- *
- */
- private static final String XHTML_CONTENT_TYPE = "application/xhtml+xml";
-
- // TODO - check what's in MyFaces
- private static final String ATTRIBUTES_THAT_ARE_SET = UIComponentBase.class.getName()
+ ".attributesThatAreSet";
-
- private static final String[] BOOLEAN_ATTRIBUTE_NAMES = { "checked",
"compact", "declare", "defer", "disabled",
- "ismap", "multiple", "nohref", "noshade",
"nowrap", "readonly", "selected" };
-
- private static final String[] URI_ATTRIBUTE_NAMES = { "action",
"background", "cite", "classid", "codebase",
- "data", "href", "longdesc", "profile",
"src", "usemap" };
-
- private static final String[] XHTML_ATTRIBUTE_NAMES = { "lang" };
-
- private static final String DISABLED_ATTRIBUTE_NAME = "disabled";
-
- private RenderKitUtils() {
- // utility constructor
- }
-
- private static Map<String, List<ClientBehavior>>
getClientBehaviorsMap(UIComponent component) {
- Map<String, List<ClientBehavior>> result;
- if (component instanceof ClientBehaviorHolder) {
- ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder)
component;
-
- result = clientBehaviorHolder.getClientBehaviors();
- } else {
- result = Collections.emptyMap();
- }
- return result;
- }
-
- static boolean isDisabled(UIComponent component) {
- Object disabledAttributeValue =
component.getAttributes().get(DISABLED_ATTRIBUTE_NAME);
- if (disabledAttributeValue == null) {
- return false;
- }
-
- if (disabledAttributeValue instanceof Boolean) {
- return Boolean.TRUE.equals(disabledAttributeValue);
- }
-
- return Boolean.valueOf(disabledAttributeValue.toString());
- }
-
- static String escape(String s) {
- StringBuilder sb = new StringBuilder(s.length());
- int start = 0;
- int end;
-
- while ((end = s.indexOf('\'', start)) >= 0) {
- sb.append(s, start, end);
- sb.append("\\'");
-
- start = end + 1;
- }
-
- sb.append(s, start, s.length());
-
- return sb.toString();
- }
-
- static boolean chain(StringBuilder sb, Object object, boolean isChained) {
- if (object != null) {
- String objectString = object.toString().trim();
- if (objectString.length() != 0) {
- final boolean localIsChained;
-
- if (!isChained && sb.length() != 0) {
- // extract previously stored handler
- String previousHandlerString = sb.toString();
- // clear builder object
- sb.setLength(0);
-
- // append escaped handler
- sb.append("'");
- sb.append(escape(previousHandlerString));
- sb.append("'");
-
- localIsChained = true;
- } else {
- // use passed in value of chained indicator
- localIsChained = isChained;
- }
-
- if (localIsChained) {
- sb.append(",'");
- sb.append(escape(objectString));
- sb.append("'");
-
- return true;
- } else {
- sb.append(objectString);
- return false;
- }
- }
- }
-
- // no changes, pass chained indicator we initially used
- return isChained;
- }
-
- private static Object createBehaviorsChain(Object inlineHandlerValue,
ClientBehaviorContext behaviorContext,
- List<ClientBehavior> behaviors) {
-
- boolean isChained = false;
- StringBuilder result = new StringBuilder();
-
- isChained = chain(result, inlineHandlerValue, isChained);
- for (ClientBehavior behavior : behaviors) {
- isChained = chain(result, behavior.getScript(behaviorContext), isChained);
-
- if (behavior.getHints().contains(ClientBehaviorHint.SUBMITTING)) {
- break;
- }
- }
-
- if (result.length() == 0) {
- return null;
- }
-
- if (isChained) {
- result.insert(0, "jsf.util.chain(");
- result.append(")");
- }
-
- return result.toString();
- }
-
- public static boolean shouldRenderAttribute(Object attributeValue) {
- if (attributeValue == null) {
- return false;
- } else if (attributeValue instanceof String) {
- return ((String) attributeValue).length() > 0;
- } else if (attributeValue instanceof Boolean &&
Boolean.FALSE.equals(attributeValue)) {
- return false;
- } else if (attributeValue instanceof Integer && (Integer) attributeValue
== Integer.MIN_VALUE) {
- return false;
- } else if (attributeValue instanceof Double && (Double) attributeValue ==
Double.MIN_VALUE) {
- return false;
- } else if (attributeValue instanceof Character && (Character)
attributeValue == Character.MIN_VALUE) {
- return false;
- } else if (attributeValue instanceof Float && (Float) attributeValue ==
Float.MIN_VALUE) {
- return false;
- } else if (attributeValue instanceof Short && (Short) attributeValue ==
Short.MIN_VALUE) {
- return false;
- } else if (attributeValue instanceof Byte && (Byte) attributeValue ==
Byte.MIN_VALUE) {
- return false;
- } else if (attributeValue instanceof Long && (Long) attributeValue ==
Long.MIN_VALUE) {
- return false;
- }
-
- return attributeValue.toString().length() > 0;
- }
-
- public static String prefixAttributeName(String attributeName, boolean isXhtmlMode)
{
- if (isXhtmlMode) {
- if (Arrays.binarySearch(XHTML_ATTRIBUTE_NAMES, attributeName) >= 0) {
- return XHTML_ATTRIBUTE_PREFIX + attributeName;
- }
- }
-
- return attributeName;
- }
-
- public static String prefixAttributeName(String attributeName, ResponseWriter
responseWriter) {
- return prefixAttributeName(attributeName,
XHTML_CONTENT_TYPE.equals(responseWriter.getContentType()));
- }
-
- public static void renderAttribute(FacesContext facesContext, String attributeName,
Object attributeValue)
- throws IOException {
-
- if (!shouldRenderAttribute(attributeValue)) {
- return;
- }
-
- ResponseWriter writer = facesContext.getResponseWriter();
-
- String prefixedAttributeName = prefixAttributeName(attributeName, writer);
-
- if (Arrays.binarySearch(URI_ATTRIBUTE_NAMES, attributeName) >= 0) {
- writer.writeURIAttribute(prefixedAttributeName, attributeValue, null);
- } else if (Arrays.binarySearch(BOOLEAN_ATTRIBUTE_NAMES, attributeName) >= 0)
{
- boolean booleanAttributeValue =
Boolean.valueOf(String.valueOf(attributeValue));
- if (booleanAttributeValue) {
- // TODO - is passing in Boolean.TRUE value documented somewhere?
- writer.writeAttribute(prefixedAttributeName, Boolean.TRUE, null);
- }
- } else {
- writer.writeAttribute(prefixedAttributeName, attributeValue, null);
- }
- }
-
- public static Object getAttributeAndBehaviorsValue(FacesContext facesContext,
UIComponent component,
- ComponentAttribute componentAttribute) {
- if (facesContext == null) {
- throw new NullPointerException("facesContext");
- }
-
- if (component == null) {
- throw new NullPointerException("component");
- }
-
- if (componentAttribute == null) {
- throw new NullPointerException("componentAttribute");
- }
-
- String componentAttributeName = componentAttribute.getComponentAttributeName();
- Object attributeValue = component.getAttributes().get(componentAttributeName);
-
- String[] eventNames = componentAttribute.getEventNames();
- if (eventNames.length > 0) {
- Map<String, List<ClientBehavior>> behaviorsMap =
getClientBehaviorsMap(component);
- if (behaviorsMap.size() > 0) {
- for (String eventName : eventNames) {
- if (behaviorsMap.containsKey(eventName)) {
- List<ClientBehavior> behaviorsList =
behaviorsMap.get(eventName);
- if (!behaviorsList.isEmpty()) {
- // TODO - parameters handling
- ClientBehaviorContext behaviorContext =
-
ClientBehaviorContext.createClientBehaviorContext(facesContext, component, eventName,
- null, null);
- attributeValue = createBehaviorsChain(attributeValue,
behaviorContext, behaviorsList);
- }
- break;
- }
- }
- }
- }
- return attributeValue;
- }
-
- public static void renderAttributeAndBehaviors(FacesContext facesContext, UIComponent
component,
- ComponentAttribute componentAttribute) throws IOException {
- Object attributeValue = getAttributeAndBehaviorsValue(facesContext, component,
componentAttribute);
- renderAttribute(facesContext, componentAttribute.getHtmlAttributeName(),
attributeValue);
- }
-
- public static void renderPassThroughAttributesOptimized(FacesContext context,
UIComponent component,
- Map<String, ComponentAttribute> knownAttributesMap) throws IOException {
-
- boolean disabled = isDisabled(component);
- Set<String> handledAttributes = new
HashSet<String>(knownAttributesMap.size());
- Object attributesThatAreSetObject =
component.getAttributes().get(ATTRIBUTES_THAT_ARE_SET);
- if (attributesThatAreSetObject instanceof Collection<?>) {
- Collection<?> attributesThatAreSet = (Collection<?>)
attributesThatAreSetObject;
- for (Object attributeNameObject : attributesThatAreSet) {
- if (attributeNameObject == null) {
- continue;
- }
-
- String attributeName = attributeNameObject.toString();
-
- ComponentAttribute knownAttribute =
knownAttributesMap.get(attributeName);
- if (knownAttribute != null) {
- handledAttributes.add(knownAttribute.getHtmlAttributeName());
-
- if (disabled && knownAttribute.getEventNames() != null) {
- continue;
- }
-
- renderAttributeAndBehaviors(context, component, knownAttribute);
- }
- }
-
- // render attributes that haven't been processed yet - there can be
behaviors
- for (ComponentAttribute knownAttribute : knownAttributesMap.values()) {
-
- if (handledAttributes.contains(knownAttribute.getHtmlAttributeName())) {
- continue;
- }
-
- renderAttributeAndBehaviors(context, component, knownAttribute);
- }
- } else {
- // switch to unoptimized mode
- renderPassThroughAttributes(context, component, knownAttributesMap);
- }
- }
-
- public static void renderPassThroughAttributes(FacesContext context, UIComponent
component,
- Map<String, ComponentAttribute> knownAttributesMap) throws IOException {
- Collection<ComponentAttribute> attributes = knownAttributesMap.values();
-
- renderPassThroughAttributes(context, component, attributes);
- }
-
- public static void renderPassThroughAttributes(FacesContext context, UIComponent
component, Collection<ComponentAttribute> attributes)
- throws IOException {
- boolean disabled = isDisabled(component);
- for (ComponentAttribute knownAttribute : attributes) {
- if (!disabled || knownAttribute.getEventNames().length == 0) {
- renderAttributeAndBehaviors(context, component, knownAttribute);
- }
- }
- }
-
- public static String decodeBehaviors(FacesContext context, UIComponent component) {
- if (!(component instanceof ClientBehaviorHolder)) {
- return null;
- }
-
- ClientBehaviorHolder holder = (ClientBehaviorHolder) component;
- Map<String, List<ClientBehavior>> behaviors =
holder.getClientBehaviors();
-
- if (behaviors == null || behaviors.isEmpty()) {
- return null;
- }
-
- ExternalContext externalContext = context.getExternalContext();
- Map<String, String> parametersMap =
externalContext.getRequestParameterMap();
- String behaviorEvent = parametersMap.get(BEHAVIOR_EVENT_NAME);
-
- if (behaviorEvent == null) {
- return null;
- }
-
- List<ClientBehavior> behaviorsForEvent = behaviors.get(behaviorEvent);
- String behaviorSource = parametersMap.get(BEHAVIOR_SOURCE_ID);
- String clientId = component.getClientId(context);
-
- if (behaviorSource != null && behaviorSource.equals(clientId)) {
- if (behaviorsForEvent != null && !behaviorsForEvent.isEmpty()) {
- for (ClientBehavior behavior : behaviorsForEvent) {
- behavior.decode(context, component);
- }
-
- return behaviorEvent;
- }
- }
-
- return null;
- }
-
- public static Attributes attributes() {
- return new Attributes();
- }
-
- public static Attributes attributes(Enum<?> ... attrs) {
- Attributes res = new Attributes();
- for (Enum<?> attr : attrs) {
- res.generic(attr.toString(), attr.toString());
- }
-
- return res;
- }
-
- public static Attributes attributes(String ... attrs) {
- Attributes res = new Attributes();
- for (String attr : attrs) {
- res.generic(attr, attr);
- }
-
- return res;
- }
-
- @SuppressWarnings("serial")
- public static final class Attributes extends TreeSet<ComponentAttribute> {
-
- private ComponentAttribute last;
-
- public void render(FacesContext context, UIComponent component) throws
IOException {
- renderPassThroughAttributes(context, component, this);
- }
-
- public Attributes generic(String name, String componentAttribute, String...
events) {
- ComponentAttribute attribute = createAttribute(name, componentAttribute);
- attribute.setEventNames(events);
- attribute.setKind(Kind.GENERIC);
- return this;
- }
-
- private ComponentAttribute createAttribute(String name, String
componentAttribute) {
- ComponentAttribute attribute = new ComponentAttribute(name);
- attribute.setComponentAttributeName(componentAttribute);
- add(attribute);
- last = attribute;
- return attribute;
- }
-
- public Attributes uri(String name, String componentAttribute) {
- ComponentAttribute attribute = createAttribute(name, componentAttribute);
- attribute.setKind(Kind.URI);
- return this;
- }
-
- public Attributes bool(String name, String componentAttribute) {
- ComponentAttribute attribute = createAttribute(name, componentAttribute);
- attribute.setKind(Kind.BOOL);
- return this;
- }
-
- public Attributes defaultValue(Object value){
- last.setDefaultValue(value);
- return this;
- }
-
- }
-
-}
Deleted:
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/MockClientBehaviorHolder.java
===================================================================
---
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/MockClientBehaviorHolder.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/MockClientBehaviorHolder.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,58 +0,0 @@
-/*
- * 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.renderkit;
-
-import static org.jboss.test.faces.mock.FacesMockController.invokeCurrent;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.component.behavior.ClientBehavior;
-import javax.faces.component.behavior.ClientBehaviorHolder;
-
-import org.easymock.IMocksControl;
-import org.jboss.test.faces.mock.component.MockUIComponent;
-
-public class MockClientBehaviorHolder extends MockUIComponent implements
ClientBehaviorHolder {
-
- public MockClientBehaviorHolder(IMocksControl control, String name) {
- super(control, name);
- }
-
- public void addClientBehavior(String eventName, ClientBehavior behavior) {
- invokeCurrent(this, eventName, behavior);
- }
-
- public Map<String, List<ClientBehavior>> getClientBehaviors() {
- return invokeCurrent(this);
- }
-
- public String getDefaultEventName() {
- return invokeCurrent(this);
- }
-
- public Collection<String> getEventNames() {
- return invokeCurrent(this);
- }
-
-}
Deleted:
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java
===================================================================
---
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,377 +0,0 @@
-/*
- * 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.renderkit;
-
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.same;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.Arrays;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.behavior.ClientBehavior;
-import javax.faces.component.behavior.ClientBehaviorContext;
-import javax.faces.component.behavior.ClientBehaviorHint;
-import javax.faces.component.behavior.ClientBehaviorHolder;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
-import org.easymock.EasyMock;
-import org.jboss.test.faces.mock.MockFacesEnvironment;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class RenderKitUtilsMocksTest {
-
- /**
- *
- */
- private static final String CLIENT_ID = "submittedId";
-
- private MockFacesEnvironment facesEnvironment;
-
- private ResponseWriter responseWriter;
-
- private FacesContext facesContext;
-
- private ExternalContext externalContext;
-
- private Map<String, Object> componentAttributes;
-
- private Map<String, List<ClientBehavior>> behaviorsMap;
-
- private Map<String, ComponentAttribute> knownAttributes;
-
- @Before
- public void setUp() throws Exception {
- facesEnvironment =
MockFacesEnvironment.createEnvironment().withExternalContext();
-
- facesContext = facesEnvironment.getFacesContext();
- externalContext = facesEnvironment.getExternalContext();
-
- responseWriter = facesEnvironment.createMock(ResponseWriter.class);
- expect(facesContext.getResponseWriter()).andStubReturn(responseWriter);
-
expect(responseWriter.getContentType()).andStubReturn("application/xhtml+xml");
-
- componentAttributes = new HashMap<String, Object>();
- behaviorsMap = new HashMap<String, List<ClientBehavior>>();
- knownAttributes = new TreeMap<String, ComponentAttribute>();
- }
-
- @After
- public void tearDown() throws Exception {
- this.facesEnvironment.verify();
- this.facesEnvironment.release();
-
- this.facesEnvironment = null;
- this.responseWriter = null;
- this.facesContext = null;
- this.externalContext = null;
- this.componentAttributes = null;
- this.behaviorsMap = null;
- this.knownAttributes = null;
- }
-
- private UIComponent createMockComponent() {
- UIComponent component = facesEnvironment.createMock(UIComponent.class);
- expect(component.getAttributes()).andStubReturn(componentAttributes);
- expect(component.getClientId(same(facesContext))).andStubReturn(CLIENT_ID);
- return component;
- }
-
- private ClientBehaviorHolder createMockClientBehaviorHolder() {
- UIComponent component =
facesEnvironment.createMock(MockClientBehaviorHolder.class);
- expect(component.getClientId(same(facesContext))).andStubReturn(CLIENT_ID);
- expect(component.getAttributes()).andStubReturn(componentAttributes);
- ClientBehaviorHolder behaviorHolder = (ClientBehaviorHolder) component;
- expect(behaviorHolder.getClientBehaviors()).andStubReturn(behaviorsMap);
- expect(behaviorHolder.getEventNames()).andStubReturn(
- Arrays.asList("click", "action", "mousemove",
"keypress", "blur", "contextmenu"));
- return behaviorHolder;
- }
-
- @Test
- public void testRenderPassThroughAttributes() throws Exception {
- knownAttributes.put("disabled", new
ComponentAttribute("disabled"));
- knownAttributes.put("checked", new
ComponentAttribute("checked"));
- knownAttributes.put("style", new
ComponentAttribute("style"));
- knownAttributes.put("src", new ComponentAttribute("src"));
- knownAttributes.put("lang", new ComponentAttribute("lang"));
- knownAttributes.put("class", new
ComponentAttribute("class").setComponentAttributeName("styleClass"));
-
- componentAttributes.put("disabled", Boolean.TRUE);
- componentAttributes.put("checked", Boolean.FALSE);
- componentAttributes.put("style", "color:red");
- componentAttributes.put("src", "urn:abc");
- componentAttributes.put("facelets.Mark", 123);
- componentAttributes.put("lang", "ru");
- componentAttributes.put("styleClass", "rich-component");
-
- UIComponent component = createMockComponent();
-
- responseWriter.writeAttribute(eq("disabled"), eq(Boolean.TRUE),
EasyMock.<String>isNull());
- // checked attribute shouldn't be rendered - it's 'false'
- responseWriter.writeAttribute(eq("style"), eq("color:red"),
EasyMock.<String>isNull());
- responseWriter.writeURIAttribute(eq("src"), eq("urn:abc"),
EasyMock.<String>isNull());
- // facelets.Mark shouldn't be rendered - it's unknown
- responseWriter.writeAttribute(eq("xml:lang"), eq("ru"),
EasyMock.<String>isNull());
- responseWriter.writeAttribute(eq("class"),
eq("rich-component"), EasyMock.<String>isNull());
-
- facesEnvironment.replay();
-
- RenderKitUtils.renderPassThroughAttributes(facesContext, component,
knownAttributes);
- }
-
- private ClientBehavior createClientBehavior(String handlerData,
Set<ClientBehaviorHint> hints) {
- ClientBehavior behavior = facesEnvironment.createMock(ClientBehavior.class);
- expect(behavior.getScript(EasyMock.<ClientBehaviorContext>
notNull())).andStubReturn(
- MessageFormat.format("prompt({0})", handlerData));
-
- expect(behavior.getHints()).andStubReturn(hints);
- return behavior;
- }
-
- @Test
- public void testBehaviors() throws Exception {
- knownAttributes.put("onclick", new
ComponentAttribute("onclick")
- .setEventNames(new String[] { "click", "action" }));
- knownAttributes.put("onmousemove", new
ComponentAttribute("onmousemove")
- .setEventNames(new String[] { "mousemove" }));
- knownAttributes.put("onkeypress", new
ComponentAttribute("onkeypress")
- .setEventNames(new String[] { "keypress" }));
- knownAttributes.put("oncontextmenu", new
ComponentAttribute("oncontextmenu")
- .setEventNames(new String[] { "contextmenu" }));
-
- componentAttributes.put("onkeypress", "alert(keypress)");
- componentAttributes.put("onmousemove", "alert(mousemove)");
- componentAttributes.put("onclick", "alert(click)");
-
- Set<ClientBehaviorHint> emptyHintsSet =
EnumSet.noneOf(ClientBehaviorHint.class);
- Set<ClientBehaviorHint> submittingHintsSet =
EnumSet.of(ClientBehaviorHint.SUBMITTING);
-
- ClientBehavior keypressBehavior = createClientBehavior("keypress",
emptyHintsSet);
- ClientBehavior actionBehavior1 = createClientBehavior("action1",
emptyHintsSet);
- ClientBehavior actionBehavior2 = createClientBehavior("action2",
submittingHintsSet);
- ClientBehavior actionBehavior3 = createClientBehavior("action3",
emptyHintsSet);
- ClientBehavior contextmenuBehavior =
createClientBehavior("contextmenu", emptyHintsSet);
-
- behaviorsMap.put("keypress", Arrays.asList(keypressBehavior));
- behaviorsMap.put("action", Arrays.asList(actionBehavior1,
actionBehavior2, actionBehavior3));
- behaviorsMap.put("contextmenu", Arrays.asList(contextmenuBehavior));
-
- ClientBehaviorHolder behaviorHolder = createMockClientBehaviorHolder();
- UIComponent component = (UIComponent) behaviorHolder;
-
- responseWriter.writeAttribute(eq("onkeypress"),
eq("jsf.util.chain('alert(keypress)','prompt(keypress)')"),
- EasyMock.<String>isNull());
- responseWriter.writeAttribute(eq("onclick"),
-
eq("jsf.util.chain('alert(click)','prompt(action1)','prompt(action2)')"),
EasyMock.<String>isNull());
- responseWriter.writeAttribute(eq("onmousemove"),
eq("alert(mousemove)"), EasyMock.<String>isNull());
- responseWriter.writeAttribute(eq("oncontextmenu"),
eq("prompt(contextmenu)"), EasyMock.<String>isNull());
-
- facesEnvironment.replay();
-
- RenderKitUtils.renderPassThroughAttributes(facesContext, component,
knownAttributes);
- }
-
- private UIComponent setupBehaviorsTestForDisabledComponent() throws IOException {
- knownAttributes.put("style", new
ComponentAttribute("style"));
- knownAttributes.put("onclick", new
ComponentAttribute("onclick")
- .setEventNames(new String[] { "click", "action" }));
- knownAttributes.put("onmousemove", new
ComponentAttribute("onmousemove")
- .setEventNames(new String[] { "mousemove" }));
-
- componentAttributes.put("onmousemove", "alert(mousemove)");
- componentAttributes.put("onclick", "alert(click)");
- componentAttributes.put("style", "color:green");
-
- Set<ClientBehaviorHint> emptyHintsSet =
EnumSet.noneOf(ClientBehaviorHint.class);
-
- ClientBehavior actionBehavior1 = createClientBehavior("action1",
emptyHintsSet);
- behaviorsMap.put("action", Arrays.asList(actionBehavior1));
-
- ClientBehaviorHolder behaviorHolder = createMockClientBehaviorHolder();
- UIComponent component = (UIComponent) behaviorHolder;
- return component;
- }
-
- @Test
- public void testBehaviorsForDisabledComponent() throws Exception {
- componentAttributes.put("disabled", Boolean.TRUE);
- UIComponent component = setupBehaviorsTestForDisabledComponent();
-
- responseWriter.writeAttribute(eq("style"), eq("color:green"),
EasyMock.<String>isNull());
-
- facesEnvironment.replay();
-
- RenderKitUtils.renderPassThroughAttributes(facesContext, component,
knownAttributes);
- }
-
- @Test
- public void testBehaviorsForNonDisabledComponent() throws Exception {
- componentAttributes.put("disabled", Boolean.FALSE);
- UIComponent component = setupBehaviorsTestForDisabledComponent();
-
- responseWriter.writeAttribute(eq("onclick"),
eq("jsf.util.chain('alert(click)','prompt(action1)')"),
- EasyMock.<String>isNull());
- responseWriter.writeAttribute(eq("onmousemove"),
- eq("alert(mousemove)"), EasyMock.<String>isNull());
- responseWriter.writeAttribute(eq("style"), eq("color:green"),
EasyMock.<String>isNull());
-
- facesEnvironment.replay();
-
- RenderKitUtils.renderPassThroughAttributes(facesContext, component,
knownAttributes);
- }
-
- public void checkDisabled(Object attributeValue, boolean expectedValue) throws
Exception {
- componentAttributes.put("disabled", attributeValue);
-
- UIComponent component = createMockComponent();
- facesEnvironment.replay();
- assertTrue(expectedValue == RenderKitUtils.isDisabled(component));
- }
-
- @Test
- public void testIsDisabled() throws Exception {
- checkDisabled(Boolean.TRUE, true);
- }
-
- @Test
- public void testIsDisabledString() throws Exception {
- checkDisabled("true", true);
- }
-
- @Test
- public void testIsNonDisabled() throws Exception {
- checkDisabled(Boolean.FALSE, false);
- }
-
- @Test
- public void testIsNonDisabledString() throws Exception {
- checkDisabled("false", false);
- }
-
- @Test
- public void testIsNonDisabledNull() throws Exception {
- checkDisabled(null, false);
- }
-
- private UIComponent setupTestDecodeBehaviors(String behaviorSourceId, String
behaviorEventName) throws Exception {
- ClientBehaviorHolder behaviorHolder = createMockClientBehaviorHolder();
- UIComponent component = (UIComponent) behaviorHolder;
-
- Map<String, String> requestParameterMap = new HashMap<String,
String>();
- requestParameterMap.put(RenderKitUtils.BEHAVIOR_SOURCE_ID, behaviorSourceId);
- requestParameterMap.put(RenderKitUtils.BEHAVIOR_EVENT_NAME, behaviorEventName);
-
expect(externalContext.getRequestParameterMap()).andStubReturn(requestParameterMap);
-
- ClientBehavior actionBehavior = createClientBehavior("action1",
EnumSet.of(ClientBehaviorHint.SUBMITTING));
- ClientBehavior actionBehavior1 = createClientBehavior("action2",
EnumSet.of(ClientBehaviorHint.SUBMITTING));
- behaviorsMap.put("action", Arrays.asList(actionBehavior,
actionBehavior1));
-
- ClientBehavior blurBehavior = createClientBehavior("blur1",
EnumSet.of(ClientBehaviorHint.SUBMITTING));
- behaviorsMap.put("blur", Arrays.asList(blurBehavior));
-
- return component;
- }
-
- @Test
- public void testDecodeActionBehaviors() throws Exception {
- UIComponent component = setupTestDecodeBehaviors(CLIENT_ID, "action");
-
- List<ClientBehavior> behaviors = behaviorsMap.get("action");
- for (ClientBehavior clientBehavior : behaviors) {
- clientBehavior.decode(same(facesContext), same(component));
- expectLastCall();
- }
-
- facesEnvironment.replay();
-
- assertEquals("action", RenderKitUtils.decodeBehaviors(facesContext,
component));
- }
-
- @Test
- public void testDecodeBlurBehaviors() throws Exception {
- UIComponent component = setupTestDecodeBehaviors(CLIENT_ID, "blur");
-
- List<ClientBehavior> behaviors = behaviorsMap.get("blur");
- for (ClientBehavior clientBehavior : behaviors) {
- clientBehavior.decode(same(facesContext), same(component));
- expectLastCall();
- }
-
- facesEnvironment.replay();
-
- assertEquals("blur", RenderKitUtils.decodeBehaviors(facesContext,
component));
- }
-
- @Test
- public void testDecodeNonMatchingClientId() throws Exception {
- UIComponent component = setupTestDecodeBehaviors("wrongId",
"action");
-
- //nothing should be called - clientId is not matched
-
- facesEnvironment.replay();
-
- assertNull(RenderKitUtils.decodeBehaviors(facesContext, component));
- }
-
- @Test
- public void testDecodeNoSubmittedBehavior() throws Exception {
- UIComponent component = setupTestDecodeBehaviors(CLIENT_ID, null);
-
- //nothing should be called - no behavior event information was submitted
-
- facesEnvironment.replay();
-
- assertNull(RenderKitUtils.decodeBehaviors(facesContext, component));
- }
-
- @Test
- public void testDecodeContextMenuBehaviors() throws Exception {
- UIComponent component = setupTestDecodeBehaviors(CLIENT_ID,
"contextmenu");
-
- //nothing should be called - no context menu behaviors were created
-
- facesEnvironment.replay();
-
- assertNull(RenderKitUtils.decodeBehaviors(facesContext, component));
- }
-}
\ No newline at end of file
Deleted:
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java
===================================================================
---
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,110 +0,0 @@
-/*
- * 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.renderkit;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class RenderKitUtilsTest {
-
- @Test
- public void testEscape() throws Exception {
- assertEquals("", RenderKitUtils.escape(""));
- assertEquals("abcd", RenderKitUtils.escape("abcd"));
- assertEquals("\\'abcd",
RenderKitUtils.escape("'abcd"));
- assertEquals("abcd\\'",
RenderKitUtils.escape("abcd'"));
- assertEquals("ab\\'cd",
RenderKitUtils.escape("ab'cd"));
- assertEquals("ab\\'\\'cd",
RenderKitUtils.escape("ab''cd"));
- assertEquals("ab\\'c\\'d",
RenderKitUtils.escape("ab'c'd"));
- }
-
- @Test
- public void testChain() throws Exception {
- StringBuilder sb = new StringBuilder();
-
- assertFalse(RenderKitUtils.chain(sb, "", false));
- assertTrue(sb.length() == 0);
- assertFalse(RenderKitUtils.chain(sb, null, false));
- assertTrue(sb.length() == 0);
-
- assertFalse(RenderKitUtils.chain(sb, "test", false));
- assertEquals("test", sb.toString());
-
- assertFalse(RenderKitUtils.chain(sb, "", false));
- assertEquals("test", sb.toString());
-
- assertTrue(RenderKitUtils.chain(sb, "another'object", false));
- assertEquals("'test','another\\'object'",
sb.toString());
-
- assertTrue(RenderKitUtils.chain(sb, "one more", true));
- assertEquals("'test','another\\'object','one
more'", sb.toString());
- }
-
- @Test
- public void testShouldRenderAttribute() throws Exception {
- assertFalse(RenderKitUtils.shouldRenderAttribute(null));
-
- assertFalse(RenderKitUtils.shouldRenderAttribute(""));
- assertTrue(RenderKitUtils.shouldRenderAttribute("test"));
-
- assertTrue(RenderKitUtils.shouldRenderAttribute(new Object()));
-
- assertTrue(RenderKitUtils.shouldRenderAttribute(Long.valueOf(10)));
- assertTrue(RenderKitUtils.shouldRenderAttribute(Long.valueOf(0)));
- assertFalse(RenderKitUtils.shouldRenderAttribute(Long.MIN_VALUE));
-
- assertTrue(RenderKitUtils.shouldRenderAttribute(Integer.valueOf(10)));
- assertTrue(RenderKitUtils.shouldRenderAttribute(Integer.valueOf(0)));
- assertFalse(RenderKitUtils.shouldRenderAttribute(Integer.MIN_VALUE));
-
- assertTrue(RenderKitUtils.shouldRenderAttribute(Short.valueOf((short) 10)));
- assertTrue(RenderKitUtils.shouldRenderAttribute(Short.valueOf((short) 0)));
- assertFalse(RenderKitUtils.shouldRenderAttribute(Short.MIN_VALUE));
-
-
assertTrue(RenderKitUtils.shouldRenderAttribute(Character.valueOf('a')));
- assertTrue(RenderKitUtils.shouldRenderAttribute(Character.valueOf((char) 13)));
- assertFalse(RenderKitUtils.shouldRenderAttribute(Character.MIN_VALUE));
-
- assertTrue(RenderKitUtils.shouldRenderAttribute(Byte.valueOf((byte) 10)));
- assertTrue(RenderKitUtils.shouldRenderAttribute(Byte.valueOf((byte) 0)));
- assertFalse(RenderKitUtils.shouldRenderAttribute(Byte.MIN_VALUE));
-
- assertTrue(RenderKitUtils.shouldRenderAttribute(Double.valueOf(10)));
- assertTrue(RenderKitUtils.shouldRenderAttribute(Double.valueOf(0)));
- assertFalse(RenderKitUtils.shouldRenderAttribute(Double.MIN_VALUE));
-
- assertTrue(RenderKitUtils.shouldRenderAttribute(Float.valueOf(10)));
- assertTrue(RenderKitUtils.shouldRenderAttribute(Float.valueOf(0)));
- assertFalse(RenderKitUtils.shouldRenderAttribute(Float.MIN_VALUE));
-
- assertTrue(RenderKitUtils.shouldRenderAttribute(Boolean.TRUE));
- assertFalse(RenderKitUtils.shouldRenderAttribute(Boolean.FALSE));
- }
-
-}
\ No newline at end of file
Modified: branches/RF-7560/core/impl/pom.xml
===================================================================
--- branches/RF-7560/core/impl/pom.xml 2010-08-31 16:59:42 UTC (rev 19051)
+++ branches/RF-7560/core/impl/pom.xml 2010-08-31 17:20:11 UTC (rev 19052)
@@ -124,23 +124,8 @@
</configuration>
</plugin>
- <!--
- TODO Centralize this because calendar and context menu use this too
- Note: This may be removed by redisgn
- -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
- <artifactId>javacc-maven-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>javacc</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<executions>
<execution>
Deleted:
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,221 +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.ajax4jsf.renderkit;
-
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import javax.faces.component.NamingContainer;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.component.AjaxChildrenEncoder;
-import org.ajax4jsf.component.AjaxOutput;
-import org.ajax4jsf.context.AjaxContext;
-import org.richfaces.log.Logger;
-import org.richfaces.log.RichfacesLogger;
-
-/**
- * @author shura
- */
-public abstract class AjaxChildrenRenderer extends AjaxComponentRendererBase implements
AjaxRenderer {
- public static final String[] SPECIAL_COMPONENTS_TYPES =
{"org.ajax4jsf.Bundle" /* UILoadBundle.COMPONENT_TYPE */,
- "org.apache.myfaces.AliasBean",
"org.apache.myfaces.AliasBeansScope"};
-
- private static final String SPECIAL_TYPES_PARAMETER =
"org.ajax4jsf.CONTROL_COMPONENTS";
- private static final Logger LOG = RichfacesLogger.RENDERKIT.getLogger();
-
- private Set<String> specialComponentTypes = null;
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.ajax4jsf.renderkit.AjaxRenderer#encodeAjaxChildren(javax.faces.context
- * .FacesContext, javax.faces.component.UIComponent, java.lang.String,
- * java.util.Set, java.util.Set)
- */
- public void encodeAjaxChildren(FacesContext context, UIComponent component, String
path, Set<String> ids,
- Set<String> renderedAreas) throws IOException {
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(Messages.getMessage(Messages.ENCODE_CHILD_AJAX_INFO, path,
component.getId()));
- }
-
- String currentPath = path;
-
- if (component instanceof NamingContainer) {
- currentPath += component.getId() + NamingContainer.SEPARATOR_CHAR;
-
- // Do not check children if we have no id to render under naming
- // container.
- if (AjaxContext.getCurrentInstance(context).isLimitToList() &&
noIdUnderPath(path, ids)) {
- return;
- }
- }
-
- for (Iterator<UIComponent> it = component.getFacetsAndChildren();
it.hasNext();) {
- UIComponent element = (UIComponent) it.next();
-
- encodeAjaxComponent(context, element, currentPath, ids, renderedAreas);
- }
- }
-
- private boolean noIdUnderPath(String path, Set<String> ids) {
-
- // Do we have an any component for the rendering under that container ?
- boolean noSuchId = true;
-
- for (String id : ids) {
- if ((null != id) && id.startsWith(path)) {
- noSuchId = false;
-
- break;
- }
- }
-
- return noSuchId;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.ajax4jsf.renderkit.AjaxRenderer#encodeAjaxComponent(javax.faces.context
- * .FacesContext, javax.faces.component.UIComponent, java.lang.String,
- * java.util.Set, java.util.Set)
- */
- public void encodeAjaxComponent(FacesContext context, UIComponent component, String
currentPath, Set<String> ids,
- Set<String> renderedAreas) throws IOException
{
-
- if (component.isRendered()) { // skip not-rendered components.
- boolean found = false;
- boolean limitToList =
AjaxContext.getCurrentInstance(context).isLimitToList();
- String elementId = component.getId();
- String absoluteId = currentPath + elementId;
-
- if (!ids.isEmpty()) {
-
- // list for rendering may contains absolute id ( best ),
- // component Id or client ID
- // String clientId = element.getClientId(context);
- if (ids.contains(absoluteId) || ids.contains(elementId)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug(Messages.getMessage(Messages.RENDER_AJAX_AREA_INFO,
absoluteId));
- }
-
- // renderChild(context, element);
- found = true;
- }
- }
-
- //
- if (!found && limitToList && (component instanceof
NamingContainer)
- && noIdUnderPath(absoluteId + NamingContainer.SEPARATOR_CHAR,
ids)) {
- return;
- }
-
- if (!found && !limitToList && (component instanceof
AjaxOutput)) {
- if (((AjaxOutput) component).isAjaxRendered()) {
-
- // renderChild(context, element);
- found = true;
- }
- }
-
- if (!found) {
- if (component instanceof AjaxChildrenEncoder) {
- ((AjaxChildrenEncoder) component).encodeAjaxChild(context,
currentPath, ids, renderedAreas);
- } else {
-
- // Special case - for control components, not produced
- // html code - such as message bundles loaders,
- // MyFaces aliases etc. we call encodeBegin/end methods
- // even if components not in rendered areas.
- boolean special = isSpecialElement(context, component);
-
- if (special) {
- component.encodeBegin(context);
- }
-
- encodeAjaxChildren(context, component, currentPath, ids,
renderedAreas);
-
- if (special) {
- component.encodeEnd(context);
- }
- }
- } else {
- renderedAreas.add(component.getClientId(context));
- component.encodeAll(context);
- }
- }
- }
-
- /**
- * Detect component as special control case - such as messages bundle
- * loader, alias bean components etc. Type of component get by reflection
- * from static field COMPONENT_TYPE
- *
- * @param context
- * @param component
- * @return true if encode methods must be called for this component even in
- * not-rendered parts.
- */
- private boolean isSpecialElement(FacesContext context, UIComponent component) {
- if (specialComponentTypes == null) {
- specialComponentTypes = new HashSet<String>(10);
-
- for (int i = 0; i < SPECIAL_COMPONENTS_TYPES.length; i++) {
- specialComponentTypes.add(SPECIAL_COMPONENTS_TYPES[i]);
- }
-
- String special =
context.getExternalContext().getInitParameter(SPECIAL_TYPES_PARAMETER);
-
- if (null != special) {
- String[] split = special.split(",");
-
- for (int i = 0; i < split.length; i++) {
- specialComponentTypes.add(split[i]);
- }
- }
- }
-
- boolean result;
-
- try {
- String componentType = (String)
component.getClass().getField("COMPONENT_TYPE").get(null);
-
- result = specialComponentTypes.contains(componentType);
- } catch (Exception e) {
-
- // exception occurs if component not have accesible COMPONENT_TYPE
- // constant
- // we assume that component not in special types.
- result = false;
- }
-
- return result;
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxComponentRendererBase.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxComponentRendererBase.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxComponentRendererBase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,32 +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.ajax4jsf.renderkit;
-
-/**
- * Base class for all Ajax enabled components. Perform common task -
- * output javasript for component.
- *
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:49 $
- */
-public abstract class AjaxComponentRendererBase extends RendererBase {
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/ComponentRendererBase.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/ComponentRendererBase.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/ComponentRendererBase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,96 +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.ajax4jsf.renderkit;
-
-import javax.faces.component.UIComponent;
-import java.util.HashMap;
-import java.util.Stack;
-
-/**
- * Components Base Renderer for all chameleon Skin's and components.
- * At most, make all common procedures and realise concrete work in "template"
methods.
- *
- * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:52 $
- */
-public abstract class ComponentRendererBase extends RendererBase {
-
- /**
- * logger for common cases.
- */
- protected static final String COMPONENT_RENDERER_BASE =
ComponentRendererBase.class.getName();
-
- public ComponentVariables getVariables(UIComponent component) {
- HashMap components;
- Stack stackComponentsVariables;
- ComponentVariables variables;
-
- components = (HashMap) component.getAttributes().get(COMPONENT_RENDERER_BASE);
-
- if (components == null) {
- components = new HashMap();
- component.getAttributes().put(COMPONENT_RENDERER_BASE, components);
- }
-
- stackComponentsVariables = (Stack) components.get(this.getClass().getName());
-
- if (stackComponentsVariables == null) {
- stackComponentsVariables = new Stack();
- components.put(COMPONENT_RENDERER_BASE, stackComponentsVariables);
- }
-
- if (stackComponentsVariables.empty()) {
- variables = new ComponentVariables();
- stackComponentsVariables.push(variables);
- } else {
- variables = (ComponentVariables) stackComponentsVariables.peek();
- }
-
- return variables;
- }
-
- public void removeVariables(UIComponent component) {
- HashMap components;
- Stack stackComponentsVariables;
- ComponentVariables variables;
-
- components = (HashMap) component.getAttributes().get(COMPONENT_RENDERER_BASE);
-
- if (components != null) {
- stackComponentsVariables = (Stack)
component.getAttributes().get(this.getClass().getName());
-
- if (stackComponentsVariables != null) {
- if (!stackComponentsVariables.empty()) {
- stackComponentsVariables.pop();
- }
-
- if (stackComponentsVariables.empty()) {
- components.remove(this.getClass().getName());
- }
- }
-
- if (components.isEmpty()) {
- component.getAttributes().remove(COMPONENT_RENDERER_BASE);
- }
- }
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/ComponentVariables.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/ComponentVariables.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/ComponentVariables.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,99 +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.ajax4jsf.renderkit;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * storing tempates variables
- *
- * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.2 $ $Date: 2007/02/28 17:01:01 $
- */
-public class ComponentVariables implements Serializable {
-
- /**
- *
- */
- private static final long serialVersionUID = 4310787278096026676L;
- private transient Map<String, Object> variablesMap = new HashMap<String,
Object>();
-
- /**
- * setting variable
- *
- * @param variableName
- * @param variable
- */
- public void setVariable(final String variableName, final Object variable) {
- variablesMap.put(variableName, variable);
- }
-
- /**
- * @param variableName
- * @return
- */
- public Object getVariable(final String variableName) {
- return variablesMap.get(variableName);
- }
-
- /**
- * @param variableName
- * @param addValue
- */
- public void addValueToVariable(final String variableName, final Object addValue) {
- Object variable = getVariable(variableName);
-
- if (variable == null) {
- return;
- }
-
- if (variable instanceof Integer) {
- addToValue(variableName, (Integer) variable, addValue);
- }
- }
-
- /**
- * @param variableName
- * @param variable
- * @param addValue
- */
- protected void addToValue(final String variableName, Integer variable, final Object
addValue) {
- Integer retultValue;
-
- if (addValue instanceof Integer) {
- Integer intAddValue = (Integer) addValue;
-
- retultValue = new Integer(variable.intValue() + intAddValue.intValue());
- } else {
- retultValue = variable;
- }
-
- setVariable(variableName, retultValue);
- }
-
- private void readObject(java.io.ObjectInputStream in) throws IOException,
ClassNotFoundException {
- variablesMap = new HashMap<String, Object>();
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/ComponentsVariableResolver.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/ComponentsVariableResolver.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/ComponentsVariableResolver.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,60 +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.ajax4jsf.renderkit;
-
-import javax.faces.component.UIComponent;
-
-/**
- * Resolve component variables
- *
- * @author ayukhovich(a)exadel.com (latest modification by $Author:
- * alexeyyukhovich $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:53 $
- */
-public final class ComponentsVariableResolver {
- private static final String COMPONENTS_VARIABLE_RESOLVER =
ComponentsVariableResolver.class.getName();
-
- private ComponentsVariableResolver() {
- }
-
- private static String getAttributeName(RendererBase renderer) {
- return COMPONENTS_VARIABLE_RESOLVER + ":" + ((renderer != null) ?
renderer.getClass().getName() : null);
- }
-
- public static ComponentVariables getVariables(RendererBase renderer, UIComponent
component) {
- ComponentVariables variables;
- String attributeName = getAttributeName(renderer);
-
- variables = (ComponentVariables) component.getAttributes().get(attributeName);
-
- if (variables == null) {
- variables = new ComponentVariables();
- component.getAttributes().put(attributeName, variables);
- }
-
- return variables;
- }
-
- public static void removeVariables(RendererBase renderer, UIComponent component) {
- component.getAttributes().remove(getAttributeName(renderer));
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,284 +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.ajax4jsf.renderkit;
-
-import java.io.IOException;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.render.Renderer;
-
-import org.ajax4jsf.Messages;
-import org.richfaces.log.Logger;
-import org.richfaces.log.RichfacesLogger;
-import org.richfaces.renderkit.RenderKitUtils;
-import org.richfaces.skin.Skin;
-import org.richfaces.skin.SkinFactory;
-
-/**
- * Base Renderer for all chameleon Skin's and components.
- * At most, make all common procedures and realise concrete work in "template"
methods.
- *
- * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:51 $
- */
-public abstract class RendererBase extends Renderer {
-
- private static final Logger LOG = RichfacesLogger.RENDERKIT.getLogger();
- private static final RendererUtils UTILS = RendererUtils.getInstance();
-
- private SkinFactory skinFactory = null;
-
- /*
- * (non-Javadoc)
- * @see javax.faces.render.Renderer#decode(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
- */
- @Override
- public void decode(FacesContext context, UIComponent component) {
-
- // Test for correct parameters.
- checkNull(context, component, "decode");
-
- if (!getComponentClass().isInstance(component)) {
- throw new
IllegalArgumentException(Messages.getMessage(Messages.COMPONENT_CLASS_ERROR,
"",
- getComponentClass().getName()));
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(Messages.getMessage(Messages.START_DECODING_COMPONENT_INFO,
component.getClientId(context),
- component.getClass().getName()));
- }
-
- preDecode(context, component);
-
- // TODO - create set od common decoders ( UIInput, ActionSource etc. ) for
process decoding.
- if (component.isRendered()) {
- String behaviorEventName = RenderKitUtils.decodeBehaviors(context,
component);
- if (behaviorEventName != null) {
- queueComponentEventForBehaviorEvent(context, component,
behaviorEventName);
- }
-
- doDecode(context, component);
- }
- }
-
- protected void queueComponentEventForBehaviorEvent(FacesContext context, UIComponent
component, String eventName) {
-
- }
-
- protected void preDecode(FacesContext context, UIComponent component) {
- }
-
- protected void preEncodeBegin(FacesContext context, UIComponent component) throws
IOException {
- }
-
- /*
- * (non-Javadoc)
- * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
- */
- @Override
- public void encodeBegin(FacesContext context, UIComponent component) throws
IOException {
-
- // Test for correct parameters.
- checkForCorrectParams(context, component, "encodeBegin");
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(Messages.getMessage(Messages.START_ENCODING_COMPONENT_INFO,
component.getClientId(context),
- component.getClass().getName()));
- }
-
- preEncodeBegin(context, component);
-
- if (component.isRendered()) {
- ResponseWriter writer = context.getResponseWriter();
-
- doEncodeBegin(writer, context, component);
- }
- }
-
- private void checkForCorrectParams(FacesContext context, UIComponent component,
String exceptionMessageParam) {
- checkNull(context, component, exceptionMessageParam);
-
- if (!getComponentClass().isInstance(component)) {
- throw new
IllegalArgumentException(Messages.getMessage(Messages.COMPONENT_CLASS_ERROR,
- component.getClientId(context), getComponentClass().getName()));
- }
- }
-
- private void checkNull(Object context, Object component, String
exceptionMessageParam) {
- if (context == null) {
- throw new
NullPointerException(Messages.getMessage(Messages.CONTEXT_NULL_ERROR,
exceptionMessageParam));
- }
-
- if (component == null) {
- throw new
NullPointerException(Messages.getMessage(Messages.COMPONENT_NULL_ERROR,
exceptionMessageParam));
- }
- }
-
- /*
- * (non-Javadoc)
- * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
- */
- @Override
- public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
-
- // Test for correct parameters.
- checkForCorrectParams(context, component, "encodeBegin");
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(Messages.getMessage(Messages.CHILDREN_ENCODING_COMPONENT_INFO,
component.getClientId(context),
- component.getClass().getName()));
- }
-
- preEncodeBegin(context, component);
-
- if (component.isRendered()) {
- ResponseWriter writer = context.getResponseWriter();
-
- doEncodeChildren(writer, context, component);
- }
- }
-
- /*
- * (non-Javadoc)
- * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
- */
- @Override
- public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
-
- // Test for correct parameters.
- checkForCorrectParams(context, component, "encodeEnd");
-
- if (component.isRendered()) {
- ResponseWriter writer = context.getResponseWriter();
-
- doEncodeEnd(writer, context, component);
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(Messages.getMessage(Messages.FINISH_ENCODING_COMPONENT_INFO,
component.getClientId(context),
- component.getClass().getName()));
- }
- }
-
- // ==========================================================
- // Protected common methods - for all Renderer's
-
- /**
- * Calculate current Skin for rendering.
- *
- * @param context - current {@link FacesContext }
- * @return
- */
- protected Skin getSkin(FacesContext context) {
- if (skinFactory == null) {
- skinFactory = SkinFactory.getInstance();
- }
-
- return skinFactory.getSkin(context);
- }
-
- /**
- * Due to big number of common utility methods, base renderer divide to 2 classes -
renderer and utils.
- * since use static methods of utility class breack object paradigm, we use getter
for concrete util instance.
- * Developer can override any utility metod in 2 stages :
- * 1) Create subclass of {@link RendererUtils} and override utility method.
- * 2) Override this method for return instance of such subclass.
- *
- * @return Returns the utils.
- */
- public RendererUtils getUtils() {
- return UTILS;
- }
-
- /**
- * Get base component slass , targetted for this renderer. Used for check arguments
in decode/encode.
- *
- * @return
- */
- protected Class<? extends UIComponent> getComponentClass() {
- //TODO - do we need this function?
- return UIComponent.class;
- }
-
- /**
- * Template method for custom decoding of concrete renderer.
- * All parameters checking if performed in original {@see decode } method.
- *
- * @param context
- * @param component
- */
- protected void doDecode(FacesContext context, UIComponent component) {
- }
-
- /**
- * Template method for custom start encoding of concrete renderer.
- * All parameters checking and writer is performed in original {@link encodeBegin }
method.
- *
- * @param writer
- * @param context
- * @param component
- */
- protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component)
- throws IOException {
- }
-
- /**
- * @param writer
- * @param context
- * @param component
- */
- protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component)
- throws IOException {
-
- // Hook method, must be overriden in renderers with special children processing
- }
-
- /**
- * Template method for custom finish encoding of concrete renderer.
- * All parameters checking and writer is performed in original {@link encodeEnd }
method.
- *
- * @param writer
- * @param context
- * @param component
- * @throws IOException
- */
- protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
- }
-
- /**
- * Render all children for given component.
- *
- * @param facesContext
- * @param component
- * @throws IOException
- */
- public void renderChildren(FacesContext facesContext, UIComponent component) throws
IOException {
- if (component.getChildCount() > 0) {
- for (UIComponent child : component.getChildren()) {
- child.encodeAll(facesContext);
- }
- }
- }
-
-}
Deleted: branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/CacheContent.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/CacheContent.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/CacheContent.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,337 +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.ajax4jsf.webapp;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.Serializable;
-import java.io.Writer;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.faces.context.ExternalContext;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletResponse;
-
-import org.ajax4jsf.io.FastBufferOutputStream;
-import org.ajax4jsf.io.FastBufferWriter;
-import org.richfaces.log.Logger;
-import org.richfaces.log.RichfacesLogger;
-import org.richfaces.util.Util;
-
-/**
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:20 $
- */
-public class CacheContent implements Serializable {
- private static final long serialVersionUID = 8120940486890871177L;
- private static final Logger LOG = RichfacesLogger.WEBAPP.getLogger();
-
- boolean filledOutputWriter = false;
- boolean filledOutputStream = false;
-
- // content to send.
- private byte[] content = null;
- private String writerContent = null;
- private Map<String, Object> headers = new HashMap<String, Object>();
- private Integer contentLength;
- private String contentType;
-
- // private transient ByteArrayOutputStream outputStream ;
- private transient FastBufferOutputStream outputStream;
- private transient ServletOutputStream servletStream;
- private transient PrintWriter servletWriter;
- private transient FastBufferWriter stringOutputWriter;
-
- @Deprecated
- public void send(HttpServletResponse response) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Send saved content to http responce
- *
- * @param response
- * @throws IOException
- */
- public void send(ExternalContext externalContext) throws IOException {
- if (filledOutputStream) {
- OutputStream out = externalContext.getResponseOutputStream();
-
- if (content != null) {
- out.write(content);
- } else {
- this.outputStream.writeTo(out);
- }
-
- // out.flush();
- // out.close();
- } else if (filledOutputWriter) {
- Writer out = externalContext.getResponseOutputWriter();
-
- if (null != writerContent) {
- out.write(writerContent);
- } else {
- stringOutputWriter.writeTo(out);
- }
-
- // out.flush();
- // out.close();
- }
- }
-
- /**
- * Send saved headers to http responce.
- *
- * @param response
- */
- public void sendHeaders(ExternalContext externalContext) {
-
- // set real content-length.
- // / if (null != content) {
- int realContentLength = 0;
-
- if (filledOutputStream) {
- if ((null != content) && (content.length > 0)) {
- realContentLength = content.length;
- } else if ((null != outputStream) && (outputStream.getLength() >
0)) {
- realContentLength = outputStream.getLength();
- }
- } // TODO - calculate content-lenght for writer ?
-
- if ((realContentLength <= 0) && (contentLength != null)) {
- realContentLength = contentLength.intValue();
- }
-
- for (Iterator<Entry<String, Object>> iter =
headers.entrySet().iterator(); iter.hasNext();) {
- Entry<String, Object> element = iter.next();
- String header = (String) element.getKey();
- Object headerValue = element.getValue();
-
- try {
- if (headerValue instanceof Long) {
- Long time = (Long) headerValue;
- String formattedDate = Util.formatHttpDate(time);
-
- externalContext.setResponseHeader(header, formattedDate);
- } else if (headerValue instanceof Integer) {
- Integer value = (Integer) headerValue;
-
- // Check real content length.
- if ("Content-Length".equals(header)) {
- if (realContentLength <= 0) {
- realContentLength = value.intValue();
- } else {
-
- // do nothing
- }
- } else {
- externalContext.setResponseHeader(header, value.toString());
- }
- } else {
-
- // Don't send "chunked" transfer-encoding type with
real content-length
- if (!((realContentLength > 0) &&
"Transfer-Encoding".equals(header)
- && "chunked".equals(headerValue))) {
- externalContext.setResponseHeader(header, (String) headerValue);
- }
- }
- } catch (Exception e) {
- LOG.error("Error set response header " + header + "for
value " + headerValue, e);
- }
-
- if (realContentLength > 0) {
- externalContext.setResponseContentLength(realContentLength);
- }
-
- if (null != contentType) {
- externalContext.setResponseContentType(this.contentType);
- }
- }
- }
-
- @Deprecated
- public void sendHeaders(HttpServletResponse response) {
- throw new UnsupportedOperationException();
- }
-
- public void setDateHeader(String name, long value) {
-
- // Expires not stored in cache - must be re-calculated for every
- // response.
- if (!"Expires".equals(name)) {
- headers.put(name, new Long(value));
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.resource.ResourceContext#setHeader(java.lang.String,
- * java.lang.String)
- */
- public void setHeader(String name, String value) {
- headers.put(name, value);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.resource.ResourceContext#setIntHeader(java.lang.String,
- * int)
- */
- public void setIntHeader(String name, int value) {
- headers.put(name, new Integer(value));
- }
-
- /**
- * Create UNIX command 'tee' like stream - send all data to servlet
- *
- * @param responseStream
- * @return
- */
- public OutputStream getOutputStream() {
- if (null == servletStream) {
- outputStream = new FastBufferOutputStream(1024);
- servletStream = new ServletOutputStream() {
- @Override
- public void close() {
- filledOutputStream = true;
- content = null;
- }
-
- @Override
- public void flush() {
- }
-
- @Override
- public void write(byte[] b, int off, int len) throws IOException {
- outputStream.write(b, off, len);
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- outputStream.write(b);
- }
-
- @Override
- public void write(int b) throws IOException {
- outputStream.write(b);
- }
- };
- }
-
- return servletStream;
- }
-
- public PrintWriter getWriter() {
- if (null == servletWriter) {
- stringOutputWriter = new FastBufferWriter(1024);
-
- Writer out = new Writer() {
- @Override
- public void write(char[] cbuf, int off, int len) throws IOException {
- stringOutputWriter.write(cbuf, off, len);
- }
-
- @Override
- public void flush() throws IOException {
- }
-
- @Override
- public void close() throws IOException {
- filledOutputWriter = true;
- writerContent = null;
- }
- };
-
- servletWriter = new PrintWriter(out);
- }
-
- return servletWriter;
- }
-
- public void setContentType(String contentType) {
- this.contentType = contentType;
- }
-
- /**
- * @return Returns the contentType.
- */
- public String getContentType() {
- return contentType;
- }
-
- private void writeObject(java.io.ObjectOutputStream s) throws IOException {
- if (filledOutputStream) {
- if (outputStream != null) {
- content = outputStream.toByteArray();
- }
- } else if (filledOutputWriter) {
- if (stringOutputWriter != null) {
- char[] cs = stringOutputWriter.toCharArray();
-
- writerContent = new String(cs);
- }
- }
-
- s.defaultWriteObject();
- }
-
- @Deprecated
- public void flush(HttpServletResponse response) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Flush used output writer/stream, to fix
https://jira.jboss.org/jira/browse/RF-4017
- *
- * @param response
- * @throws IOException
- */
- public void flush(ExternalContext externalContext) throws IOException {
- if (filledOutputStream) {
- OutputStream out = externalContext.getResponseOutputStream();
-
- out.flush();
- } else if (filledOutputWriter) {
- Writer out = externalContext.getResponseOutputWriter();
-
- out.flush();
- }
- }
-
- public int getContentLength() {
- if (contentLength == null) {
- throw new IllegalStateException("Content length hasn't been set
yet!");
- }
-
- return contentLength.intValue();
- }
-
- public void setContentLength(int contentLength) {
- this.contentLength = contentLength;
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/PollEventsManager.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/PollEventsManager.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/PollEventsManager.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,63 +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.ajax4jsf.webapp;
-
-import java.io.Serializable;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import javax.servlet.ServletContext;
-
-/**
- * @author asmirnov
- */
-
-//TODO: deprecate
-public class PollEventsManager implements Serializable {
- public static final String EVENTS_MANAGER_KEY = PollEventsManager.class.getName();
- private static final long serialVersionUID = -6257285396790747665L;
-
- // TODO should use cache - push is application-scoped, not session-scoped
- private ConcurrentMap<String, PushEventsCounter> counters = new
ConcurrentHashMap<String, PushEventsCounter>();
-
- public void init(ServletContext servletContext) {
- servletContext.setAttribute(EVENTS_MANAGER_KEY, this);
- }
-
- public PushEventsCounter getListener(String key) {
- PushEventsCounter counter = counters.get(key);
-
- if (counter != null) {
- return counter;
- } else {
- counter = new PushEventsCounter();
-
- PushEventsCounter oldCounter = counters.putIfAbsent(key, counter);
-
- if (oldCounter != null) {
- return oldCounter;
- } else {
- return counter;
- }
- }
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/AjaxActionsRule.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/AjaxActionsRule.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/AjaxActionsRule.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,123 +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.ajax4jsf.webapp.taglib;
-
-import javax.faces.component.ActionSource;
-import javax.faces.component.ActionSource2;
-import javax.faces.event.ActionEvent;
-import javax.faces.event.MethodExpressionActionListener;
-import javax.faces.view.facelets.FaceletContext;
-import javax.faces.view.facelets.MetaRule;
-import javax.faces.view.facelets.Metadata;
-import javax.faces.view.facelets.MetadataTarget;
-import javax.faces.view.facelets.TagAttribute;
-
-/**
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/02/01 15:31:21 $
- */
-public class AjaxActionsRule extends MetaRule {
- public static final Class<?>[] ACTION_SIG = new Class[0];
- public static final Class<?>[] ACTION_LISTENER_SIG = new
Class[]{ActionEvent.class};
- public static final AjaxActionsRule INSTANCE = new AjaxActionsRule();
-
- public AjaxActionsRule() {
- super();
- }
-
- @Override
- public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
{
- if (meta.isTargetInstanceOf(ActionSource.class)) {
- if ("action".equals(name)) {
- if (meta.isTargetInstanceOf(ActionSource2.class)) {
- return new ActionMapper2(attribute);
- } else {
- return new ActionMapper(attribute);
- }
- }
-
- if ("actionListener".equals(name)) {
- if (meta.isTargetInstanceOf(ActionSource2.class)) {
- return new ActionListenerMapper2(attribute);
- } else {
- return new ActionListenerMapper(attribute);
- }
- }
- }
-
- return null;
- }
-
- public static final class ActionListenerMapper extends Metadata {
- private final TagAttribute attr;
-
- public ActionListenerMapper(TagAttribute attr) {
- this.attr = attr;
- }
-
- public void applyMetadata(FaceletContext ctx, Object instance) {
- ((ActionSource) instance).addActionListener(
- new MethodExpressionActionListener(
- this.attr.getMethodExpression(ctx, null,
AjaxActionsRule.ACTION_LISTENER_SIG)));
- }
- }
-
- static final class ActionListenerMapper2 extends Metadata {
- private final TagAttribute attr;
-
- public ActionListenerMapper2(TagAttribute attr) {
- this.attr = attr;
- }
-
- public void applyMetadata(FaceletContext ctx, Object instance) {
- ((ActionSource2) instance).addActionListener(
- new MethodExpressionActionListener(
- this.attr.getMethodExpression(ctx, null,
AjaxActionsRule.ACTION_LISTENER_SIG)));
- }
- }
-
- public static final class ActionMapper extends Metadata {
- private final TagAttribute attr;
-
- public ActionMapper(TagAttribute attr) {
- this.attr = attr;
- }
-
- public void applyMetadata(FaceletContext ctx, Object instance) {
- ((ActionSource2)
instance).setActionExpression(this.attr.getMethodExpression(ctx, String.class,
- AjaxActionsRule.ACTION_SIG));
- }
- }
-
- static final class ActionMapper2 extends Metadata {
- private final TagAttribute attr;
-
- public ActionMapper2(TagAttribute attr) {
- this.attr = attr;
- }
-
- public void applyMetadata(FaceletContext ctx, Object instance) {
- ((ActionSource2)
instance).setActionExpression(this.attr.getMethodExpression(ctx, String.class,
- AjaxActionsRule.ACTION_SIG));
- }
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/EmptyHandler.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/EmptyHandler.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/EmptyHandler.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,53 +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.ajax4jsf.webapp.taglib;
-
-import javax.el.ELException;
-import javax.faces.FacesException;
-import javax.faces.component.UIComponent;
-import javax.faces.view.facelets.FaceletContext;
-import javax.faces.view.facelets.FaceletException;
-import javax.faces.view.facelets.TagConfig;
-import javax.faces.view.facelets.TagHandler;
-import java.io.IOException;
-
-/**
- * This if "empty" facelets tag handler stub. This handler used to ignore tags
on a page.
- * At most, it used to bypass <jsp:root> and other tags, so we can use same
markup for an facelets an jsp pages.
- *
- * @author asmirnov
- */
-public class EmptyHandler extends TagHandler {
- public EmptyHandler(TagConfig config) {
- super(config);
- }
-
- /*
- * (non-Javadoc)
- * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext,
javax.faces.component.UIComponent)
- */
- public void apply(FaceletContext ctx, UIComponent parent)
- throws IOException, FacesException, FaceletException, ELException {
-
- this.nextHandler.apply(ctx, parent);
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/RowKeyConverterRule.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/RowKeyConverterRule.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/RowKeyConverterRule.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,94 +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.ajax4jsf.webapp.taglib;
-
-import org.richfaces.component.UIDataAdaptor;
-
-import javax.faces.convert.Converter;
-import javax.faces.view.facelets.FaceletContext;
-import javax.faces.view.facelets.MetaRule;
-import javax.faces.view.facelets.Metadata;
-import javax.faces.view.facelets.MetadataTarget;
-import javax.faces.view.facelets.TagAttribute;
-
-/**
- * Apply rowKeyConverter to component
- *
- * @author Maksim Kaszynski
- * @since 3.3.1
- */
-public class RowKeyConverterRule extends MetaRule {
- public static final RowKeyConverterRule INSTANCE = new RowKeyConverterRule();
-
- /*
- * (non-Javadoc)
- *
- * @see com.sun.facelets.tag.MetaRule#applyRule(java.lang.String,
- * com.sun.facelets.tag.TagAttribute,
- * com.sun.facelets.tag.MetadataTarget)
- */
- @Override
- public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
{
- if (meta.isTargetInstanceOf(UIDataAdaptor.class)) {
- if ("rowKeyConverter".equals(name)) {
- if (attribute.isLiteral()) {
- return new StaticConverterMetadata(attribute.getValue());
- } else {
- return new DynamicConverterMetaData(attribute);
- }
- }
- }
-
- return null;
- }
-
- static final class DynamicConverterMetaData extends Metadata {
- private final TagAttribute attribute;
-
- public DynamicConverterMetaData(TagAttribute attribute) {
- super();
- this.attribute = attribute;
- }
-
- @Override
- public void applyMetadata(FaceletContext ctx, Object instance) {
- ((UIDataAdaptor) instance).setValueExpression("rowKeyConverter",
- attribute.getValueExpression(ctx, Converter.class));
- }
- }
-
- static final class StaticConverterMetadata extends Metadata {
- private final String converterId;
-
- public StaticConverterMetadata(String converterId) {
- super();
- this.converterId = converterId;
- }
-
- @Override
- public void applyMetadata(FaceletContext ctx, Object instance) {
- Converter converter =
ctx.getFacesContext().getApplication().createConverter(converterId);
-
- ((UIDataAdaptor) instance).setRowKeyConverter(converter);
- }
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/package-info.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/package-info.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/package-info.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,4 +0,0 @@
-/**
- * Basic tag classes
- */
-package org.ajax4jsf.webapp.taglib;
Deleted:
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/EnclosingFormRequiredException.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/EnclosingFormRequiredException.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/EnclosingFormRequiredException.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,52 +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 javax.faces.FacesException;
-
-/**
- * @author Filip Antonov - mailto:fantonov@exadel.com
- * created 08.02.2007
- */
-public class EnclosingFormRequiredException extends FacesException {
-
- /**
- *
- */
- private static final long serialVersionUID = 1877777524838776600L;
-
- public EnclosingFormRequiredException() {
- super();
- }
-
- public EnclosingFormRequiredException(String message) {
- super(message);
- }
-
- public EnclosingFormRequiredException(Throwable cause) {
- super(cause);
- }
-
- public EnclosingFormRequiredException(String message, Throwable cause) {
- super(message, cause);
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/RowKeyContextEventWrapper.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/RowKeyContextEventWrapper.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/RowKeyContextEventWrapper.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,74 +0,0 @@
-/*
- * 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 javax.faces.component.UIComponent;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.FacesListener;
-import javax.faces.event.PhaseId;
-
-/**
- * @author Nick Belaevski
- */
-class RowKeyContextEventWrapper extends FacesEvent {
-
- /**
- *
- */
- private static final long serialVersionUID = -869970815228914529L;
- private FacesEvent event;
- private Object rowKey;
-
- public RowKeyContextEventWrapper(UIComponent component, FacesEvent event, Object
rowKey) {
- super(component);
- this.event = event;
- this.rowKey = rowKey;
- }
-
- public FacesEvent getFacesEvent() {
- return this.event;
- }
-
- public PhaseId getPhaseId() {
- return this.event.getPhaseId();
- }
-
- public void setPhaseId(PhaseId phaseId) {
- this.event.setPhaseId(phaseId);
- }
-
- public boolean isAppropriateListener(FacesListener listener) {
- return false;
- }
-
- public void processListener(FacesListener listener) {
- throw new IllegalStateException();
- }
-
- /**
- * @return the rowKey
- */
- public Object getRowKey() {
- return rowKey;
- }
-}
Deleted: branches/RF-7560/core/impl/src/main/java/org/richfaces/component/SavedState.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/SavedState.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/SavedState.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,141 +0,0 @@
-/*
- * 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.io.Serializable;
-
-import javax.faces.component.EditableValueHolder;
-import javax.faces.component.UIForm;
-
-import org.ajax4jsf.component.IterationStateHolder;
-
-//from RI
-
-/**
- * This class keep values of {@link EditableValueHolder} row-sensitive
- * fields.
- *
- * @author shura
- */
-final class SavedState implements Serializable {
-
- public static final SavedState EMPTY = new SavedState();
-
- private static final long serialVersionUID = -1563864456074187422L;
-
- private boolean valid = true;
- private boolean localValueSet;
- private boolean submitted;
- private Object submittedValue;
- private Object value;
-
- private Object iterationState;
-
- public SavedState() {
- super();
- }
-
- public SavedState(EditableValueHolder evh) {
- super();
- this.value = evh.getLocalValue();
- this.valid = evh.isValid();
- this.submittedValue = evh.getSubmittedValue();
- this.localValueSet = evh.isLocalValueSet();
- }
-
- public SavedState(IterationStateHolder ish) {
- super();
-
- this.iterationState = ish.getIterationState();
- }
-
- public SavedState(UIForm form) {
- super();
- this.submitted = form.isSubmitted();
- }
-
- Object getSubmittedValue() {
- return this.submittedValue;
- }
-
- void setSubmittedValue(Object submittedValue) {
- this.submittedValue = submittedValue;
- }
-
- boolean isValid() {
- return this.valid;
- }
-
- void setValid(boolean valid) {
- this.valid = valid;
- }
-
- Object getValue() {
- return this.value;
- }
-
- void setValue(Object value) {
- this.value = value;
- }
-
- boolean isLocalValueSet() {
- return this.localValueSet;
- }
-
- void setLocalValueSet(boolean localValueSet) {
- this.localValueSet = localValueSet;
- }
-
- Object getIterationState() {
- return iterationState;
- }
-
- void setIterationState(Object iterationState) {
- this.iterationState = iterationState;
- }
-
- @Override
- public String toString() {
- if (iterationState != null) {
- return "iterationState: " + iterationState;
- } else {
- return "submittedValue: " + submittedValue + " value: " +
value + " localValueSet: " + localValueSet
- + " submitted: " + submitted;
- }
- }
-
- public void apply(EditableValueHolder evh) {
- evh.setValue(this.value);
- evh.setValid(this.valid);
- evh.setSubmittedValue(this.submittedValue);
- evh.setLocalValueSet(this.localValueSet);
- }
-
- public void apply(IterationStateHolder ish) {
- ish.setIterationState(iterationState);
- }
-
- public void apply(UIForm form) {
- form.setSubmitted(this.submitted);
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/SequenceIterationStatus.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/SequenceIterationStatus.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/SequenceIterationStatus.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,130 +0,0 @@
-/*
- * 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 java.io.Serializable;
-
-import javax.servlet.jsp.jstl.core.LoopTagStatus;
-
-/**
- * @author Nick Belaevski
- *
- */
-public final class SequenceIterationStatus implements LoopTagStatus, Serializable {
-
- private static final long serialVersionUID = 1968212566967489719L;
-
- private Integer begin;
-
- private Integer count;
-
- private Integer end;
-
- private int index;
-
- private Integer rowCount;
-
- private boolean first;
-
- private boolean last;
-
- private boolean even;
-
- public SequenceIterationStatus(Integer begin, Integer end, int index, Integer
rowCount) {
- int iBegin = (begin != null ? begin.intValue() : 0);
-
- int iRowCountEnd = (rowCount != null ? rowCount.intValue() - 1 :
Integer.MAX_VALUE);
- int iEnd = (end != null ? end.intValue() : iRowCountEnd);
- int iLastIdx = Math.min(iEnd, iRowCountEnd);
-
- this.begin = begin;
- this.end = iEnd;
- this.index = index;
- this.rowCount = rowCount;
-
- this.first = (index == iBegin);
-
- this.last = (index >= iLastIdx);
-
- this.count = (index - iBegin) + 1;
- this.even = ((count % 2) == 0);
- }
-
- public Integer getBegin() {
- return begin;
- }
-
- public int getCount() {
- return count;
- }
-
- public Object getCurrent() {
- return null;
- }
-
- public Integer getEnd() {
- return end;
- }
-
- public int getIndex() {
- return index;
- }
-
- public Integer getStep() {
- return 1;
- }
-
- public boolean isFirst() {
- return first;
- }
-
- public boolean isLast() {
- return last;
- }
-
- public Integer getRowCount() {
- return rowCount;
- }
-
- public boolean isEven() {
- return even;
- }
-
- public boolean isOdd() {
- return !isEven();
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("begin= " + begin);
- sb.append(", end= " + end);
- sb.append(", index= " + index);
- sb.append(", count= " + count);
- sb.append(", first= " + first);
- sb.append(", last= " + last);
- sb.append(", even= " + even);
- sb.append(", rowCount= " + rowCount);
-
- return sb.toString();
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,1516 +0,0 @@
-/*
- * 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.io.IOException;
-import java.io.Serializable;
-import java.text.MessageFormat;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import javax.el.ValueExpression;
-import javax.faces.FacesException;
-import javax.faces.application.Application;
-import javax.faces.application.FacesMessage;
-import javax.faces.component.ContextCallback;
-import javax.faces.component.EditableValueHolder;
-import javax.faces.component.NamingContainer;
-import javax.faces.component.PartialStateHolder;
-import javax.faces.component.StateHelper;
-import javax.faces.component.StateHolder;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIComponentBase;
-import javax.faces.component.UIForm;
-import javax.faces.component.UINamingContainer;
-import javax.faces.component.UIViewRoot;
-import javax.faces.component.UniqueIdVendor;
-import javax.faces.component.visit.VisitCallback;
-import javax.faces.component.visit.VisitContext;
-import javax.faces.component.visit.VisitResult;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.convert.ConverterException;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.ComponentSystemEvent;
-import javax.faces.event.ComponentSystemEventListener;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.ListenerFor;
-import javax.faces.event.PhaseId;
-import javax.faces.event.PostValidateEvent;
-import javax.faces.event.PreRenderComponentEvent;
-import javax.faces.event.PreValidateEvent;
-import javax.faces.render.Renderer;
-
-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.context.ExtendedVisitContext;
-import org.richfaces.log.Logger;
-import org.richfaces.log.RichfacesLogger;
-
-/**
- * Base class for iterable components, like dataTable, Tomahawk dataList, Facelets
repeat, tree etc., with support for
- * partial rendering on AJAX responces for one or more selected iterations.
- *
- * @author shura
- */
-@ListenerFor(systemEventClass = PreRenderComponentEvent.class)
-public abstract class UIDataAdaptor extends UIComponentBase implements NamingContainer,
- UniqueIdVendor, IterationStateHolder, ComponentSystemEventListener {
-
- /**
- * <p>The standard component family for this component.</p>
- */
- public static final String COMPONENT_FAMILY = "org.richfaces.Data";
-
- /**
- * <p>The standard component type for this component.</p>
- */
- public static final String COMPONENT_TYPE = "org.richfaces.Data";
-
- private static final class IterationState implements Serializable {
-
- private static final long serialVersionUID = -3502645160277416066L;
-
- private DataComponentState componentState;
-
- private Object savedComponentState;
-
- private boolean componentStateIsStateHolder;
-
- private ExtendedDataModel<?> dataModel;
-
- public IterationState() {
- super();
- }
-
- public IterationState(DataComponentState componentState,
ExtendedDataModel<?> dataModel) {
- super();
- this.componentState = componentState;
- this.dataModel = dataModel;
- }
-
- public ExtendedDataModel<?> getDataModel() {
- return dataModel;
- }
-
- public DataComponentState getComponentState() {
- return componentState;
- }
-
- /**
- * @param uiDataAdaptor
- */
- public void restoreComponentState(UIDataAdaptor uiDataAdaptor) {
- if (savedComponentState != null && componentStateIsStateHolder) {
- componentState = uiDataAdaptor.createComponentState();
- ((StateHolder)
componentState).restoreState(FacesContext.getCurrentInstance(), savedComponentState);
- savedComponentState = null;
- }
- }
-
- final Object saveState() {
- boolean localComponentStateIsHolder = false;
- Object localSavedComponentState = null;
-
- if (componentState != null) {
- if (componentState instanceof StateHolder) {
- localComponentStateIsHolder = true;
-
- StateHolder stateHolder = (StateHolder) componentState;
- if (!stateHolder.isTransient()) {
- localSavedComponentState =
stateHolder.saveState(FacesContext.getCurrentInstance());
- }
- } else {
- if (componentState instanceof Serializable) {
- localSavedComponentState = componentState;
- }
- }
- }
-
- Object savedSerializableModel = null;
-
- if (componentState != null && dataModel != null) {
- // TODO handle model serialization - "execute" model
- savedSerializableModel =
dataModel.getSerializableModel(componentState.getRange());
- }
-
- if (localSavedComponentState != null || savedSerializableModel != null) {
- return new Object[] {
- localComponentStateIsHolder,
- localSavedComponentState,
- savedSerializableModel
- };
- } else {
- return null;
- }
- }
-
- final void restoreState(Object stateObject) {
- if (stateObject != null) {
- Object[] state = (Object[]) stateObject;
- componentStateIsStateHolder = Boolean.TRUE.equals(state[0]);
- Object localSavedComponentState = state[1];
-
- if (componentStateIsStateHolder) {
- savedComponentState = localSavedComponentState;
- } else {
- componentState = (DataComponentState) localSavedComponentState;
- }
-
- dataModel = (ExtendedDataModel<?>) state[2];
- }
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws IOException {
-
- out.writeObject(saveState());
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws IOException, ClassNotFoundException {
-
- restoreState(in.readObject());
- }
- }
-
- private static final VisitCallback STUB_CALLBACK = new VisitCallback() {
-
- public VisitResult visit(VisitContext context, UIComponent target) {
- return VisitResult.ACCEPT;
- }
- };
-
- private static final Logger LOG = RichfacesLogger.COMPONENTS.getLogger();
-
- /**
- * Visitor for process decode on children components.
- */
- protected ComponentVisitor decodeVisitor = new ComponentVisitor() {
- @Override
- public void processComponent(FacesContext context, UIComponent c, Object
argument) {
- c.processDecodes(context);
- }
- };
-
- /**
- * Visitor for process validation phase
- */
- protected ComponentVisitor validateVisitor = new ComponentVisitor() {
- @Override
- public void processComponent(FacesContext context, UIComponent c, Object
argument) {
- c.processValidators(context);
- }
- };
-
- /**
- * Visitor for process update model phase.
- */
- protected ComponentVisitor updateVisitor = new ComponentVisitor() {
- @Override
- public void processComponent(FacesContext context, UIComponent c, Object
argument) {
- c.processUpdates(context);
- }
- };
-
- //TODO nick - PSH support?
- private DataComponentState componentState = null;
- private ExtendedDataModel<?> extendedDataModel = null;
- private Object rowKey = null;
-
- private String clientId;
-
- private Object originalVarValue;
-
- private Converter rowKeyConverter;
-
- /**
- * @author Nick Belaevski
- *
- */
- private final class DataVisitorForVisitTree implements DataVisitor {
- /**
- *
- */
- private final VisitCallback callback;
- /**
- *
- */
- private final VisitContext visitContext;
- /**
- *
- */
- private boolean visitResult;
-
- /**
- * @param callback
- * @param visitContext
- */
- private DataVisitorForVisitTree(VisitCallback callback, VisitContext
visitContext) {
- this.callback = callback;
- this.visitContext = visitContext;
- }
-
- public DataVisitResult process(FacesContext context, Object rowKey, Object
argument) {
- setRowKey(context, rowKey);
-
- if (isRowAvailable()) {
- VisitResult result = VisitResult.ACCEPT;
-
- if (visitContext instanceof ExtendedVisitContext) {
- result = visitContext.invokeVisitCallback(UIDataAdaptor.this,
callback);
- if (VisitResult.COMPLETE.equals(result)) {
- visitResult = true;
-
- return DataVisitResult.STOP;
- }
- }
-
- if (VisitResult.ACCEPT.equals(result)) {
- Iterator<UIComponent> dataChildrenItr = dataChildren();
-
- while (dataChildrenItr.hasNext()) {
- UIComponent dataChild = dataChildrenItr.next();
-
- if (dataChild.visitTree(visitContext, callback)) {
- visitResult = true;
-
- return DataVisitResult.STOP;
- }
- }
- }
- }
-
- return DataVisitResult.CONTINUE;
- }
-
- public boolean getVisitResult() {
- return visitResult;
- }
- }
-
- private enum PropertyKeys {
- lastId, var, rowKeyVar, stateVar, childState, rowKeyConverter,
rowKeyConverterSet, keepSaved
- }
-
- public UIDataAdaptor() {
- super();
- }
-
- protected Map<String, Object> getVariablesMap(FacesContext facesContext) {
- return facesContext.getExternalContext().getRequestMap();
- }
-
- /*
- * (non-Javadoc)
- * @see javax.faces.component.UIComponent#getFamily()
- */
- @Override
- public String getFamily() {
- return COMPONENT_FAMILY;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.component.AjaxChildrenEncoder#encodeAjaxChild(javax.faces.context.FacesContext,
- * java.lang.String, java.util.Set, java.util.Set)
- */
- public void encodeAjaxChild(FacesContext context, String path, Set<String> ids,
Set<String> renderedAreas)
- throws IOException {
-
- // TODO Auto-generated method stub
- }
-
- /*
- * (non-Javadoc)
- * @see
javax.faces.component.UniqueIdVendor#createUniqueId(javax.faces.context.FacesContext,
java.lang.String)
- */
- public String createUniqueId(FacesContext context, String seed) {
- Integer i = (Integer) getStateHelper().get(PropertyKeys.lastId);
- int lastId = (i != null) ? i : 0;
-
- getStateHelper().put(PropertyKeys.lastId, ++lastId);
-
- return UIViewRoot.UNIQUE_ID_PREFIX + ((seed == null) ? lastId : seed);
- }
-
- /**
- * @return the rowKey
- */
- public Object getRowKey() {
- return rowKey;
- }
-
- /**
- * Setup current row by key. Perform same functionality as
- * {@link javax.faces.component.UIData#setRowIndex(int)}, but for key object - it may
be not only
- * row number in sequence data, but, for example - path to current node in
- * tree.
- *
- * @param faces -
- * current FacesContext
- * @param key new key value.
- */
- public void setRowKey(FacesContext facesContext, Object rowKey) {
- this.saveChildState(facesContext);
- this.rowKey = rowKey;
- this.clientId = null;
- getExtendedDataModel().setRowKey(rowKey);
-
- boolean rowSelected = (rowKey != null) && isRowAvailable();
-
- setupVariable(facesContext, rowSelected);
- this.restoreChildState(facesContext);
- }
-
- /**
- * Save values of {@link EditableValueHolder} fields before change current
- * row.
- *
- * @param faces
- */
- protected void saveChildState(FacesContext facesContext) {
- Iterator<UIComponent> itr = dataChildren();
-
- while (itr.hasNext()) {
- this.saveChildState(facesContext, (UIComponent) itr.next());
- }
- }
-
- /**
- * @param facesContext
- * @param next
- * @param childState
- */
- protected void saveChildState(FacesContext facesContext, UIComponent component) {
-
- // TODO - is it right?
- if (component.isTransient()) {
- return;
- }
-
- SavedState state = null;
-
- if (component instanceof IterationStateHolder) {
- IterationStateHolder ish = (IterationStateHolder) component;
-
- state = new SavedState(ish);
- } else if (component instanceof EditableValueHolder) {
- EditableValueHolder evh = (EditableValueHolder) component;
-
- state = new SavedState(evh);
- } else if (component instanceof UIForm) {
- UIForm form = (UIForm) component;
-
- state = new SavedState(form);
- }
-
- if (state != null) {
-
- // TODO - use local map - children save their state themselves using
visitors
- getStateHelper().put(PropertyKeys.childState,
component.getClientId(facesContext), state);
- }
-
- if (component.getChildCount() > 0) {
- for (UIComponent child : component.getChildren()) {
- saveChildState(facesContext, child);
- }
- }
-
- if (component.getFacetCount() > 0) {
- for (UIComponent facet : component.getFacets().values()) {
- saveChildState(facesContext, facet);
- }
- }
- }
-
- protected Iterator<UIComponent> dataChildren() {
- if (getChildCount() > 0) {
- return getChildren().iterator();
- } else {
- return Collections.<UIComponent>emptyList().iterator();
- }
- }
-
- protected Iterator<UIComponent> fixedChildren() {
- if (getFacetCount() > 0) {
- return getFacets().values().iterator();
- } else {
- return Collections.<UIComponent>emptyList().iterator();
- }
- }
-
- /**
- * @param facesContext
- */
- protected void restoreChildState(FacesContext facesContext) {
- Iterator<UIComponent> itr = dataChildren();
-
- while (itr.hasNext()) {
- this.restoreChildState(facesContext, (UIComponent) itr.next());
- }
- }
-
- /**
- * Restore values of {@link EditableValueHolder} fields after change current
- * row.
- *
- * @param facesContext
- * @param next
- * @param childState
- */
- protected void restoreChildState(FacesContext facesContext, UIComponent component) {
- String id = component.getId();
-
- component.setId(id); // Forces client id to be reset
-
- SavedState savedState = null;
- @SuppressWarnings("unchecked")
- Map<String, SavedState> savedStatesMap = (Map<String, SavedState>)
getStateHelper()
- .get(PropertyKeys.childState);
-
- if (savedStatesMap != null) {
- savedState = savedStatesMap.get(component.getClientId(facesContext));
- }
-
- if (savedState == null) {
- savedState = SavedState.EMPTY;
- }
-
- if (component instanceof IterationStateHolder) {
- IterationStateHolder ish = (IterationStateHolder) component;
-
- savedState.apply(ish);
- } else if (component instanceof EditableValueHolder) {
- EditableValueHolder evh = (EditableValueHolder) component;
-
- savedState.apply(evh);
- } else if (component instanceof UIForm) {
- UIForm form = (UIForm) component;
-
- savedState.apply(form);
- }
-
- if (component.getChildCount() > 0) {
- for (UIComponent child : component.getChildren()) {
- restoreChildState(facesContext, child);
- }
- }
-
- if (component.getFacetCount() > 0) {
- for (UIComponent facet : component.getFacets().values()) {
- restoreChildState(facesContext, facet);
- }
- }
- }
-
- public void setRowKey(Object rowKey) {
- setRowKey(getFacesContext(), rowKey);
- }
-
- /*
- * (non-Javadoc)
- * @see
javax.faces.component.UIComponentBase#queueEvent(javax.faces.event.FacesEvent)
- */
- @Override
- public void queueEvent(FacesEvent event) {
- super.queueEvent(new RowKeyContextEventWrapper(this, event, getRowKey()));
- }
-
- /*
- * (non-Javadoc)
- * @see
javax.faces.component.UIComponentBase#broadcast(javax.faces.event.FacesEvent)
- */
- @Override
- public void broadcast(FacesEvent event) throws AbortProcessingException {
- if (!(event instanceof RowKeyContextEventWrapper)) {
- if (!broadcastLocal(event)) {
- super.broadcast(event);
- }
-
- return;
- }
-
- FacesContext context = getFacesContext();
-
- // Set up the correct context and fire our wrapped event
- RowKeyContextEventWrapper revent = (RowKeyContextEventWrapper) event;
- Object oldRowKey = getRowKey();
-
- setRowKey(context, revent.getRowKey());
-
- FacesEvent rowEvent = revent.getFacesEvent();
- UIComponent source = rowEvent.getComponent();
- UIComponent compositeParent = null;
-
- try {
- if (!UIComponent.isCompositeComponent(source)) {
- compositeParent = UIComponent.getCompositeComponentParent(source);
- }
-
- if (compositeParent != null) {
- compositeParent.pushComponentToEL(context, null);
- }
-
- source.pushComponentToEL(context, null);
- source.broadcast(rowEvent);
- } finally {
- source.popComponentFromEL(context);
-
- if (compositeParent != null) {
- compositeParent.popComponentFromEL(context);
- }
- }
-
- setRowKey(context, oldRowKey);
- }
-
- /**
- * Process events targetted for concrete implementation. Hook method called
- * from {@link #broadcast(FacesEvent)}
- *
- * @param event -
- * processed event.
- * @return true if event processed, false if component must continue
- * processing.
- */
-
- // TODO - is it still actual?
- protected boolean broadcastLocal(FacesEvent event) {
- return false;
- }
-
- /**
- * @return the extendedDataModel
- */
- protected ExtendedDataModel<?> getExtendedDataModel() {
- if (extendedDataModel == null) {
- extendedDataModel = createExtendedDataModel();
- }
-
- return extendedDataModel;
- }
-
- /**
- * @return
- */
- protected abstract ExtendedDataModel<?> createExtendedDataModel();
-
- /**
- * @param extendedDataModel the extendedDataModel to set
- */
- protected void setExtendedDataModel(ExtendedDataModel<?> extendedDataModel) {
- this.extendedDataModel = extendedDataModel;
- }
-
- public String getVar() {
- return (String) getStateHelper().get(PropertyKeys.var);
- }
-
- public void setVar(String var) {
- getStateHelper().put(PropertyKeys.var, var);
- }
-
- public String getRowKeyVar() {
- return (String) getStateHelper().get(PropertyKeys.rowKeyVar);
- }
-
- public void setRowKeyVar(String rowKeyVar) {
- getStateHelper().put(PropertyKeys.rowKeyVar, rowKeyVar);
- }
-
- public String getStateVar() {
- return (String) getStateHelper().get(PropertyKeys.stateVar);
- }
-
- public void setStateVar(String stateVar) {
- getStateHelper().put(PropertyKeys.stateVar, stateVar);
- }
-
- //XXX - review and probably remove - useful method, should be left
- public int getRowCount() {
- return getExtendedDataModel().getRowCount();
- }
-
- public Object getRowData() {
- return getExtendedDataModel().getRowData();
- }
-
- public boolean isRowAvailable() {
- return getExtendedDataModel().isRowAvailable();
- }
-
- /**
- * Boolean attribute that defines whether this iteration component will reset saved
children's state
- * before rendering. By default state is reset if there are no faces messages with
severity error or higher.
- * @return
- */
- public boolean isKeepSaved() {
- Object value = getStateHelper().eval(PropertyKeys.keepSaved);
-
- if (value == null) {
- return keepSaved(getFacesContext());
- } else {
- return Boolean.valueOf(value.toString());
- }
- }
-
- public void setKeepSaved(boolean keepSaved) {
- getStateHelper().put(PropertyKeys.keepSaved, keepSaved);
- }
-
- /**
- * Setup EL variable for different iteration. Value of row data and
- * component state will be put into request scope attributes with names
- * given by "var" and "varState" bean properties.
- * <p/>
- * Changed: does not check for row availability now
- *
- * @param faces current faces context
- * @param localModel
- * @param rowSelected
- */
- protected void setupVariable(FacesContext faces, boolean rowSelected) {
- Map<String, Object> attrs = getVariablesMap(faces);
-
- if (rowSelected) {
-
- // Current row data.
- setupVariable(getVar(), attrs, getRowData());
-
- // Component state variable.
- setupVariable(getStateVar(), attrs, getComponentState());
-
- // Row key Data variable.
- setupVariable(getRowKeyVar(), attrs, getRowKey());
- } else {
- removeVariable(getVar(), attrs);
- removeVariable(getStateVar(), attrs);
- removeVariable(getRowKeyVar(), attrs);
- }
- }
-
- /**
- * @return
- */
- public DataComponentState getComponentState() {
- if (componentState != null) {
- return componentState;
- }
-
- ValueExpression componentStateExpression =
getValueExpression("componentState");
-
- if (componentStateExpression != null) {
- componentState = (DataComponentState)
componentStateExpression.getValue(getFacesContext().getELContext());
- }
-
- if (componentState == null) {
- componentState = createComponentState();
-
- if ((componentStateExpression != null)
- &&
!componentStateExpression.isReadOnly(getFacesContext().getELContext())) {
- componentStateExpression.setValue(getFacesContext().getELContext(),
componentState);
- }
- }
-
- return componentState;
- }
-
- protected abstract DataComponentState createComponentState();
-
- /**
- * @param var
- * @param attrs
- * @param rowData
- */
- private void setupVariable(String var, Map<String, Object> attrs, Object
rowData) {
- if (var != null) {
- attrs.put(var, rowData);
- }
- }
-
- /**
- * @param var
- * @param attrs
- * @param rowData
- */
- private void removeVariable(String var, Map<String, Object> attrs) {
- if (var != null) {
- attrs.remove(var);
- }
- }
-
- public Converter getRowKeyConverter() {
- if (this.rowKeyConverter != null) {
- return this.rowKeyConverter;
- }
-
- return (Converter) getStateHelper().eval(PropertyKeys.rowKeyConverter);
- }
-
- public void setRowKeyConverter(Converter converter) {
- StateHelper stateHelper = getStateHelper();
- if (initialStateMarked()) {
- stateHelper.put(PropertyKeys.rowKeyConverterSet, Boolean.TRUE);
- }
-
- this.rowKeyConverter = converter;
- }
-
- private boolean isSetRowKeyConverter() {
- Boolean value = (Boolean) getStateHelper().get(PropertyKeys.rowKeyConverterSet);
- return Boolean.TRUE.equals(value);
- }
-
- @Override
- public String getClientId(FacesContext facesContext) {
- if (facesContext == null) {
- throw new NullPointerException("context");
- }
-
- if (null == clientId) {
- StringBuilder id = new StringBuilder(super.getClientId(facesContext));
- Object rowKey = getRowKey();
-
- if (rowKey != null) {
-
- // Use converter to get String representation ot the row key.
- Converter rowKeyConverter = getRowKeyConverter();
-
- if (null == rowKeyConverter) {
-
- // Create default converter for a row key.
- rowKeyConverter =
facesContext.getApplication().createConverter(rowKey.getClass());
-
- // Store converter for a invokeOnComponents call.
- if (null != rowKeyConverter) {
- // TODO - review
- setRowKeyConverter(rowKeyConverter);
- }
- }
-
- String rowKeyString;
-
- if (null != rowKeyConverter) {
-
- // Temporary set clientId, to avoid infinite calls from converter.
- clientId = id.toString();
- rowKeyString = rowKeyConverter.getAsString(facesContext, this,
rowKey);
- } else {
- rowKeyString = rowKey.toString();
- }
-
-
id.append(UINamingContainer.getSeparatorChar(facesContext)).append(rowKeyString);
- }
-
- Renderer renderer = getRenderer(facesContext);
-
- if (null != renderer) {
- clientId = renderer.convertClientId(facesContext, id.toString());
- } else {
- clientId = id.toString();
- }
- }
-
- return clientId;
- }
-
- /**
- * Save current state of data variable.
- *
- * @param faces current faces context
- */
-
- // TODO move into walk() method body
- public void captureOrigValue(FacesContext faces) {
- String var = getVar();
-
- if (var != null) {
- Map<String, Object> attrs = getVariablesMap(faces);
-
- this.originalVarValue = attrs.get(var);
- }
-
- // TODO add support for another variables
- }
-
- /**
- * Restore value of data variable after processing phase.
- *
- * @param faces current faces context
- */
- public void restoreOrigValue(FacesContext faces) {
- String var = getVar();
-
- if (var != null) {
- Map<String, Object> attrs = getVariablesMap(faces);
-
- if (this.originalVarValue != null) {
- attrs.put(var, this.originalVarValue);
- } else {
- attrs.remove(var);
- }
- }
- }
-
- /*
- * (non-Javadoc)
- * @see javax.faces.component.UIComponent#setValueExpression(java.lang.String,
javax.el.ValueExpression)
- */
- @Override
- public void setValueExpression(String name, ValueExpression binding) {
- if ("var".equals(name) || "rowKeyVar".equals(name) ||
"stateVar".equals(name)) {
- throw new IllegalArgumentException(MessageFormat.format("{0} cannot be
EL-expression", name));
- }
-
- super.setValueExpression(name, binding);
- }
-
- /**
- * Check for validation errors on children components. If true, saved values
- * must be keep on render phase
- *
- * @param context
- * @return
- */
- protected boolean keepSaved(FacesContext context) {
-
- // For an any validation errors, children components state should be preserved
- FacesMessage.Severity sev = context.getMaximumSeverity();
-
- return (sev != null) && (FacesMessage.SEVERITY_ERROR.compareTo(sev) >=
0);
- }
-
- /**
- * Perform iteration on all children components and all data rows with given
- * visitor.
- *
- * @param faces
- * @param visitor
- */
- protected void iterate(FacesContext faces, ComponentVisitor visitor) {
-
- // stop if not rendered
- if (!this.isRendered()) {
- return;
- }
-
- // reset rowIndex
- this.captureOrigValue(faces);
- this.setRowKey(faces, null);
-
- try {
- Iterator<UIComponent> fixedChildren = fixedChildren();
-
- while (fixedChildren.hasNext()) {
- UIComponent component = fixedChildren.next();
-
- visitor.processComponent(faces, component, null);
- }
-
- walk(faces, visitor, null);
- } catch (Exception e) {
- throw new FacesException(e);
- } finally {
- this.setRowKey(faces, null);
- this.restoreOrigValue(faces);
- }
- }
-
- /**
- * Walk ( visit ) this component on all data-aware children for each row.
- *
- * @param faces
- * @param visitor
- */
- public void walk(FacesContext faces, DataVisitor visitor, Object argument) {
- Object key = getRowKey();
- captureOrigValue(faces);
-
- Range range = null;
- DataComponentState componentState = getComponentState();
-
- if (componentState != null) {
- range = componentState.getRange();
- }
-
- getExtendedDataModel().walk(faces, visitor, range, argument);
-
- setRowKey(faces, key);
- restoreOrigValue(faces);
- }
-
- public void processDecodes(FacesContext faces) {
- if (!this.isRendered()) {
- return;
- }
-
- pushComponentToEL(faces, this);
- preDecode(faces);
- this.iterate(faces, decodeVisitor);
- this.decode(faces);
- popComponentFromEL(faces);
- }
-
- public void processValidators(FacesContext faces) {
- if (!this.isRendered()) {
- return;
- }
-
- pushComponentToEL(faces, this);
- Application app = faces.getApplication();
- app.publishEvent(faces, PreValidateEvent.class, this);
- preValidate(faces);
- this.iterate(faces, validateVisitor);
- app.publishEvent(faces, PostValidateEvent.class, this);
- popComponentFromEL(faces);
- }
-
- public void processUpdates(FacesContext faces) {
- if (!this.isRendered()) {
- return;
- }
-
- pushComponentToEL(faces, this);
- preUpdate(faces);
- this.iterate(faces, updateVisitor);
-
- ExtendedDataModel<?> dataModel = getExtendedDataModel();
-
- // If no validation errors, update values for serializable model,
- // restored from view.
- if ((dataModel instanceof SerializableDataModel) && (!isKeepSaved())) {
- SerializableDataModel serializableModel = (SerializableDataModel) dataModel;
-
- serializableModel.update();
- }
-
- popComponentFromEL(faces);
- }
-
- @Override
- public void setId(String id) {
- super.setId(id);
- this.clientId = null;
- }
-
- /*
- * (non-Javadoc)
- * @see org.ajax4jsf.component.IterationStateHolder#getIterationState()
- */
- public Object getIterationState() {
- assert rowKey == null;
-
- return new IterationState(this.componentState, this.extendedDataModel);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.component.IterationStateHolder#setIterationState(java.lang.Object)
- */
- public void setIterationState(Object stateObject) {
- assert rowKey == null;
-
- // TODO - ?
- // restoreChildState(getFacesContext());
- if (stateObject != null) {
- IterationState iterationState = (IterationState) stateObject;
- iterationState.restoreComponentState(this);
-
- this.componentState = iterationState.getComponentState();
- this.extendedDataModel = iterationState.getDataModel();
- } else {
- this.componentState = null;
- this.extendedDataModel = null;
- }
- }
-
- protected void resetDataModel() {
- this.extendedDataModel = null;
- }
-
- protected void resetChildState() {
- getStateHelper().remove(PropertyKeys.childState);
- }
-
- protected void preDecode(FacesContext context) {
- resetDataModel();
-
- Object savedChildState = getStateHelper().get(PropertyKeys.childState);
- // TODO - verify the check for null: savedChildState == null
- if (savedChildState == null || !isKeepSaved()) {
- resetChildState();
- }
- }
-
- // TODO - do we need this method?
- protected void preValidate(FacesContext context) {
- }
-
- // TODO - do we need this method?
- protected void preUpdate(FacesContext context) {
- }
-
- protected void preEncodeBegin(FacesContext context) {
- resetDataModel();
-
- if (!isKeepSaved()) {
- //TODO - this also resets state for the nested iteration components - is it
correct?
- resetChildState();
- }
- }
-
- @Override
- public void markInitialState() {
- super.markInitialState();
-
- if (rowKeyConverter instanceof PartialStateHolder) {
- ((PartialStateHolder) rowKeyConverter).markInitialState();
- }
- }
-
- @Override
- public void clearInitialState() {
- super.clearInitialState();
-
- if (rowKeyConverter instanceof PartialStateHolder) {
- ((PartialStateHolder) rowKeyConverter).clearInitialState();
- }
- }
-
- /*
- * (non-Javadoc)
- * @see
javax.faces.component.UIComponentBase#saveState(javax.faces.context.FacesContext)
- */
- @Override
- public Object saveState(FacesContext context) {
- Object parentState = super.saveState(context);
- Object savedComponentState = new IterationState(componentState,
extendedDataModel).saveState();
-
- Object converterState = null;
- boolean nullDelta = true;
-
- boolean converterHasPartialState = false;
-
- if (initialStateMarked()) {
- if (!isSetRowKeyConverter() && rowKeyConverter != null &&
rowKeyConverter instanceof PartialStateHolder) {
- // Delta
- StateHolder holder = (StateHolder) rowKeyConverter;
- if (!holder.isTransient()) {
- Object attachedState = holder.saveState(context);
- if (attachedState != null) {
- nullDelta = false;
- converterState = attachedState;
- }
- converterHasPartialState = true;
- } else {
- converterState = null;
- }
- } else if (isSetRowKeyConverter() || rowKeyConverter != null) {
- // Full
- converterState = saveAttachedState(context, rowKeyConverter);
- nullDelta = false;
- }
-
- if (parentState == null && savedComponentState == null &&
nullDelta) {
- // No values
- return null;
- }
- } else {
- converterState = saveAttachedState(context, rowKeyConverter);
- }
-
- return new Object[] {
- parentState,
- savedComponentState,
- converterHasPartialState,
- converterState
- };
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.component.UIComponentBase#restoreState(javax.faces.context.FacesContext,
java.lang.Object)
- */
- @Override
- public void restoreState(FacesContext context, Object stateObject) {
- if (stateObject == null) {
- return ;
- }
-
- Object[] state = (Object[]) stateObject;
-
- super.restoreState(context, state[0]);
-
- if (state[1] != null) {
- IterationState iterationState = new IterationState();
- iterationState.restoreState(state[1]);
- iterationState.restoreComponentState(this);
-
- // TODO update state model binding
- componentState = iterationState.getComponentState();
- extendedDataModel = iterationState.getDataModel();
- }
-
- boolean converterHasPartialState = Boolean.TRUE.equals(state[2]);
- Object savedConverterState = state[3];
- if (converterHasPartialState) {
- ((StateHolder) rowKeyConverter).restoreState(context, savedConverterState);
- } else {
- rowKeyConverter = (Converter) UIComponentBase.restoreAttachedState(context,
savedConverterState);
- }
- }
-
- private boolean matchesBaseId(String clientId, String baseId, char separatorChar) {
- if (clientId.equals(baseId)) {
- return true;
- }
-
- // if clientId.startsWith(baseId + separatorChar)
- if (clientId.startsWith(baseId) && (clientId.length() >
baseId.length())
- && (clientId.charAt(baseId.length()) == separatorChar)) {
- return true;
- }
-
- return false;
- }
-
- @Override
- public boolean invokeOnComponent(FacesContext context, String clientId,
ContextCallback callback)
- throws FacesException {
-
- if ((null == context) || (null == clientId) || (null == callback)) {
- throw new NullPointerException();
- }
-
- String baseId = super.getClientId(context);
-
- if (!matchesBaseId(clientId, baseId,
UINamingContainer.getSeparatorChar(context))) {
- return false;
- }
-
- boolean found = false;
- Object oldRowKey = getRowKey();
-
- // TODO - this does not seem right
- captureOrigValue(context);
-
- try {
-
- // TODO - ?
- // if (null != oldRowKey) {
- setRowKey(context, null);
-
- // }
- if (clientId.equals(baseId)) {
- callback.invokeContextCallback(context, this);
- found = true;
- } else {
- Iterator<UIComponent> fixedChildrenItr = fixedChildren();
-
- while (fixedChildrenItr.hasNext() && !found) {
- UIComponent fixedChild = fixedChildrenItr.next();
-
- found = fixedChild.invokeOnComponent(context, clientId, callback);
- }
- }
-
- if (!found) {
- Object newRowKey = null;
-
- // 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) {
- Converter keyConverter = getRowKeyConverter();
-
- if (null != keyConverter) {
- try {
- //TODO: review
- newRowKey = keyConverter.getAsObject(context, this,
rowKeyString);
- } catch (ConverterException e) {
-
- // TODO: LOG error
- }
- }
- }
-
- setRowKey(context, newRowKey);
-
- if (isRowAvailable()) {
- Iterator<UIComponent> dataChildrenItr = dataChildren();
-
- while (dataChildrenItr.hasNext() && !found) {
- UIComponent dataChild = dataChildrenItr.next();
-
- found = dataChild.invokeOnComponent(context, clientId,
callback);
- }
- }
- }
- } catch (Exception e) {
- throw new FacesException(e);
- } finally {
-
- // if (null != oldRowKey) {
- try {
- setRowKey(context, oldRowKey);
- restoreOrigValue(context);
- } catch (Exception e) {
- LOG.error(e.getMessage(), e);
- }
-
- // }
- }
-
- return found;
- }
-
- // Tests whether we need to visit our children as part of
- // a tree visit
- private boolean doVisitChildren(VisitContext context, boolean visitRows) {
-
- // Just need to check whether there are any ids under this
- // subtree. Make sure row index is cleared out since
- // getSubtreeIdsToVisit() needs our row-less client id.
-
- // TODO check this
- if (visitRows) {
- setRowKey(context.getFacesContext(), null);
- }
-
- // TODO optimize for returned IDs
- Collection<String> idsToVisit = context.getSubtreeIdsToVisit(this);
-
- assert idsToVisit != null;
-
- if (idsToVisit == VisitContext.ALL_IDS) {
- // TODO
- }
-
- // All ids or non-empty collection means we need to visit our children.
- return !idsToVisit.isEmpty();
- }
-
- private boolean visitComponents(Iterator<UIComponent> components, VisitContext
context, VisitCallback callback) {
-
- while (components.hasNext()) {
- UIComponent nextChild = components.next();
-
- if (nextChild.visitTree(context, callback)) {
- return true;
- }
- }
-
- return false;
- }
-
- protected boolean visitFixedChildren(VisitContext visitContext, VisitCallback
callback) {
-
- return visitComponents(fixedChildren(), visitContext, callback);
- }
-
- protected boolean visitDataChildren(VisitContext visitContext, VisitCallback
callback, boolean visitRows) {
-
- if (visitRows) {
- FacesContext facesContext = visitContext.getFacesContext();
-
- DataVisitorForVisitTree dataVisitor = new DataVisitorForVisitTree(callback,
visitContext);
- this.walk(facesContext, dataVisitor, null);
-
- return dataVisitor.getVisitResult();
- } else {
- return visitComponents(dataChildren(), visitContext, callback);
- }
- }
-
- @Override
- public boolean visitTree(VisitContext visitContext, VisitCallback callback) {
-
- // First check to see whether we are visitable. If not
- // short-circuit out of this subtree, though allow the
- // visit to proceed through to other subtrees.
- if (!isVisitable(visitContext)) {
- return false;
- }
-
- // Clear out the row index is one is set so that
- // we start from a clean slate.
- FacesContext facesContext = visitContext.getFacesContext();
-
- // NOTE: that the visitRows local will be obsolete once the
- // appropriate visit hints have been added to the API
- boolean visitRows = requiresRowIteration(facesContext);
-
- Object oldRowKey = null;
- if (visitRows) {
- captureOrigValue(facesContext);
- oldRowKey = getRowKey();
- setRowKey(facesContext, null);
- }
-
- // Push ourselves to EL
- pushComponentToEL(facesContext, null);
-
- try {
-
- // Visit ourselves. Note that we delegate to the
- // VisitContext to actually perform the visit.
- VisitResult result = visitContext.invokeVisitCallback(this, callback);
-
- // If the visit is complete, short-circuit out and end the visit
- if (result == VisitResult.COMPLETE) {
- return true;
- }
-
- // Visit children, short-circuiting as necessary
- if ((result == VisitResult.ACCEPT) && doVisitChildren(visitContext,
visitRows)) {
- if (visitRows) {
- setRowKey(facesContext, null);
- }
-
- if (visitFixedChildren(visitContext, callback)) {
- return true;
- }
-
- if (visitContext instanceof ExtendedVisitContext) {
- ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext)
visitContext;
-
- Collection<String> directSubtreeIdsToVisit =
extendedVisitContext.getDirectSubtreeIdsToVisit(this);
- if (directSubtreeIdsToVisit != VisitContext.ALL_IDS) {
- if (directSubtreeIdsToVisit.isEmpty()) {
- return false;
- } else {
- VisitContext directChildrenVisitContext =
-
extendedVisitContext.createNamingContainerVisitContext(this, directSubtreeIdsToVisit);
-
- if (visitRows) {
- setRowKey(facesContext, null);
- }
- if (visitFixedChildren(directChildrenVisitContext,
STUB_CALLBACK)) {
- return false;
- }
- }
- }
- }
-
- if (visitDataChildren(visitContext, callback, visitRows)) {
- return true;
- }
- }
- } finally {
-
- // Clean up - pop EL and restore old row index
- popComponentFromEL(facesContext);
-
- if (visitRows) {
- try {
- setRowKey(facesContext, oldRowKey);
- restoreOrigValue(facesContext);
- } catch (Exception e) {
-
- // TODO: handle exception
- LOG.error(e.getMessage(), e);
- }
- }
- }
-
- // Return false to allow the visit to continue
- return false;
- }
-
- /**
- * @param facesContext
- * @return
- */
- private boolean requiresRowIteration(FacesContext context) {
- return (!PhaseId.RESTORE_VIEW.equals(context.getCurrentPhaseId()));
- }
-
- /**
- * @param context
- * @param substring
- * @return
- */
- // TODO review!
- protected String extractKeySegment(FacesContext context, String substring) {
- char separatorChar = UINamingContainer.getSeparatorChar(context);
- int separatorIndex = substring.indexOf(separatorChar);
-
- if (separatorIndex < 0) {
- return substring;
- } else {
- return substring.substring(0, separatorIndex);
- }
- }
-
- /**
- * Base class for visit data model at phases decode, validation and update model
- *
- * @author shura
- */
- protected abstract class ComponentVisitor implements DataVisitor {
- public DataVisitResult process(FacesContext context, Object rowKey, Object
argument) {
- setRowKey(context, rowKey);
-
- if (isRowAvailable()) {
- Iterator<UIComponent> childIterator = dataChildren();
-
- while (childIterator.hasNext()) {
- UIComponent component = childIterator.next();
-
- processComponent(context, component, argument);
- }
- }
-
- return DataVisitResult.CONTINUE;
- }
-
- 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) {
- preEncodeBegin(getFacesContext());
- }
- }
-
- protected DataComponentState getLocalComponentState() {
- return componentState;
- }
-}
Deleted: branches/RF-7560/core/impl/src/main/java/org/richfaces/component/UISequence.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/UISequence.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/UISequence.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,305 +0,0 @@
-/*
- * 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.sql.ResultSet;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import javax.el.ValueExpression;
-import javax.faces.component.UINamingContainer;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.model.ArrayDataModel;
-import javax.faces.model.DataModel;
-import javax.faces.model.ListDataModel;
-import javax.faces.model.ResultDataModel;
-import javax.faces.model.ResultSetDataModel;
-import javax.faces.model.ScalarDataModel;
-import javax.servlet.jsp.jstl.sql.Result;
-
-import org.ajax4jsf.model.DataComponentState;
-import org.ajax4jsf.model.ExtendedDataModel;
-import org.ajax4jsf.model.Range;
-import org.ajax4jsf.model.SequenceDataModel;
-import org.ajax4jsf.model.SequenceRange;
-import org.ajax4jsf.model.SequenceState;
-
-/**
- * @author Nick Belaevski
- */
-public class UISequence extends UIDataAdaptor {
-
- private Object iterationStatusVarObject;
-
- protected enum PropertyKeys {
- first, rows, value, iterationStatusVar
- }
-
- protected void updateState(SequenceState state) {
- state.setFirst(getActualFirst());
- state.setRows(getActualRows());
- }
-
- protected void updateState() {
- DataComponentState localState = getLocalComponentState();
- if (localState instanceof SequenceState) {
- updateState((SequenceState) localState);
- }
- }
-
- protected int getActualFirst() {
- return getFirst();
- }
-
- protected int getActualRows() {
- return getRows();
- }
-
- @SuppressWarnings("unchecked")
- protected DataModel<?> createFacesModel(Object value) {
- DataModel<?> model = null;
-
- if (value == null) {
- model = new ListDataModel(Collections.EMPTY_LIST);
- } else if (value instanceof DataModel) {
- model = (DataModel) value;
- } else if (value instanceof List) {
- model = new ListDataModel((List) value);
- } else if (Object[].class.isAssignableFrom(value.getClass())) {
- model = new ArrayDataModel((Object[]) value);
- } else if (value instanceof ResultSet) {
- model = new ResultSetDataModel((ResultSet) value);
- } else if (value instanceof Result) {
- model = new ResultDataModel((Result) value);
- } else {
- model = new ScalarDataModel(value);
- }
-
- return model;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- protected ExtendedDataModel<?> createExtendedDataModel() {
- ExtendedDataModel<?> model = null;
-
- // Synthesize a DataModel around our current value if possible
- Object value = getValue();
-
- if (value instanceof ExtendedDataModel<?>) {
- model = (ExtendedDataModel<?>) value;
- } else {
- model = new SequenceDataModel(createFacesModel(value));
- }
-
- return model;
- }
-
- @Override
- protected DataComponentState createComponentState() {
- SequenceState state = new SequenceState();
-
- updateState(state);
-
- return state;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.component.UIDataAdaptor#getRowKeyConverter()
- */
-
- // TODO make this a property of model
-
- @Override
- public Converter getRowKeyConverter() {
- return getFacesContext().getApplication().createConverter(Integer.class);
- }
-
- public int getFirst() {
- return (Integer) getStateHelper().eval(PropertyKeys.first, 0);
- }
-
- public void setFirst(int first) {
- getStateHelper().put(PropertyKeys.first, first);
- updateState();
- }
-
- public int getRows() {
- return (Integer) getStateHelper().eval(PropertyKeys.rows, 0);
- }
-
- public void setRows(int rows) {
- getStateHelper().put(PropertyKeys.rows, rows);
- updateState();
- }
-
- public Object getValue() {
- return getStateHelper().eval(PropertyKeys.value);
- }
-
- public void setValue(Object value) {
- resetDataModel();
- getStateHelper().put(PropertyKeys.value, value);
- }
-
- public String getIterationStatusVar() {
- return (String) getStateHelper().get(PropertyKeys.iterationStatusVar);
- }
-
- public void setIterationStatusVar(String iterationStatusVar) {
- getStateHelper().put(PropertyKeys.iterationStatusVar, iterationStatusVar);
- }
-
- public int getRowIndex() {
- return getExtendedDataModel().getRowIndex();
- }
-
- @Override
- public void captureOrigValue(FacesContext faces) {
- super.captureOrigValue(faces);
-
- String iterationStatusVar = getIterationStatusVar();
- if (iterationStatusVar != null) {
- Map<String, Object> variablesMap = getVariablesMap(faces);
-
- iterationStatusVarObject = variablesMap.get(iterationStatusVar);
- }
- }
-
- @Override
- public void restoreOrigValue(FacesContext faces) {
- super.restoreOrigValue(faces);
-
- String iterationStatusVar = getIterationStatusVar();
- if (iterationStatusVar != null) {
- Map<String, Object> variablesMap = getVariablesMap(faces);
-
- if (iterationStatusVarObject != null) {
- variablesMap.put(iterationStatusVar, iterationStatusVarObject);
- } else {
- variablesMap.remove(iterationStatusVar);
- }
- }
- }
-
- @Override
- protected void setupVariable(FacesContext faces, boolean rowSelected) {
- super.setupVariable(faces, rowSelected);
-
- //TODO nick - should iterationStatus be available out of iteration?
- // if yes, better name than "iterationStatusVar" is
required
- String iterationStatusVar = getIterationStatusVar();
- if (iterationStatusVar != null) {
- Map<String, Object> requestMap = getVariablesMap(faces);
-
- if (rowSelected) {
- Integer begin = null;
- Integer end = null;
-
- Range range = getComponentState().getRange();
- if (range instanceof SequenceRange) {
- SequenceRange sequenceRange = (SequenceRange) range;
-
- begin = sequenceRange.getFirstRow();
- int iRows = sequenceRange.getRows();
-
- if (iRows > 0) {
- // end is zero-based
- end = begin + iRows - 1;
- }
- }
-
- SequenceIterationStatus iterationStatus = new
SequenceIterationStatus(begin, end,
- getRowIndex(), getRowCount());
-
- requestMap.put(iterationStatusVar, iterationStatus);
- } else {
- requestMap.remove(iterationStatusVar);
- }
- }
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public void setValueBinding(String name, javax.faces.el.ValueBinding binding) {
- if ("value".equals(name)) {
- resetDataModel();
- } else if ("first".equals(name) || "rows".equals(name)) {
- updateState();
- }
-
- super.setValueBinding(name, binding);
- }
-
- @Override
- public void setValueExpression(String name, ValueExpression binding) {
- if ("value".equals(name)) {
- resetDataModel();
- } else if ("first".equals(name) || "rows".equals(name)) {
- updateState();
- }
-
- super.setValueExpression(name, binding);
- }
-
- @Override
- protected void preEncodeBegin(FacesContext context) {
- super.preEncodeBegin(context);
-
- updateState();
- }
-
- public int getRelativeRowIndex() {
- int rowIndex = getRowIndex();
- int rows = getRows();
-
- if (rows > 1) {
- return rowIndex % rows;
- }
-
- return rowIndex;
- }
-
- public String getRelativeClientId(FacesContext facesContext) {
-
- //save current rowKey
- Object savedRowKey = getRowKey();
-
- setRowKey(null);
-
- //retrieve base client id without rowkey part
- StringBuilder baseId = new StringBuilder(getClientId(facesContext));
-
- //restore rowKey
- setRowKey(savedRowKey);
-
- String result =
baseId.append(UINamingContainer.getSeparatorChar(facesContext)).append(getRelativeRowIndex())
- .toString();
-
- return result;
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/CompositeRenderer.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/CompositeRenderer.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/CompositeRenderer.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,148 +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.renderkit;
-
-import org.ajax4jsf.renderkit.AjaxChildrenRenderer;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * @author Nick Belaevski - nbelaevski(a)exadel.com
- * created 18.12.2006
- */
-public abstract class CompositeRenderer extends AjaxChildrenRenderer {
- private static final Command MERGE_OPTIONS_COMMAND = new Command() {
- @Override
- protected void execute(RendererContributor renderer, FacesContext context,
UIComponent component,
- Object argument) {
- ScriptOptions initialOptions = (ScriptOptions) argument;
- ScriptOptions builtOptions = renderer.buildOptions(context, component);
-
- if (builtOptions != null) {
- initialOptions.merge(builtOptions);
- }
- }
- };
- private static final Command GET_SCRIPT_CONTRIBUTIONS = new Command() {
- @Override
- protected void execute(RendererContributor renderer, FacesContext context,
UIComponent component,
- Object argument) {
- String contribution = renderer.getScriptContribution(context, component);
-
- if (contribution != null) {
- ((List<String>) argument).add(contribution);
- }
- }
- };
- private List<RendererContributor> renderers = new
ArrayList<RendererContributor>();
- private List<AttributeParametersEncoder> parameterEncoders = new
ArrayList<AttributeParametersEncoder>();
- private final Command decodeCommand = new Command() {
- @Override
- protected void execute(RendererContributor renderer, FacesContext context,
UIComponent component,
- Object argument) {
- renderer.decode(context, component, CompositeRenderer.this);
- }
- };
-
- @Override
- protected void doDecode(FacesContext context, UIComponent component) {
- super.doDecode(context, component);
- decodeCommand.execute(renderers.iterator(), context, component, null,
component.getClass());
- }
-
- protected void mergeScriptOptions(ScriptOptions scriptOptions, FacesContext context,
UIComponent component) {
- mergeScriptOptions(scriptOptions, context, component, null);
- }
-
- protected void mergeScriptOptions(ScriptOptions scriptOptions, FacesContext context,
UIComponent component,
- Class<?> acceptableClass) {
- MERGE_OPTIONS_COMMAND.execute(renderers.iterator(), context, component,
scriptOptions, acceptableClass);
- }
-
- protected String getScriptContributions(String varString, FacesContext context,
UIComponent component) {
- return getScriptContributions(varString, context, component,
component.getClass());
- }
-
- protected String getScriptContributions(String varString, FacesContext context,
UIComponent component,
- Class<?> acceptableClass) {
- List<String> scriptContributions = new ArrayList<String>();
-
- GET_SCRIPT_CONTRIBUTIONS.execute(renderers.iterator(), context, component,
scriptContributions,
- acceptableClass);
-
- StringBuffer result = new StringBuffer();
-
- for (Iterator<String> itr = scriptContributions.iterator(); itr.hasNext();)
{
- result.append(varString);
- result.append(itr.next());
- }
-
- return result.toString();
- }
-
- protected void addContributor(RendererContributor renderer) {
- renderers.add(renderer);
- }
-
- protected RendererContributor[] getContributors() {
- return (RendererContributor[]) renderers.toArray(new
RendererContributor[renderers.size()]);
- }
-
- protected void addParameterEncoder(AttributeParametersEncoder encoder) {
- parameterEncoders.add(encoder);
- }
-
- protected AttributeParametersEncoder[] getParameterEncoders() {
- return (AttributeParametersEncoder[]) parameterEncoders.toArray(
- new AttributeParametersEncoder[renderers.size()]);
- }
-
- public void encodeAttributeParameters(FacesContext context, UIComponent component)
throws IOException {
- for (Iterator<AttributeParametersEncoder> iterator =
parameterEncoders.iterator(); iterator.hasNext();) {
- AttributeParametersEncoder encoder = iterator.next();
-
- encoder.doEncode(context, component);
- }
- }
-
- private abstract static class Command {
- protected final void execute(Iterator<?> renderers, FacesContext
facesContext, UIComponent component,
- Object argument, Class<?> clazz) {
- while (renderers.hasNext()) {
- RendererContributor contributor = (RendererContributor)
renderers.next();
- Class<?> acceptableClass = contributor.getAcceptableClass();
-
- if ((clazz == null) || (acceptableClass == null) ||
acceptableClass.isAssignableFrom(clazz)) {
- execute(contributor, facesContext, component, argument);
- }
- }
- }
-
- protected abstract void execute(RendererContributor renderer, FacesContext
facesContext, UIComponent component,
- Object argument);
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/InputRendererBase.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/InputRendererBase.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/InputRendererBase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,84 +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.renderkit;
-
-import org.ajax4jsf.renderkit.AjaxComponentRendererBase;
-import org.ajax4jsf.util.SelectUtils;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIInput;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.convert.ConverterException;
-import java.util.Map;
-
-/**
- * @author Nick Belaevski - nbelaevski(a)exadel.com
- * created 23.01.2007
- */
-public class InputRendererBase extends AjaxComponentRendererBase {
- protected Class getComponentClass() {
- return UIInput.class;
- }
-
- protected void doDecode(FacesContext context, UIComponent component) {
- String clientId = component.getClientId(context);
- Map requestParameterMap = context.getExternalContext().getRequestParameterMap();
- String newValue = (String) requestParameterMap.get(clientId);
-
- if (null != newValue) {
- UIInput input = (UIInput) component;
-
- input.setSubmittedValue(newValue);
- }
- }
-
- public Object getConvertedValue(FacesContext context, UIComponent component, Object
val) throws ConverterException {
- return SelectUtils.getConvertedUIInputValue(context, (UIInput) component,
(String) val);
- }
-
- public String getInputValue(FacesContext context, UIComponent component) {
- UIInput input = (UIInput) component;
- String value = (String) input.getSubmittedValue();
-
- if (value == null) {
- Object curVal = input.getValue();
- Converter converter = SelectUtils.getConverterForProperty(context, input,
"value");
-
- if (converter != null) {
- value = converter.getAsString(context, input, curVal);
- } else {
- if (curVal == null) {
- value = "";
- } else {
- value = curVal.toString();
- }
- }
- }
-
- if (value == null) {
- value = "";
- }
-
- return value;
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/MacroDefinitionJSContentHandler.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/MacroDefinitionJSContentHandler.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/MacroDefinitionJSContentHandler.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,241 +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.renderkit;
-
-import org.richfaces.javacc.RichMacroDefinition;
-import org.richfaces.json.JSContentHandler;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-import java.io.FilterWriter;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * @author Nick Belaevski - mailto:nbelaevski@exadel.com created 21.06.2007
- */
-public class MacroDefinitionJSContentHandler extends JSContentHandler {
- private String epilog;
- private String prolog;
-
- public MacroDefinitionJSContentHandler(Writer writer, String prolog, String epilog)
{
- super(writer);
- this.prolog = prolog;
- this.epilog = epilog;
- }
-
- protected List<?> parseExpressiion(String expressionString) throws SAXException
{
- try {
- if (expressionString.length() != 0) {
- List<?> result = new RichMacroDefinition(new
StringReader(expressionString)).expression();
-
- return result;
- } else {
- List<Object> list = new ArrayList<Object>(1);
-
- list.add("");
-
- return list;
- }
- } catch (Exception e) {
- throw new SAXException(e.getMessage(), e);
- }
- }
-
- private void encodeExpressionString(String string) throws IOException, SAXException
{
-
- /*
- * if (string.length() == 0) {
- * this.outputWriter.write("\'\'");
- * }
- */
- List<?> parsedExpressiion = parseExpressiion(string);
- boolean isExpression = false;
-
- for (Iterator<?> iterator = parsedExpressiion.iterator();
iterator.hasNext();) {
- Object next = (Object) iterator.next();
-
- if (next instanceof Expression) {
- isExpression = true;
-
- break;
- }
- }
-
- if (isExpression) {
- this.outputWriter.write("function (context) { return ");
- }
-
- boolean first = true;
-
- for (Iterator<?> iterator = parsedExpressiion.iterator();
iterator.hasNext();) {
- Object next = (Object) iterator.next();
-
- if (next == null) {
- continue;
- }
-
- if (!first) {
- this.outputWriter.write('+');
- }
-
- if (next instanceof Expression) {
- Expression macroExpression = (Expression) next;
-
- this.outputWriter.write(prolog);
- this.encode(macroExpression.getExpression().toString());
- this.outputWriter.write(epilog);
- } else {
- this.outputWriter.write('\'');
- this.encode(next.toString());
- this.outputWriter.write('\'');
- }
-
- first = false;
- }
-
- if (isExpression) {
- this.outputWriter.write(";}");
- }
- }
-
- protected void encodeAttributeValue(Attributes attributes, int idx) throws
SAXException, IOException {
- String value = attributes.getValue(idx);
-
- encodeExpressionString(value);
- }
-
- public void characters(char[] ch, int start, int length) throws SAXException {
- if (isProcessingCdata()) {
- super.characters(ch, start, length);
- } else {
- Writer oldWriter = outputWriter;
-
- outputWriter = new WellFormedWriter(oldWriter);
-
- try {
- List<?> parsedExpression = parseExpressiion(new String(ch, start,
length));
-
- for (Iterator<?> iterator = parsedExpression.iterator();
iterator.hasNext();) {
- Object next = iterator.next();
-
- if (next instanceof Expression) {
- Expression expression = (Expression) next;
-
- if (this.isBeforeDocumentStart() || (level < 0)) {
- return;
- }
-
- try {
- if ((level != 0) && !this.closeElement(false)
&& !this.isProcessingCdata()) {
- this.outputWriter.write(',');
- }
-
- if (!this.isProcessingCdata()) {
- this.outputWriter.write("new ET(");
- }
-
- this.outputWriter.write("function (context) { return
");
- this.outputWriter.write(prolog);
- this.encode(expression.getExpression().toString());
- this.outputWriter.write(epilog);
- this.outputWriter.write("}");
-
- if (!this.isProcessingCdata()) {
- this.outputWriter.write(")");
- }
- } catch (IOException e) {
- throw new SAXException("Write error", e);
- }
- } else {
- char[] cs = next.toString().toCharArray();
-
- super.characters(cs, 0, cs.length);
- }
-
- if (iterator.hasNext()) {
- try {
- this.outputWriter.write(',');
- } catch (IOException e) {
-
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- } finally {
- outputWriter = oldWriter;
- }
- }
- }
-
- protected void encodeText(char[] chars, int start, int length) throws SAXException,
IOException {
- if (!isProcessingCdata()) {
- String str = new String(chars, start, length);
-
- encodeExpressionString(str);
- } else {
- super.encodeText(chars, start, length);
- }
- }
-
- /**
- * Writer will not output duplicate commas
- *
- * @author Maksim Kaszynski
- */
- static class WellFormedWriter extends FilterWriter {
- private char lastChar;
-
- public WellFormedWriter(Writer out) {
- super(out);
- }
-
- public void write(char[] cbuf, int off, int len) throws IOException {
-
- // Skip comma
- while ((cbuf[off] == lastChar) && (lastChar == ',')
&& (len > 0)) {
- off++;
- len--;
- }
-
- while ((len > 1) && (cbuf[off] == cbuf[off + 1]) &&
(cbuf[off] == ',')) {
- len--;
- off++;
- }
-
- super.write(cbuf, off, len);
- lastChar = cbuf[off + len - 1];
- }
-
- public void write(int c) throws IOException {
- if ((c != lastChar) || (lastChar != ',')) {
- super.write(c);
- lastChar = (char) c;
- }
- }
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/RendererContributor.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/RendererContributor.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/RendererContributor.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,41 +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.renderkit;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-/**
- * @author Nick Belaevski - nbelaevski(a)exadel.com
- * created 18.12.2006
- */
-public interface RendererContributor extends ScriptOptionsContributor {
- public String getScriptContribution(FacesContext context, UIComponent component);
-
- public void decode(FacesContext context, UIComponent component, CompositeRenderer
compositeRenderer);
-
- public String[] getScriptDependencies();
-
- public String[] getStyleDependencies();
-
- public Class<?> getAcceptableClass();
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/SequenceRendererHelper.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/SequenceRendererHelper.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/SequenceRendererHelper.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,100 +0,0 @@
-/*
- * 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.renderkit;
-
-import org.richfaces.component.UISequence;
-import org.richfaces.component.util.HtmlUtil;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class SequenceRendererHelper {
-
- private UISequence sequence;
-
- private int rowIndex = -1;
-
- private int columnIndex = 0;
-
- private String[] rowClasses = null;
-
- private String[] columnClasses = null;
-
- public SequenceRendererHelper(UISequence sequence) {
- super();
- this.sequence = sequence;
-
- this.rowClasses = splitClassesString((String)
sequence.getAttributes().get("rowClasses"));
- this.columnClasses = splitClassesString((String)
sequence.getAttributes().get("columnClasses"));
- }
-
- private static String[] splitClassesString(String s) {
- if (s != null) {
- return s.split(",");
- }
-
- return null;
- }
-
- private static String getCorrespondingArrayItem(String[] strings, int idx) {
- if (strings != null && strings.length > 0) {
- return strings[idx % strings.length];
- }
-
- return null;
- }
-
- public UISequence getSequence() {
- return sequence;
- }
-
- private void initialize() {
- rowIndex = sequence.getRowIndex();
- }
-
- public void nextRow() {
- if (rowIndex == -1) {
- initialize();
- }
-
- rowIndex++;
- columnIndex = 0;
- }
-
- public void nextColumn() {
- columnIndex++;
- }
-
- public String getRowClass() {
- String rowClass = (String) sequence.getAttributes().get("rowClass");
- return HtmlUtil.concatClasses(getCorrespondingArrayItem(rowClasses, rowIndex),
rowClass);
- }
-
- public String getColumnClass() {
- return getCorrespondingArrayItem(columnClasses, columnIndex);
- }
-
- public boolean hasWalkedOverRows() {
- return rowIndex != -1;
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,98 +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.renderkit;
-
-import org.ajax4jsf.io.SAXResponseWriter;
-import org.ajax4jsf.renderkit.RendererBase;
-import org.richfaces.component.TemplateComponent;
-import org.xml.sax.ContentHandler;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.io.Writer;
-
-/**
- * @author Nick Belaevski - mailto:nbelaevski@exadel.com
- * created 22.06.2007
- */
-public abstract class TemplateEncoderRendererBase extends RendererBase {
- public final boolean getRendersChildren() {
- return true;
- }
-
- protected void writeScriptBody(FacesContext context, UIComponent component, boolean
children) throws IOException {
- ResponseWriter writer = context.getResponseWriter();
- ContentHandler handler = createContentHandler(writer);
- SAXResponseWriter saxResponseWriter = new SAXResponseWriter(handler);
-
- context.setResponseWriter(saxResponseWriter);
-
- TemplateComponent templateComponent = null;
-
- if (component instanceof TemplateComponent) {
- templateComponent = (TemplateComponent) component;
- }
-
- try {
- if (templateComponent != null) {
- templateComponent.startTemplateEncode();
- }
-
- saxResponseWriter.startDocument();
-
- // TODO - how to handle extra "root" element?
- saxResponseWriter.startElement("root", component);
-
- if (children) {
- this.renderChildren(context, component);
- } else {
- component.encodeAll(context);
- }
-
- saxResponseWriter.endElement("root");
- saxResponseWriter.endDocument();
- } finally {
- if (templateComponent != null) {
- templateComponent.endTemplateEncode();
- }
-
- context.setResponseWriter(writer);
- }
- }
-
- public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
- ResponseWriter writer = context.getResponseWriter();
-
- writer.startElement("script", component);
- writer.write("var evaluator = ");
- writeScriptBody(context, component, true);
- writer.write(";\n new Insertion.Top($('" +
component.getClientId(context)
- + "'), evaluator.invoke('getContent',
window).join(''));");
- writer.endElement("script");
- }
-
- protected ContentHandler createContentHandler(Writer writer) {
- return new MacroDefinitionJSContentHandler(writer,
"Richfaces.evalMacro(\"", "\", context)");
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/richfaces/webapp/taglib/SimpleComponentTag.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/webapp/taglib/SimpleComponentTag.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/webapp/taglib/SimpleComponentTag.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,169 +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.webapp.taglib;
-
-import javax.el.MethodExpression;
-import javax.el.ValueExpression;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIComponentBase;
-import javax.faces.component.UIInput;
-import javax.faces.el.MethodBinding;
-
-/**
- * @author Maksim Kaszynski
- */
-public class SimpleComponentTag extends UIComponentELTagBase {
- private MethodExpression action;
- private MethodExpression actionListener;
- private ValueExpression converter;
- private MethodExpression legacyBinding;
- private MethodExpression methodExpression;
- private ValueExpression title;
- private MethodExpression validator;
- private ValueExpression value;
- private MethodExpression valueChangeListener;
-
- public SimpleComponentTag() {
-
- // TODO Auto-generated constructor stub
- }
-
- @Override
- public String getComponentType() {
- return UIInput.COMPONENT_TYPE;
- }
-
- @Override
- public String getRendererType() {
- return "javax.faces.Text";
- }
-
- @Override
- protected void setProperties(UIComponent component) {
- super.setProperties(component);
-
- MyUIComponent myUIComponent = (MyUIComponent) component;
-
- myUIComponent.setValueExpression("value", value);
- setActionListenerProperty(myUIComponent, actionListener);
- setActionProperty(myUIComponent, action);
- setConverterProperty(myUIComponent, converter);
- setValidatorProperty(myUIComponent, validator);
-
- if (methodExpression != null) {
- myUIComponent.setMethodExpression(methodExpression);
- }
-
- if (legacyBinding != null) {
- myUIComponent.setLegacyMethodBinding(new
MethodBindingMethodExpressionAdaptor(legacyBinding));
- }
- }
-
- @Override
- public void release() {
- super.release();
- }
-
- public void setAction(MethodExpression action) {
- this.action = action;
- }
-
- public MethodExpression getAction() {
- return action;
- }
-
- public MethodExpression getActionListener() {
- return actionListener;
- }
-
- public void setActionListener(MethodExpression listener) {
- actionListener = listener;
- }
-
- public MethodExpression getValueChangeListener() {
- return valueChangeListener;
- }
-
- public void setValueChangeListener(MethodExpression changeListener) {
- valueChangeListener = changeListener;
- }
-
- public MethodExpression getValidator() {
- return validator;
- }
-
- public void setValidator(MethodExpression validator) {
- this.validator = validator;
- }
-
- public ValueExpression getConverter() {
- return converter;
- }
-
- public void setConverter(ValueExpression converter) {
- this.converter = converter;
- }
-
- public ValueExpression getTitle() {
- return title;
- }
-
- public void setTitle(ValueExpression title) {
- this.title = title;
- }
-
- public ValueExpression getValue() {
- return value;
- }
-
- public void setValue(ValueExpression value) {
- this.value = value;
- }
-
- static class MyUIComponent extends UIComponentBase {
- private MethodBinding legacyMethodBinding;
- private MethodExpression methodExpression;
-
- @Override
- public String getFamily() {
-
- // TODO Auto-generated method stub
- return null;
- }
-
- public MethodBinding getLegacyMethodBinding() {
- return legacyMethodBinding;
- }
-
- public void setLegacyMethodBinding(MethodBinding legacyMethodBinding) {
- this.legacyMethodBinding = legacyMethodBinding;
- }
-
- public MethodExpression getMethodExpression() {
- return methodExpression;
- }
-
- public void setMethodExpression(MethodExpression methodExpression) {
- this.methodExpression = methodExpression;
- }
- }
-}
Deleted:
branches/RF-7560/core/impl/src/main/java/org/richfaces/webapp/taglib/UIComponentELTagBase.java
===================================================================
---
branches/RF-7560/core/impl/src/main/java/org/richfaces/webapp/taglib/UIComponentELTagBase.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/main/java/org/richfaces/webapp/taglib/UIComponentELTagBase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,135 +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.webapp.taglib;
-
-import org.ajax4jsf.Messages;
-import org.richfaces.component.UIDataAdaptor;
-
-import javax.el.MethodExpression;
-import javax.el.ValueExpression;
-import javax.faces.component.ActionSource2;
-import javax.faces.component.EditableValueHolder;
-import javax.faces.component.UIComponent;
-import javax.faces.component.ValueHolder;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.event.MethodExpressionActionListener;
-import javax.faces.event.MethodExpressionValueChangeListener;
-import javax.faces.validator.MethodExpressionValidator;
-import javax.faces.webapp.UIComponentELTag;
-
-/**
- * @author Maksim Kaszynski
- */
-public abstract class UIComponentELTagBase extends UIComponentELTag {
- protected void setActionListenerProperty(UIComponent component, MethodExpression
actionListener) {
- if (actionListener != null) {
- if (component instanceof ActionSource2) {
- ActionSource2 actionSource2 = (ActionSource2) component;
-
- actionSource2.addActionListener(new
MethodExpressionActionListener(actionListener));
- } else {
- throw new
IllegalArgumentException(Messages.getMessage(Messages.NO_ACTION_SOURCE2_ERROR,
- component.getClientId(getFacesContext())));
- }
- }
- }
-
- protected void setActionProperty(UIComponent component, MethodExpression action) {
- if (action != null) {
- if (component instanceof ActionSource2) {
- ActionSource2 actionSource2 = (ActionSource2) component;
-
- actionSource2.setActionExpression(action);
- } else {
- throw new
IllegalArgumentException(Messages.getMessage(Messages.NO_ACTION_SOURCE2_ERROR,
- component.getClientId(getFacesContext())));
- }
- }
- }
-
- protected void setConverterProperty(UIComponent component, ValueExpression converter)
{
- if (converter != null) {
- if (component instanceof ValueHolder) {
- ValueHolder output = (ValueHolder) component;
-
- if (!converter.isLiteralText()) {
- component.setValueExpression("converter", converter);
- } else {
- Converter conv =
FacesContext.getCurrentInstance().getApplication().createConverter(
- converter.getExpressionString());
-
- output.setConverter(conv);
- }
- } else {
- throw new
IllegalArgumentException(Messages.getMessage(Messages.NO_VALUE_HOLDER_ERROR,
- component.getClass().getName()));
- }
- }
- }
-
- protected void setRowKeyConverterProperty(UIComponent component, ValueExpression
converter) {
- if (converter != null) {
- if (component instanceof UIDataAdaptor) {
- UIDataAdaptor data = (UIDataAdaptor) component;
-
- if (!converter.isLiteralText()) {
- component.setValueExpression("rowKeyConverter",
converter);
- } else {
- Converter conv =
FacesContext.getCurrentInstance().getApplication().createConverter(
- converter.getExpressionString());
-
- data.setRowKeyConverter(conv);
- }
- } else {
- throw new
IllegalArgumentException(Messages.getMessage(Messages.NO_DATA_ADAPTOR,
- component.getClass().getName()));
- }
- }
- }
-
- protected void setValidatorProperty(UIComponent component, MethodExpression
validator) {
- if (validator != null) {
- if (component instanceof EditableValueHolder) {
- EditableValueHolder input = (EditableValueHolder) component;
-
- input.addValidator(new MethodExpressionValidator(validator));
- } else {
- throw new
IllegalArgumentException(Messages.getMessage(Messages.NO_EDITABLE_VALUE_HOLDER_ERROR,
- component.getId()));
- }
- }
- }
-
- protected void setValueChangeListenerProperty(UIComponent component, MethodExpression
valueChangeListener) {
- if (valueChangeListener != null) {
- if (component instanceof EditableValueHolder) {
- EditableValueHolder input = (EditableValueHolder) component;
-
- input.addValueChangeListener(new
MethodExpressionValueChangeListener(valueChangeListener));
- } else {
- throw new
IllegalArgumentException(Messages.getMessage(Messages.NO_EDITABLE_VALUE_HOLDER_ERROR,
- component.getId()));
- }
- }
- }
-}
Deleted:
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/DataAdaptorTestCase.java
===================================================================
---
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/DataAdaptorTestCase.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/DataAdaptorTestCase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,503 +0,0 @@
-/*
- * 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(facesContext, 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(facesContext, 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(facesContext, 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(facesContext, 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(facesContext, 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(facesContext, rowKey);
- childAdaptor.setRowKey(facesContext, childKey);
-
- assertNull(input.getSubmittedValue());
- assertNull(input.getLocalValue());
- assertTrue(input.isValid());
- assertFalse(input.isLocalValueSet());
-
- input.setSubmittedValue("submittedValue");
- input.setValue("value");
-
- childAdaptor.setRowKey(facesContext, null);
- mockDataAdaptor.setRowKey(facesContext, Integer.valueOf(3));
- childAdaptor.setRowKey(facesContext, Integer.valueOf(0));
-
- assertNull(input.getSubmittedValue());
- assertNull(input.getLocalValue());
- assertFalse(input.isLocalValueSet());
-
- childAdaptor.setRowKey(facesContext, null);
- mockDataAdaptor.setRowKey(facesContext, rowKey);
- childAdaptor.setRowKey(facesContext, 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(facesContext, Integer.valueOf(1));
- assertEquals(data.get(1), getVarValue());
-
- new ValueChangeEvent(input, null, "testValue").queue();
- mockDataAdaptor.setRowKey(facesContext, 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;
- }
-
-}
Deleted:
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/MockDataAdaptor.java
===================================================================
---
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/MockDataAdaptor.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/MockDataAdaptor.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,66 +0,0 @@
-/*
- * 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.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);
- }
-
-}
Deleted:
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/MockDataAdaptorComponentState.java
===================================================================
---
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/MockDataAdaptorComponentState.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/MockDataAdaptorComponentState.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,39 +0,0 @@
-/*
- * 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;
- }
-}
Deleted:
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/SequenceIterationStatusTest.java
===================================================================
---
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/SequenceIterationStatusTest.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/SequenceIterationStatusTest.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,158 +0,0 @@
-/*
- * 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 static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-
-/**
- * @author Nick Belaevski
- *
- */
-public class SequenceIterationStatusTest {
-
- @Test
- public void testBeginEnd() throws Exception {
- SequenceIterationStatus s1 = new SequenceIterationStatus(5, 10, 5, 100);
- assertEquals(Integer.valueOf(5), s1.getBegin());
- assertEquals(Integer.valueOf(10), s1.getEnd());
-
- SequenceIterationStatus s2 = new SequenceIterationStatus(null, null, 5, 100);
- assertNull(s2.getBegin());
- assertEquals(Integer.valueOf(99), s2.getEnd());
-
- SequenceIterationStatus s3 = new SequenceIterationStatus(null, null, 5, null);
- assertNull(s3.getBegin());
- assertEquals(Integer.valueOf(Integer.MAX_VALUE), s3.getEnd());
- }
-
- @Test
- public void testFirst() throws Exception {
- SequenceIterationStatus s1 = new SequenceIterationStatus(0, 10, 0, 100);
- assertTrue(s1.isFirst());
- assertFalse(s1.isLast());
-
- SequenceIterationStatus s2 = new SequenceIterationStatus(0, 10, 1, 100);
- assertFalse(s2.isFirst());
- assertFalse(s2.isLast());
-
- SequenceIterationStatus s3 = new SequenceIterationStatus(0, 0, 0, 100);
- assertTrue(s3.isFirst());
- assertTrue(s3.isLast());
-
- SequenceIterationStatus s4 = new SequenceIterationStatus(5, 10, 5, 100);
- assertTrue(s4.isFirst());
- assertFalse(s4.isLast());
-
- SequenceIterationStatus s5 = new SequenceIterationStatus(5, 10, 6, 100);
- assertFalse(s5.isFirst());
- assertFalse(s5.isLast());
-
- SequenceIterationStatus s6 = new SequenceIterationStatus(null, 10, 0, 100);
- assertTrue(s6.isFirst());
- assertFalse(s6.isLast());
- }
-
- @Test
- public void testLast() throws Exception {
- SequenceIterationStatus s1 = new SequenceIterationStatus(0, 9, 9, 100);
- assertTrue(s1.isLast());
- assertFalse(s1.isFirst());
-
- SequenceIterationStatus s2 = new SequenceIterationStatus(0, 9, 8, 100);
- assertFalse(s2.isLast());
- assertFalse(s2.isFirst());
-
- SequenceIterationStatus s3 = new SequenceIterationStatus(0, 100, 9, 10);
- assertTrue(s3.isLast());
- assertFalse(s3.isFirst());
-
- SequenceIterationStatus s4 = new SequenceIterationStatus(0, 100, 8, 10);
- assertFalse(s4.isLast());
- assertFalse(s4.isFirst());
-
- SequenceIterationStatus s5 = new SequenceIterationStatus(0, null, 9, 10);
- assertTrue(s5.isLast());
- assertFalse(s5.isFirst());
-
- SequenceIterationStatus s6 = new SequenceIterationStatus(0, null, 8, 10);
- assertFalse(s6.isLast());
- assertFalse(s6.isFirst());
- }
-
- @Test
- public void testIsEvenOdd() throws Exception {
- SequenceIterationStatus s1 = new SequenceIterationStatus(0, 100, 0, 10);
- assertTrue(s1.isOdd());
- assertFalse(s1.isEven());
-
- SequenceIterationStatus s2 = new SequenceIterationStatus(0, 100, 1, 10);
- assertTrue(s2.isEven());
- assertFalse(s2.isOdd());
-
- SequenceIterationStatus s3 = new SequenceIterationStatus(5, 100, 7, 10);
- assertTrue(s3.isOdd());
- assertFalse(s3.isEven());
-
- SequenceIterationStatus s4 = new SequenceIterationStatus(5, 100, 6, 10);
- assertTrue(s4.isEven());
- assertFalse(s4.isOdd());
- }
-
- @Test
- public void testGetRowCount() throws Exception {
- SequenceIterationStatus s1 = new SequenceIterationStatus(0, 100, 0, 200);
- assertEquals(Integer.valueOf(200), s1.getRowCount());
-
- SequenceIterationStatus s2 = new SequenceIterationStatus(0, 400, 100, 150);
- assertEquals(Integer.valueOf(150), s2.getRowCount());
- }
-
- @Test
- public void testGetIndex() throws Exception {
- SequenceIterationStatus s1 = new SequenceIterationStatus(0, 100, 30, 200);
- assertTrue(30 == s1.getIndex());
-
- SequenceIterationStatus s2 = new SequenceIterationStatus(0, 400, 100, 150);
- assertTrue(100 == s2.getIndex());
- }
-
- @Test
- public void testGetCount() throws Exception {
- SequenceIterationStatus s1 = new SequenceIterationStatus(0, 100, 0, 10);
- assertTrue(s1.getCount() == 1);
-
- SequenceIterationStatus s2 = new SequenceIterationStatus(0, 100, 1, 10);
- assertTrue(s2.getCount() == 2);
-
- SequenceIterationStatus s3 = new SequenceIterationStatus(5, 100, 7, 10);
- assertTrue(s3.getCount() == 3);
-
- SequenceIterationStatus s4 = new SequenceIterationStatus(5, 100, 8, 10);
- assertTrue(s4.getCount() == 4);
- }
-}
Modified:
branches/RF-7560/core/impl/src/test/java/org/richfaces/context/AjaxTableComponentImpl.java
===================================================================
---
branches/RF-7560/core/impl/src/test/java/org/richfaces/context/AjaxTableComponentImpl.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/test/java/org/richfaces/context/AjaxTableComponentImpl.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -19,21 +19,29 @@
* 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.context;
+import java.util.Collection;
+
import javax.faces.component.UIComponent;
+import javax.faces.component.UIData;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
import javax.faces.component.visit.VisitResult;
+import javax.faces.context.FacesContext;
-import org.richfaces.component.UISequence;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
/**
* @author Nick Belaevski
*
*/
-public class AjaxTableComponentImpl extends UISequence {
+public class AjaxTableComponentImpl extends UIData {
+ private static final Logger LOG = RichfacesLogger.COMPONENTS.getLogger();
+
private boolean visitMetaComponent(String name, ExtendedVisitContext visitContext,
VisitCallback callback) {
UIComponent facet = getFacet(name);
if (facet != null) {
@@ -51,7 +59,81 @@
}
}
+ private boolean doVisitChildren(VisitContext context) {
+ // TODO optimize for returned IDs
+ Collection<String> idsToVisit = context.getSubtreeIdsToVisit(this);
+
+ assert idsToVisit != null;
+
+ if (idsToVisit == VisitContext.ALL_IDS) {
+ // TODO
+ }
+
+ // All ids or non-empty collection means we need to visit our children.
+ return !idsToVisit.isEmpty();
+ }
+
@Override
+ public boolean visitTree(VisitContext visitContext, VisitCallback callback) {
+
+ // First check to see whether we are visitable. If not
+ // short-circuit out of this subtree, though allow the
+ // visit to proceed through to other subtrees.
+ if (!isVisitable(visitContext)) {
+ return false;
+ }
+
+ // Clear out the row index is one is set so that
+ // we start from a clean slate.
+ FacesContext facesContext = visitContext.getFacesContext();
+
+ int oldRowIndex = getRowIndex();
+ setRowIndex(-1);
+
+ // Push ourselves to EL
+ pushComponentToEL(facesContext, null);
+
+ try {
+
+ // Visit ourselves. Note that we delegate to the
+ // VisitContext to actually perform the visit.
+ VisitResult result = visitContext.invokeVisitCallback(this, callback);
+
+ // If the visit is complete, short-circuit out and end the visit
+ if (result == VisitResult.COMPLETE) {
+ return true;
+ }
+
+ // Visit children, short-circuiting as necessary
+ if ((result == VisitResult.ACCEPT) && doVisitChildren(visitContext))
{
+ setRowIndex(-1);
+
+ if (visitFixedChildren(visitContext, callback)) {
+ return true;
+ }
+
+ if (visitDataChildren(visitContext, callback)) {
+ return true;
+ }
+ }
+ } finally {
+
+ // Clean up - pop EL and restore old row index
+ popComponentFromEL(facesContext);
+
+ try {
+ setRowIndex(oldRowIndex);
+ } catch (Exception e) {
+
+ // TODO: handle exception
+ LOG.error(e.getMessage(), e);
+ }
+ }
+
+ // Return false to allow the visit to continue
+ return false;
+ }
+
protected boolean visitFixedChildren(VisitContext visitContext, VisitCallback
callback) {
if (visitContext instanceof ExtendedVisitContext) {
@@ -67,8 +149,38 @@
return false;
} else {
- return super.visitFixedChildren(visitContext, callback);
+ for (UIComponent facet: getFacets().values()) {
+ if (facet.visitTree(visitContext, callback)) {
+ return true;
+ }
+ }
+
+ return false;
}
}
+ protected boolean visitDataChildren(VisitContext visitContext, VisitCallback
callback) {
+ int rowIndex = 0;
+
+ for (setRowIndex(rowIndex); isRowAvailable(); setRowIndex(++rowIndex)) {
+ VisitResult result = visitContext.invokeVisitCallback(this, callback);
+
+ if (result == VisitResult.COMPLETE) {
+ return true;
+ }
+
+ if (result == VisitResult.REJECT) {
+ continue;
+ }
+
+ for (UIComponent child: getChildren()) {
+ if (child.visitTree(visitContext, callback)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
}
Modified:
branches/RF-7560/core/impl/src/test/java/org/richfaces/context/ExtendedPartialVisitContextTest.java
===================================================================
---
branches/RF-7560/core/impl/src/test/java/org/richfaces/context/ExtendedPartialVisitContextTest.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/test/java/org/richfaces/context/ExtendedPartialVisitContextTest.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -44,6 +44,7 @@
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.Application;
+import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;
import javax.faces.component.UIOutput;
@@ -76,17 +77,21 @@
* <h:outputText id="theHeader" />
* </f:facet>
*
- * <a4j:outputText id="nestedOutput"
value="#{item}" />
+ * <h:column>
+ * <a4j:outputText id="nestedOutput"
value="#{item}" />
*
- * <h:outputText id="nestedText"
value="#{item}" />
+ * <h:outputText id="nestedText"
value="#{item}" />
*
- * <a4j:table id="nestedTable"
value="['Nested item 0',... ,'Nested item 2']"
var="nestedItem">
- * <f:facet name="footer">
- * <h:outputText id="nestedTableFooter"
value="#{item}" />
- * </f:facet>
+ * <a4j:table id="nestedTable"
value="['Nested item 0',... ,'Nested item 2']"
var="nestedItem">
+ * <f:facet name="footer">
+ * <h:outputText id="nestedTableFooter"
value="#{item}" />
+ * </f:facet>
*
- * <h:outputText id="nestedTableText"
value="#{nestedItem}" />
- * </a4j:table>
+ * <h:column>
+ * <h:outputText id="nestedTableText"
value="#{nestedItem}" />
+ * </h:column>
+ * </a4j:table>
+ * </h:column>
* </a4j:table>
* </h:form>
* </pre>
@@ -220,7 +225,7 @@
nestedText.setId("nestedText");
nestedText.setValueExpression("value",
createTableVarValueExpression());
- table.getChildren().add(nestedText);
+ table.getChildren().get(0).getChildren().add(nestedText);
}
private void createNestedOutput() {
@@ -229,7 +234,7 @@
nestedOutput.setId("nestedOutput");
nestedOutput.setValueExpression("value",
createTableVarValueExpression());
- table.getChildren().add(nestedOutput);
+ table.getChildren().get(0).getChildren().add(nestedOutput);
}
private void createOuterOutput() {
@@ -255,7 +260,9 @@
createNestedTableData();
nestedTable.setValue(nestedTableData);
- table.getChildren().add(nestedTable);
+ nestedTable.getChildren().add(new UIColumn());
+
+ table.getChildren().get(0).getChildren().add(nestedTable);
createNestedTableText();
createNestedTableFooter();
@@ -274,7 +281,7 @@
nestedTableText.setId("nestedTableText");
nestedTableText.setValueExpression("value",
createNestedTableVarValueExpression());
- nestedTable.getChildren().add(nestedTableText);
+ nestedTable.getChildren().get(0).getChildren().add(nestedTableText);
}
private void createTable() {
@@ -285,6 +292,8 @@
createTableData();
table.setValue(tableData);
+ table.getChildren().add(new UIColumn());
+
form.getChildren().add(table);
createNestedOutput();
createNestedText();
@@ -478,7 +487,7 @@
assertEqualSets(tableClientIds, renderingContext.getSubtreeIdsToVisit(table));
assertEqualSets(tableIds, renderingContext.getDirectSubtreeIdsToVisit(table));
- table.setRowKey(Integer.valueOf(0));
+ table.setRowIndex(0);
Set<String> nestedTableClientIds =
asSet("myForm:table:0:nestedTable:1",
"myForm:table:0:nestedTable:nestedFooter");
@@ -487,7 +496,7 @@
assertEqualSets(nestedTableClientIds,
renderingContext.getSubtreeIdsToVisit(nestedTable));
assertEqualSets(nestedTableIds,
renderingContext.getDirectSubtreeIdsToVisit(nestedTable));
- table.setRowKey(null);
+ table.setRowIndex(-1);
}
@Test
@@ -503,7 +512,7 @@
assertSame(VisitContext.ALL_IDS,
renderingContext.getDirectSubtreeIdsToVisit(table));
for (int i = 0; i < tableData.size(); i++) {
- table.setRowKey(Integer.valueOf(i));
+ table.setRowIndex(i);
assertSame(VisitContext.ALL_IDS,
renderingContext.getSubtreeIdsToVisit(table));
assertEqualSets(asSet("nestedText", "nestedTable",
"nestedOutput"),
@@ -513,7 +522,7 @@
assertEqualSets(asSet("0"),
renderingContext.getDirectSubtreeIdsToVisit(nestedTable));
}
- table.setRowKey(null);
+ table.setRowIndex(-1);
}
@Test
@@ -529,7 +538,7 @@
assertSame(VisitContext.ALL_IDS,
renderingContext.getDirectSubtreeIdsToVisit(table));
for (int i = 0; i < tableData.size(); i++) {
- table.setRowKey(Integer.valueOf(i));
+ table.setRowIndex(i);
assertSame(VisitContext.ALL_IDS,
renderingContext.getSubtreeIdsToVisit(table));
assertEqualSets(asSet("nestedText", "nestedTable"),
renderingContext.getDirectSubtreeIdsToVisit(table));
@@ -538,7 +547,7 @@
assertEqualSets(asSet("0"),
renderingContext.getDirectSubtreeIdsToVisit(nestedTable));
}
- table.setRowKey(null);
+ table.setRowIndex(-1);
}
@Test
@@ -553,7 +562,7 @@
assertSame(VisitContext.ALL_IDS,
renderingContext.getDirectSubtreeIdsToVisit(table));
for (int i = 0; i < tableData.size(); i++) {
- table.setRowKey(Integer.valueOf(i));
+ table.setRowIndex(i);
assertSame(VisitContext.ALL_IDS,
renderingContext.getSubtreeIdsToVisit(table));
assertEqualSets(asSet("nestedTable"),
renderingContext.getDirectSubtreeIdsToVisit(table));
@@ -562,7 +571,7 @@
assertTrue(renderingContext.getDirectSubtreeIdsToVisit(nestedTable).isEmpty());
}
- table.setRowKey(null);
+ table.setRowIndex(-1);
}
@Test
Deleted:
branches/RF-7560/core/impl/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java
===================================================================
---
branches/RF-7560/core/impl/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,368 +0,0 @@
-package org.richfaces.renderkit;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.Arrays;
-import java.util.Map;
-
-import javax.faces.component.NamingContainer;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIForm;
-import javax.faces.component.UIInput;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
-import org.jboss.test.faces.AbstractFacesTest;
-
-public class CompositeRendererTest extends AbstractFacesTest {
- private CompositeRenderer compositeRenderer;
-
- public void setUp() throws Exception {
- super.setUp();
- setupFacesRequest();
- this.compositeRenderer = new CompositeRenderer() {
- protected Class<? extends UIComponent> getComponentClass() {
- return UIComponent.class;
- }
- };
- }
-
- public void tearDown() throws Exception {
- super.tearDown();
- this.compositeRenderer = null;
- }
-
- public final void testDoDecodeFacesContextUIComponent() {
- MockDecodeContributor[] contributors = new MockDecodeContributor[5];
-
- for (int i = 0; i < contributors.length; i++) {
- contributors[i] = new MockDecodeContributor();
- compositeRenderer.addContributor(contributors[i]);
- }
-
- UIInput component = new UIInput();
-
- compositeRenderer.doDecode(facesContext, component);
-
- for (int i = 0; i < contributors.length; i++) {
- assertSame(compositeRenderer, contributors[i].getRenderer());
- assertSame(facesContext, contributors[i].getContext());
- assertSame(component, contributors[i].getComponent());
- }
- }
-
- public final void testMergeScriptOptionsScriptOptionsFacesContextUIComponent() {
- UIInput input = new UIInput();
- ScriptOptions inputOptions = new ScriptOptions(input);
-
- inputOptions.addOption("input", "1");
-
- ScriptOptions formOptions = new ScriptOptions(input);
-
- formOptions.addOption("form", "2");
-
- ScriptOptions options = new ScriptOptions(input);
-
- options.addOption("generic", "3");
-
- MockDecodeContributor inputContributor;
- MockDecodeContributor formContributor;
- MockDecodeContributor contributor;
- MockDecodeContributor nullContributor;
-
- inputContributor = new MockDecodeContributor(UIComponent.class, inputOptions);
- formContributor = new MockDecodeContributor(UIComponent.class, formOptions);
- contributor = new MockDecodeContributor(UIComponent.class, options);
- nullContributor = new MockDecodeContributor(UIComponent.class, (ScriptOptions)
null);
- compositeRenderer.addContributor(contributor);
- compositeRenderer.addContributor(formContributor);
- compositeRenderer.addContributor(inputContributor);
- compositeRenderer.addContributor(nullContributor);
-
- ScriptOptions scriptOptions = new ScriptOptions(input);
-
- compositeRenderer.mergeScriptOptions(scriptOptions, facesContext, input);
-
- Map map = scriptOptions.getMap();
-
- assertEquals(3, map.size());
- assertEquals("1", map.get("input"));
- assertEquals("2", map.get("form"));
- assertEquals("3", map.get("generic"));
- }
-
- public final void testMergeScriptOptionsScriptOptionsFacesContextUIComponentClass()
{
- UIInput input = new UIInput();
- ScriptOptions inputOptions = new ScriptOptions(input);
-
- inputOptions.addOption("input", "1");
-
- ScriptOptions formOptions = new ScriptOptions(input);
-
- formOptions.addOption("form", "2");
-
- ScriptOptions options = new ScriptOptions(input);
-
- options.addOption("generic", "3");
-
- MockDecodeContributor inputContributor;
- MockDecodeContributor formContributor;
- MockDecodeContributor contributor;
- MockDecodeContributor nullContributor;
-
- inputContributor = new MockDecodeContributor(UIInput.class, inputOptions);
- formContributor = new MockDecodeContributor(NamingContainer.class, formOptions);
- contributor = new MockDecodeContributor(UIComponent.class, options);
- nullContributor = new MockDecodeContributor(UIForm.class, (ScriptOptions) null);
- compositeRenderer.addContributor(contributor);
- compositeRenderer.addContributor(formContributor);
- compositeRenderer.addContributor(inputContributor);
- compositeRenderer.addContributor(nullContributor);
-
- ScriptOptions scriptOptions = new ScriptOptions(input);
-
- compositeRenderer.mergeScriptOptions(scriptOptions, facesContext, input,
UIForm.class);
-
- Map map = scriptOptions.getMap();
-
- assertEquals(2, map.size());
- assertEquals("2", map.get("form"));
- assertEquals("3", map.get("generic"));
- }
-
- public final void testGetScriptContributionsStringFacesContextUIComponent() {
- MockDecodeContributor inputContributor;
- MockDecodeContributor formContributor;
- MockDecodeContributor contributor;
- MockDecodeContributor nullContributor;
-
- inputContributor = new MockDecodeContributor(UIComponent.class,
".1;");
- formContributor = new MockDecodeContributor(UIComponent.class, ".2;");
- contributor = new MockDecodeContributor(UIComponent.class, ".3;");
- nullContributor = new MockDecodeContributor(UIForm.class, (String) null);
- compositeRenderer.addContributor(contributor);
- compositeRenderer.addContributor(formContributor);
- compositeRenderer.addContributor(inputContributor);
- compositeRenderer.addContributor(nullContributor);
-
- UIInput input = new UIInput();
-
- input.getAttributes().put("test", ".testValue");
-
- String contributions =
compositeRenderer.getScriptContributions("theVar", facesContext, input);
-
-
assertEquals("theVar.testValue.3;theVar.testValue.2;theVar.testValue.1;",
contributions);
- }
-
- public final void testGetScriptContributionsStringFacesContextUIComponentClass() {
- MockDecodeContributor inputContributor;
- MockDecodeContributor formContributor;
- MockDecodeContributor contributor;
- MockDecodeContributor nullContributor;
-
- inputContributor = new MockDecodeContributor(UIInput.class,
".input;");
- formContributor = new MockDecodeContributor(NamingContainer.class,
".namingContainer;");
- contributor = new MockDecodeContributor(UIComponent.class,
".generic;");
- nullContributor = new MockDecodeContributor(UIForm.class, (String) null);
- compositeRenderer.addContributor(contributor);
- compositeRenderer.addContributor(formContributor);
- compositeRenderer.addContributor(inputContributor);
- compositeRenderer.addContributor(nullContributor);
-
- UIInput input = new UIInput();
-
- input.getAttributes().put("test", ".testValue");
-
- String contributions =
compositeRenderer.getScriptContributions("theVar", facesContext, input,
UIForm.class);
-
-
assertEquals("theVar.testValue.generic;theVar.testValue.namingContainer;",
contributions);
- }
-
- public final void testAddContributor() {
- MockDecodeContributor[] contributors = new MockDecodeContributor[5];
-
- for (int i = 0; i < contributors.length; i++) {
- contributors[i] = new MockDecodeContributor();
- compositeRenderer.addContributor(contributors[i]);
- }
-
- assertTrue(Arrays.deepEquals(contributors,
compositeRenderer.getContributors()));
- }
-
- public final void testContributorDecodeCallback() {
- MockDecodeContributor inputContributor;
- MockDecodeContributor formContributor;
-
- formContributor = new MockDecodeContributor(NamingContainer.class);
- inputContributor = new MockDecodeContributor(UIInput.class);
- compositeRenderer.addContributor(inputContributor);
- compositeRenderer.addContributor(formContributor);
-
- UIComponent component = new UIInput();
-
- compositeRenderer.doDecode(facesContext, component);
- assertSame(compositeRenderer, inputContributor.getRenderer());
- assertSame(facesContext, inputContributor.getContext());
- assertSame(component, inputContributor.getComponent());
- assertNull(formContributor.getRenderer());
- assertNull(formContributor.getContext());
- assertNull(formContributor.getComponent());
- inputContributor.reset();
- formContributor.reset();
- assertNull(inputContributor.getRenderer());
- assertNull(inputContributor.getContext());
- assertNull(inputContributor.getComponent());
- assertNull(formContributor.getRenderer());
- assertNull(formContributor.getContext());
- assertNull(formContributor.getComponent());
- component = new UIForm();
- compositeRenderer.doDecode(facesContext, component);
- assertSame(compositeRenderer, formContributor.getRenderer());
- assertSame(facesContext, formContributor.getContext());
- assertSame(component, formContributor.getComponent());
- assertNull(inputContributor.getRenderer());
- assertNull(inputContributor.getContext());
- assertNull(inputContributor.getComponent());
- }
-
- public final void testAddParameterEncoder() {
- MockAttributeParameterEncoder[] encoders = new MockAttributeParameterEncoder[5];
-
- for (int i = 0; i < encoders.length; i++) {
- encoders[i] = new MockAttributeParameterEncoder("aaa");
- compositeRenderer.addParameterEncoder(encoders[i]);
- }
-
- assertTrue(Arrays.deepEquals(encoders,
compositeRenderer.getParameterEncoders()));
- }
-
- public final void testEncodeAttributeParameters() throws IOException {
- MockAttributeParameterEncoder encoder1 = new
MockAttributeParameterEncoder("Attribute");
- MockAttributeParameterEncoder encoder2 = new
MockAttributeParameterEncoder("MoreAttribute");
-
- compositeRenderer.addParameterEncoder(encoder1);
- compositeRenderer.addParameterEncoder(encoder2);
-
- UIInput input = new UIInput();
-
- input.getAttributes().put("Attribute", "testValue1");
- input.getAttributes().put("MoreAttribute", "testValue2");
-
- // ResponseWriter responseWriter = facesContext.getResponseWriter();
- StringWriter stringWriter = new StringWriter();
- ResponseWriter responseWriter =
facesContext.getRenderKit().createResponseWriter(stringWriter, "text/html",
- "UTF8");
-
- facesContext.setResponseWriter(responseWriter);
- responseWriter.startDocument();
- responseWriter.startElement("span", input);
- compositeRenderer.encodeAttributeParameters(facesContext, input);
- responseWriter.endElement("span");
- responseWriter.endDocument();
- responseWriter.flush();
-
- String result = stringWriter.getBuffer().toString();
-
- assertTrue(result.contains("testAttribute=\"testValue1\""));
-
assertTrue(result.contains("testMoreAttribute=\"testValue2\""));
- }
-}
-
-
-class MockAttributeParameterEncoder implements AttributeParametersEncoder {
- private String attributeName;
-
- public MockAttributeParameterEncoder(String attributeName) {
- super();
- this.attributeName = attributeName;
- }
-
- public void doEncode(FacesContext context, UIComponent component) throws IOException
{
- context.getResponseWriter().writeAttribute("test" + attributeName,
- component.getAttributes().get(attributeName), null);
- }
-}
-
-
-class MockDecodeContributor implements RendererContributor {
- private UIComponent component;
- private Class componentClass;
- private FacesContext context;
- private ScriptOptions options;
- private CompositeRenderer renderer;
- private String scriptContribution;
- private String[] scriptDependencies;
- private String[] styleDependencies;
-
- public MockDecodeContributor() {
- this(UIComponent.class);
- }
-
- public MockDecodeContributor(Class componentClass) {
- super();
- this.componentClass = componentClass;
- }
-
- public MockDecodeContributor(Class componentClass, ScriptOptions options) {
- super();
- this.componentClass = componentClass;
- this.options = options;
- }
-
- public MockDecodeContributor(Class componentClass, String scriptContribution) {
- super();
- this.componentClass = componentClass;
- this.scriptContribution = scriptContribution;
- }
-
- public MockDecodeContributor(Class componentClass, String[] scriptDependencies,
String[] styleDependencies) {
- super();
- this.componentClass = componentClass;
- this.scriptDependencies = scriptDependencies;
- this.styleDependencies = styleDependencies;
- }
-
- public void decode(FacesContext context, UIComponent component, CompositeRenderer
compositeRenderer) {
- this.component = component;
- this.context = context;
- this.renderer = compositeRenderer;
- }
-
- public Class getAcceptableClass() {
- return componentClass;
- }
-
- public String getScriptContribution(FacesContext context, UIComponent component) {
- return scriptContribution != null ?
component.getAttributes().get("test") + scriptContribution : null;
- }
-
- public String[] getScriptDependencies() {
- return scriptDependencies;
- }
-
- public String[] getStyleDependencies() {
- return styleDependencies;
- }
-
- public ScriptOptions buildOptions(FacesContext context, UIComponent component) {
- return options;
- }
-
- public UIComponent getComponent() {
- return component;
- }
-
- public FacesContext getContext() {
- return context;
- }
-
- public CompositeRenderer getRenderer() {
- return renderer;
- }
-
- public void reset() {
- this.component = null;
- this.context = null;
- this.renderer = null;
- }
-}
Deleted:
branches/RF-7560/core/impl/src/test/java/org/richfaces/renderkit/TemplateEncoderRendererBaseTest.java
===================================================================
---
branches/RF-7560/core/impl/src/test/java/org/richfaces/renderkit/TemplateEncoderRendererBaseTest.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/test/java/org/richfaces/renderkit/TemplateEncoderRendererBaseTest.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,110 +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.renderkit;
-
-import java.io.StringWriter;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIOutput;
-import javax.faces.component.html.HtmlPanelGroup;
-import javax.faces.context.ResponseWriter;
-
-import org.jboss.test.faces.AbstractFacesTest;
-
-/**
- * Created 26.10.2007
- * @author Nick Belaevski - mailto:nbelaevski@exadel.com
- * @since 3.2
- */
-public class TemplateEncoderRendererBaseTest extends AbstractFacesTest {
- @Override
- public void setUp() throws Exception {
- super.setUp();
- setupFacesRequest();
- }
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void testEncodeNonRendered() throws Exception {
- ResponseWriter responseWriter =
facesContext.getRenderKit().createResponseWriter(new StringWriter(),
- "text/html", "UTF-8");
-
- facesContext.setResponseWriter(responseWriter);
-
- TemplateEncoderRendererBase rendererBase = new TemplateEncoderRendererBase() {
- @Override
- protected Class<? extends UIComponent> getComponentClass() {
- return UIOutput.class;
- }
- };
- UIOutput output = new UIOutput();
- UIOutput c = new UIOutput();
-
- c.setRendered(false);
- c.setValue("");
- output.getChildren().add(c);
-
- // that should not fail
- rendererBase.writeScriptBody(facesContext, c, true);
- }
-
- public void testEncode() throws Exception {
- StringWriter controlWriter = new StringWriter();
- ResponseWriter responseWriter =
facesContext.getRenderKit().createResponseWriter(controlWriter, "text/html",
- "UTF-8");
-
- facesContext.setResponseWriter(responseWriter);
-
- TemplateEncoderRendererBase rendererBase = new TemplateEncoderRendererBase() {
- @Override
- protected Class<? extends UIComponent> getComponentClass() {
- return UIOutput.class;
- }
- };
- HtmlPanelGroup c = new HtmlPanelGroup();
-
- for (int i = 0; i < 3; i++) {
- HtmlPanelGroup c1 = new HtmlPanelGroup();
-
- c1.setId("panel" + i);
-
- UIOutput text = new UIOutput();
-
- text.setValue("some text");
- c1.getChildren().add(text);
-
- UIOutput text2 = new UIOutput();
-
- text2.setValue("some text");
- c.getChildren().add(text2);
- c.getChildren().add(c1);
- }
-
- rendererBase.writeScriptBody(facesContext, c, false);
- System.out.println(controlWriter.toString());
- }
-}
Deleted:
branches/RF-7560/core/impl/src/test/java/org/richfaces/renderkit/TemplateUtilTest.java
===================================================================
---
branches/RF-7560/core/impl/src/test/java/org/richfaces/renderkit/TemplateUtilTest.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/core/impl/src/test/java/org/richfaces/renderkit/TemplateUtilTest.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -1,46 +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.renderkit;
-
-import java.io.StringReader;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.richfaces.javacc.RichMacroDefinition;
-
-/**
- * @author Nick Belaevski - mailto:nbelaevski@exadel.com
- * created 17.06.2007
- *
- */
-public class TemplateUtilTest extends TestCase {
- public void testAntlr() throws Exception {
- List result = new RichMacroDefinition(new StringReader("{aa{b\\}}a}\\\\
a\\}b\\{c")).expression();
- Expression holder = (Expression) result.get(0);
-
- assertEquals("aa{b}}a", holder.getExpression());
- assertEquals("\\ a}b{c", result.get(1));
- }
-}
Copied:
branches/RF-7560/ui/common/api/src/main/java/org/richfaces/component/SequenceIterationStatus.java
(from rev 19038,
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/SequenceIterationStatus.java)
===================================================================
---
branches/RF-7560/ui/common/api/src/main/java/org/richfaces/component/SequenceIterationStatus.java
(rev 0)
+++
branches/RF-7560/ui/common/api/src/main/java/org/richfaces/component/SequenceIterationStatus.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -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 java.io.Serializable;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class SequenceIterationStatus implements Serializable {
+
+ private static final long serialVersionUID = 1968212566967489719L;
+
+ private Integer begin;
+
+ private Integer count;
+
+ private Integer end;
+
+ private int index;
+
+ private Integer rowCount;
+
+ private boolean first;
+
+ private boolean last;
+
+ private boolean even;
+
+ public SequenceIterationStatus(Integer begin, Integer end, int index, Integer
rowCount) {
+ int iBegin = (begin != null ? begin.intValue() : 0);
+
+ int iRowCountEnd = (rowCount != null ? rowCount.intValue() - 1 :
Integer.MAX_VALUE);
+ int iEnd = (end != null ? end.intValue() : iRowCountEnd);
+ int iLastIdx = Math.min(iEnd, iRowCountEnd);
+
+ this.begin = begin;
+ this.end = iEnd;
+ this.index = index;
+ this.rowCount = rowCount;
+
+ this.first = (index == iBegin);
+
+ this.last = (index >= iLastIdx);
+
+ this.count = (index - iBegin) + 1;
+ this.even = ((count % 2) == 0);
+ }
+
+ public Integer getBegin() {
+ return begin;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public Object getCurrent() {
+ return null;
+ }
+
+ public Integer getEnd() {
+ return end;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public Integer getStep() {
+ return 1;
+ }
+
+ public boolean isFirst() {
+ return first;
+ }
+
+ public boolean isLast() {
+ return last;
+ }
+
+ public Integer getRowCount() {
+ return rowCount;
+ }
+
+ public boolean isEven() {
+ return even;
+ }
+
+ public boolean isOdd() {
+ return !isEven();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("begin= " + begin);
+ sb.append(", end= " + end);
+ sb.append(", index= " + index);
+ sb.append(", count= " + count);
+ sb.append(", first= " + first);
+ sb.append(", last= " + last);
+ sb.append(", even= " + even);
+ sb.append(", rowCount= " + rowCount);
+
+ return sb.toString();
+ }
+}
Copied:
branches/RF-7560/ui/common/api/src/main/java/org/richfaces/renderkit/util/EnclosingFormRequiredException.java
(from rev 19038,
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/EnclosingFormRequiredException.java)
===================================================================
---
branches/RF-7560/ui/common/api/src/main/java/org/richfaces/renderkit/util/EnclosingFormRequiredException.java
(rev 0)
+++
branches/RF-7560/ui/common/api/src/main/java/org/richfaces/renderkit/util/EnclosingFormRequiredException.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,52 @@
+/**
+ * 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.renderkit.util;
+
+import javax.faces.FacesException;
+
+/**
+ * @author Filip Antonov - mailto:fantonov@exadel.com
+ * created 08.02.2007
+ */
+public class EnclosingFormRequiredException extends FacesException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1877777524838776600L;
+
+ public EnclosingFormRequiredException() {
+ super();
+ }
+
+ public EnclosingFormRequiredException(String message) {
+ super(message);
+ }
+
+ public EnclosingFormRequiredException(Throwable cause) {
+ super(cause);
+ }
+
+ public EnclosingFormRequiredException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Copied:
branches/RF-7560/ui/common/api/src/test/java/org/richfaces/component/SequenceIterationStatusTest.java
(from rev 19038,
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/SequenceIterationStatusTest.java)
===================================================================
---
branches/RF-7560/ui/common/api/src/test/java/org/richfaces/component/SequenceIterationStatusTest.java
(rev 0)
+++
branches/RF-7560/ui/common/api/src/test/java/org/richfaces/component/SequenceIterationStatusTest.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,158 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class SequenceIterationStatusTest {
+
+ @Test
+ public void testBeginEnd() throws Exception {
+ SequenceIterationStatus s1 = new SequenceIterationStatus(5, 10, 5, 100);
+ assertEquals(Integer.valueOf(5), s1.getBegin());
+ assertEquals(Integer.valueOf(10), s1.getEnd());
+
+ SequenceIterationStatus s2 = new SequenceIterationStatus(null, null, 5, 100);
+ assertNull(s2.getBegin());
+ assertEquals(Integer.valueOf(99), s2.getEnd());
+
+ SequenceIterationStatus s3 = new SequenceIterationStatus(null, null, 5, null);
+ assertNull(s3.getBegin());
+ assertEquals(Integer.valueOf(Integer.MAX_VALUE), s3.getEnd());
+ }
+
+ @Test
+ public void testFirst() throws Exception {
+ SequenceIterationStatus s1 = new SequenceIterationStatus(0, 10, 0, 100);
+ assertTrue(s1.isFirst());
+ assertFalse(s1.isLast());
+
+ SequenceIterationStatus s2 = new SequenceIterationStatus(0, 10, 1, 100);
+ assertFalse(s2.isFirst());
+ assertFalse(s2.isLast());
+
+ SequenceIterationStatus s3 = new SequenceIterationStatus(0, 0, 0, 100);
+ assertTrue(s3.isFirst());
+ assertTrue(s3.isLast());
+
+ SequenceIterationStatus s4 = new SequenceIterationStatus(5, 10, 5, 100);
+ assertTrue(s4.isFirst());
+ assertFalse(s4.isLast());
+
+ SequenceIterationStatus s5 = new SequenceIterationStatus(5, 10, 6, 100);
+ assertFalse(s5.isFirst());
+ assertFalse(s5.isLast());
+
+ SequenceIterationStatus s6 = new SequenceIterationStatus(null, 10, 0, 100);
+ assertTrue(s6.isFirst());
+ assertFalse(s6.isLast());
+ }
+
+ @Test
+ public void testLast() throws Exception {
+ SequenceIterationStatus s1 = new SequenceIterationStatus(0, 9, 9, 100);
+ assertTrue(s1.isLast());
+ assertFalse(s1.isFirst());
+
+ SequenceIterationStatus s2 = new SequenceIterationStatus(0, 9, 8, 100);
+ assertFalse(s2.isLast());
+ assertFalse(s2.isFirst());
+
+ SequenceIterationStatus s3 = new SequenceIterationStatus(0, 100, 9, 10);
+ assertTrue(s3.isLast());
+ assertFalse(s3.isFirst());
+
+ SequenceIterationStatus s4 = new SequenceIterationStatus(0, 100, 8, 10);
+ assertFalse(s4.isLast());
+ assertFalse(s4.isFirst());
+
+ SequenceIterationStatus s5 = new SequenceIterationStatus(0, null, 9, 10);
+ assertTrue(s5.isLast());
+ assertFalse(s5.isFirst());
+
+ SequenceIterationStatus s6 = new SequenceIterationStatus(0, null, 8, 10);
+ assertFalse(s6.isLast());
+ assertFalse(s6.isFirst());
+ }
+
+ @Test
+ public void testIsEvenOdd() throws Exception {
+ SequenceIterationStatus s1 = new SequenceIterationStatus(0, 100, 0, 10);
+ assertTrue(s1.isOdd());
+ assertFalse(s1.isEven());
+
+ SequenceIterationStatus s2 = new SequenceIterationStatus(0, 100, 1, 10);
+ assertTrue(s2.isEven());
+ assertFalse(s2.isOdd());
+
+ SequenceIterationStatus s3 = new SequenceIterationStatus(5, 100, 7, 10);
+ assertTrue(s3.isOdd());
+ assertFalse(s3.isEven());
+
+ SequenceIterationStatus s4 = new SequenceIterationStatus(5, 100, 6, 10);
+ assertTrue(s4.isEven());
+ assertFalse(s4.isOdd());
+ }
+
+ @Test
+ public void testGetRowCount() throws Exception {
+ SequenceIterationStatus s1 = new SequenceIterationStatus(0, 100, 0, 200);
+ assertEquals(Integer.valueOf(200), s1.getRowCount());
+
+ SequenceIterationStatus s2 = new SequenceIterationStatus(0, 400, 100, 150);
+ assertEquals(Integer.valueOf(150), s2.getRowCount());
+ }
+
+ @Test
+ public void testGetIndex() throws Exception {
+ SequenceIterationStatus s1 = new SequenceIterationStatus(0, 100, 30, 200);
+ assertTrue(30 == s1.getIndex());
+
+ SequenceIterationStatus s2 = new SequenceIterationStatus(0, 400, 100, 150);
+ assertTrue(100 == s2.getIndex());
+ }
+
+ @Test
+ public void testGetCount() throws Exception {
+ SequenceIterationStatus s1 = new SequenceIterationStatus(0, 100, 0, 10);
+ assertTrue(s1.getCount() == 1);
+
+ SequenceIterationStatus s2 = new SequenceIterationStatus(0, 100, 1, 10);
+ assertTrue(s2.getCount() == 2);
+
+ SequenceIterationStatus s3 = new SequenceIterationStatus(5, 100, 7, 10);
+ assertTrue(s3.getCount() == 3);
+
+ SequenceIterationStatus s4 = new SequenceIterationStatus(5, 100, 8, 10);
+ assertTrue(s4.getCount() == 4);
+ }
+}
Copied:
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/RowKeyContextEventWrapper.java
(from rev 19038,
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/RowKeyContextEventWrapper.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/RowKeyContextEventWrapper.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/RowKeyContextEventWrapper.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,74 @@
+/*
+ * 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 javax.faces.component.UIComponent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+import javax.faces.event.PhaseId;
+
+/**
+ * @author Nick Belaevski
+ */
+class RowKeyContextEventWrapper extends FacesEvent {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -869970815228914529L;
+ private FacesEvent event;
+ private Object rowKey;
+
+ public RowKeyContextEventWrapper(UIComponent component, FacesEvent event, Object
rowKey) {
+ super(component);
+ this.event = event;
+ this.rowKey = rowKey;
+ }
+
+ public FacesEvent getFacesEvent() {
+ return this.event;
+ }
+
+ public PhaseId getPhaseId() {
+ return this.event.getPhaseId();
+ }
+
+ public void setPhaseId(PhaseId phaseId) {
+ this.event.setPhaseId(phaseId);
+ }
+
+ public boolean isAppropriateListener(FacesListener listener) {
+ return false;
+ }
+
+ public void processListener(FacesListener listener) {
+ throw new IllegalStateException();
+ }
+
+ /**
+ * @return the rowKey
+ */
+ public Object getRowKey() {
+ return rowKey;
+ }
+}
Copied:
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/SavedState.java (from
rev 19038,
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/SavedState.java)
===================================================================
--- branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/SavedState.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/SavedState.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,141 @@
+/*
+ * 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.io.Serializable;
+
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIForm;
+
+import org.ajax4jsf.component.IterationStateHolder;
+
+//from RI
+
+/**
+ * This class keep values of {@link EditableValueHolder} row-sensitive
+ * fields.
+ *
+ * @author shura
+ */
+final class SavedState implements Serializable {
+
+ public static final SavedState EMPTY = new SavedState();
+
+ private static final long serialVersionUID = -1563864456074187422L;
+
+ private boolean valid = true;
+ private boolean localValueSet;
+ private boolean submitted;
+ private Object submittedValue;
+ private Object value;
+
+ private Object iterationState;
+
+ public SavedState() {
+ super();
+ }
+
+ public SavedState(EditableValueHolder evh) {
+ super();
+ this.value = evh.getLocalValue();
+ this.valid = evh.isValid();
+ this.submittedValue = evh.getSubmittedValue();
+ this.localValueSet = evh.isLocalValueSet();
+ }
+
+ public SavedState(IterationStateHolder ish) {
+ super();
+
+ this.iterationState = ish.getIterationState();
+ }
+
+ public SavedState(UIForm form) {
+ super();
+ this.submitted = form.isSubmitted();
+ }
+
+ Object getSubmittedValue() {
+ return this.submittedValue;
+ }
+
+ void setSubmittedValue(Object submittedValue) {
+ this.submittedValue = submittedValue;
+ }
+
+ boolean isValid() {
+ return this.valid;
+ }
+
+ void setValid(boolean valid) {
+ this.valid = valid;
+ }
+
+ Object getValue() {
+ return this.value;
+ }
+
+ void setValue(Object value) {
+ this.value = value;
+ }
+
+ boolean isLocalValueSet() {
+ return this.localValueSet;
+ }
+
+ void setLocalValueSet(boolean localValueSet) {
+ this.localValueSet = localValueSet;
+ }
+
+ Object getIterationState() {
+ return iterationState;
+ }
+
+ void setIterationState(Object iterationState) {
+ this.iterationState = iterationState;
+ }
+
+ @Override
+ public String toString() {
+ if (iterationState != null) {
+ return "iterationState: " + iterationState;
+ } else {
+ return "submittedValue: " + submittedValue + " value: " +
value + " localValueSet: " + localValueSet
+ + " submitted: " + submitted;
+ }
+ }
+
+ public void apply(EditableValueHolder evh) {
+ evh.setValue(this.value);
+ evh.setValid(this.valid);
+ evh.setSubmittedValue(this.submittedValue);
+ evh.setLocalValueSet(this.localValueSet);
+ }
+
+ public void apply(IterationStateHolder ish) {
+ ish.setIterationState(iterationState);
+ }
+
+ public void apply(UIForm form) {
+ form.setSubmitted(this.submitted);
+ }
+}
Copied:
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java
(from rev 19038,
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,1516 @@
+/*
+ * 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.io.IOException;
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.ContextCallback;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.NamingContainer;
+import javax.faces.component.PartialStateHolder;
+import javax.faces.component.StateHelper;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIForm;
+import javax.faces.component.UINamingContainer;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.UniqueIdVendor;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitResult;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ComponentSystemEvent;
+import javax.faces.event.ComponentSystemEventListener;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.ListenerFor;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PostValidateEvent;
+import javax.faces.event.PreRenderComponentEvent;
+import javax.faces.event.PreValidateEvent;
+import javax.faces.render.Renderer;
+
+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.context.ExtendedVisitContext;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+
+/**
+ * Base class for iterable components, like dataTable, Tomahawk dataList, Facelets
repeat, tree etc., with support for
+ * partial rendering on AJAX responces for one or more selected iterations.
+ *
+ * @author shura
+ */
+@ListenerFor(systemEventClass = PreRenderComponentEvent.class)
+public abstract class UIDataAdaptor extends UIComponentBase implements NamingContainer,
+ UniqueIdVendor, IterationStateHolder, ComponentSystemEventListener {
+
+ /**
+ * <p>The standard component family for this component.</p>
+ */
+ public static final String COMPONENT_FAMILY = "org.richfaces.Data";
+
+ /**
+ * <p>The standard component type for this component.</p>
+ */
+ public static final String COMPONENT_TYPE = "org.richfaces.Data";
+
+ private static final class IterationState implements Serializable {
+
+ private static final long serialVersionUID = -3502645160277416066L;
+
+ private DataComponentState componentState;
+
+ private Object savedComponentState;
+
+ private boolean componentStateIsStateHolder;
+
+ private ExtendedDataModel<?> dataModel;
+
+ public IterationState() {
+ super();
+ }
+
+ public IterationState(DataComponentState componentState,
ExtendedDataModel<?> dataModel) {
+ super();
+ this.componentState = componentState;
+ this.dataModel = dataModel;
+ }
+
+ public ExtendedDataModel<?> getDataModel() {
+ return dataModel;
+ }
+
+ public DataComponentState getComponentState() {
+ return componentState;
+ }
+
+ /**
+ * @param uiDataAdaptor
+ */
+ public void restoreComponentState(UIDataAdaptor uiDataAdaptor) {
+ if (savedComponentState != null && componentStateIsStateHolder) {
+ componentState = uiDataAdaptor.createComponentState();
+ ((StateHolder)
componentState).restoreState(FacesContext.getCurrentInstance(), savedComponentState);
+ savedComponentState = null;
+ }
+ }
+
+ final Object saveState() {
+ boolean localComponentStateIsHolder = false;
+ Object localSavedComponentState = null;
+
+ if (componentState != null) {
+ if (componentState instanceof StateHolder) {
+ localComponentStateIsHolder = true;
+
+ StateHolder stateHolder = (StateHolder) componentState;
+ if (!stateHolder.isTransient()) {
+ localSavedComponentState =
stateHolder.saveState(FacesContext.getCurrentInstance());
+ }
+ } else {
+ if (componentState instanceof Serializable) {
+ localSavedComponentState = componentState;
+ }
+ }
+ }
+
+ Object savedSerializableModel = null;
+
+ if (componentState != null && dataModel != null) {
+ // TODO handle model serialization - "execute" model
+ savedSerializableModel =
dataModel.getSerializableModel(componentState.getRange());
+ }
+
+ if (localSavedComponentState != null || savedSerializableModel != null) {
+ return new Object[] {
+ localComponentStateIsHolder,
+ localSavedComponentState,
+ savedSerializableModel
+ };
+ } else {
+ return null;
+ }
+ }
+
+ final void restoreState(Object stateObject) {
+ if (stateObject != null) {
+ Object[] state = (Object[]) stateObject;
+ componentStateIsStateHolder = Boolean.TRUE.equals(state[0]);
+ Object localSavedComponentState = state[1];
+
+ if (componentStateIsStateHolder) {
+ savedComponentState = localSavedComponentState;
+ } else {
+ componentState = (DataComponentState) localSavedComponentState;
+ }
+
+ dataModel = (ExtendedDataModel<?>) state[2];
+ }
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out)
+ throws IOException {
+
+ out.writeObject(saveState());
+ }
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+
+ restoreState(in.readObject());
+ }
+ }
+
+ private static final VisitCallback STUB_CALLBACK = new VisitCallback() {
+
+ public VisitResult visit(VisitContext context, UIComponent target) {
+ return VisitResult.ACCEPT;
+ }
+ };
+
+ private static final Logger LOG = RichfacesLogger.COMPONENTS.getLogger();
+
+ /**
+ * Visitor for process decode on children components.
+ */
+ protected ComponentVisitor decodeVisitor = new ComponentVisitor() {
+ @Override
+ public void processComponent(FacesContext context, UIComponent c, Object
argument) {
+ c.processDecodes(context);
+ }
+ };
+
+ /**
+ * Visitor for process validation phase
+ */
+ protected ComponentVisitor validateVisitor = new ComponentVisitor() {
+ @Override
+ public void processComponent(FacesContext context, UIComponent c, Object
argument) {
+ c.processValidators(context);
+ }
+ };
+
+ /**
+ * Visitor for process update model phase.
+ */
+ protected ComponentVisitor updateVisitor = new ComponentVisitor() {
+ @Override
+ public void processComponent(FacesContext context, UIComponent c, Object
argument) {
+ c.processUpdates(context);
+ }
+ };
+
+ //TODO nick - PSH support?
+ private DataComponentState componentState = null;
+ private ExtendedDataModel<?> extendedDataModel = null;
+ private Object rowKey = null;
+
+ private String clientId;
+
+ private Object originalVarValue;
+
+ private Converter rowKeyConverter;
+
+ /**
+ * @author Nick Belaevski
+ *
+ */
+ private final class DataVisitorForVisitTree implements DataVisitor {
+ /**
+ *
+ */
+ private final VisitCallback callback;
+ /**
+ *
+ */
+ private final VisitContext visitContext;
+ /**
+ *
+ */
+ private boolean visitResult;
+
+ /**
+ * @param callback
+ * @param visitContext
+ */
+ private DataVisitorForVisitTree(VisitCallback callback, VisitContext
visitContext) {
+ this.callback = callback;
+ this.visitContext = visitContext;
+ }
+
+ public DataVisitResult process(FacesContext context, Object rowKey, Object
argument) {
+ setRowKey(context, rowKey);
+
+ if (isRowAvailable()) {
+ VisitResult result = VisitResult.ACCEPT;
+
+ if (visitContext instanceof ExtendedVisitContext) {
+ result = visitContext.invokeVisitCallback(UIDataAdaptor.this,
callback);
+ if (VisitResult.COMPLETE.equals(result)) {
+ visitResult = true;
+
+ return DataVisitResult.STOP;
+ }
+ }
+
+ if (VisitResult.ACCEPT.equals(result)) {
+ Iterator<UIComponent> dataChildrenItr = dataChildren();
+
+ while (dataChildrenItr.hasNext()) {
+ UIComponent dataChild = dataChildrenItr.next();
+
+ if (dataChild.visitTree(visitContext, callback)) {
+ visitResult = true;
+
+ return DataVisitResult.STOP;
+ }
+ }
+ }
+ }
+
+ return DataVisitResult.CONTINUE;
+ }
+
+ public boolean getVisitResult() {
+ return visitResult;
+ }
+ }
+
+ private enum PropertyKeys {
+ lastId, var, rowKeyVar, stateVar, childState, rowKeyConverter,
rowKeyConverterSet, keepSaved
+ }
+
+ public UIDataAdaptor() {
+ super();
+ }
+
+ protected Map<String, Object> getVariablesMap(FacesContext facesContext) {
+ return facesContext.getExternalContext().getRequestMap();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.faces.component.UIComponent#getFamily()
+ */
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.component.AjaxChildrenEncoder#encodeAjaxChild(javax.faces.context.FacesContext,
+ * java.lang.String, java.util.Set, java.util.Set)
+ */
+ public void encodeAjaxChild(FacesContext context, String path, Set<String> ids,
Set<String> renderedAreas)
+ throws IOException {
+
+ // TODO Auto-generated method stub
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
javax.faces.component.UniqueIdVendor#createUniqueId(javax.faces.context.FacesContext,
java.lang.String)
+ */
+ public String createUniqueId(FacesContext context, String seed) {
+ Integer i = (Integer) getStateHelper().get(PropertyKeys.lastId);
+ int lastId = (i != null) ? i : 0;
+
+ getStateHelper().put(PropertyKeys.lastId, ++lastId);
+
+ return UIViewRoot.UNIQUE_ID_PREFIX + ((seed == null) ? lastId : seed);
+ }
+
+ /**
+ * @return the rowKey
+ */
+ public Object getRowKey() {
+ return rowKey;
+ }
+
+ /**
+ * Setup current row by key. Perform same functionality as
+ * {@link javax.faces.component.UIData#setRowIndex(int)}, but for key object - it may
be not only
+ * row number in sequence data, but, for example - path to current node in
+ * tree.
+ *
+ * @param faces -
+ * current FacesContext
+ * @param key new key value.
+ */
+ public void setRowKey(FacesContext facesContext, Object rowKey) {
+ this.saveChildState(facesContext);
+ this.rowKey = rowKey;
+ this.clientId = null;
+ getExtendedDataModel().setRowKey(rowKey);
+
+ boolean rowSelected = (rowKey != null) && isRowAvailable();
+
+ setupVariable(facesContext, rowSelected);
+ this.restoreChildState(facesContext);
+ }
+
+ /**
+ * Save values of {@link EditableValueHolder} fields before change current
+ * row.
+ *
+ * @param faces
+ */
+ protected void saveChildState(FacesContext facesContext) {
+ Iterator<UIComponent> itr = dataChildren();
+
+ while (itr.hasNext()) {
+ this.saveChildState(facesContext, (UIComponent) itr.next());
+ }
+ }
+
+ /**
+ * @param facesContext
+ * @param next
+ * @param childState
+ */
+ protected void saveChildState(FacesContext facesContext, UIComponent component) {
+
+ // TODO - is it right?
+ if (component.isTransient()) {
+ return;
+ }
+
+ SavedState state = null;
+
+ if (component instanceof IterationStateHolder) {
+ IterationStateHolder ish = (IterationStateHolder) component;
+
+ state = new SavedState(ish);
+ } else if (component instanceof EditableValueHolder) {
+ EditableValueHolder evh = (EditableValueHolder) component;
+
+ state = new SavedState(evh);
+ } else if (component instanceof UIForm) {
+ UIForm form = (UIForm) component;
+
+ state = new SavedState(form);
+ }
+
+ if (state != null) {
+
+ // TODO - use local map - children save their state themselves using
visitors
+ getStateHelper().put(PropertyKeys.childState,
component.getClientId(facesContext), state);
+ }
+
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : component.getChildren()) {
+ saveChildState(facesContext, child);
+ }
+ }
+
+ if (component.getFacetCount() > 0) {
+ for (UIComponent facet : component.getFacets().values()) {
+ saveChildState(facesContext, facet);
+ }
+ }
+ }
+
+ protected Iterator<UIComponent> dataChildren() {
+ if (getChildCount() > 0) {
+ return getChildren().iterator();
+ } else {
+ return Collections.<UIComponent>emptyList().iterator();
+ }
+ }
+
+ protected Iterator<UIComponent> fixedChildren() {
+ if (getFacetCount() > 0) {
+ return getFacets().values().iterator();
+ } else {
+ return Collections.<UIComponent>emptyList().iterator();
+ }
+ }
+
+ /**
+ * @param facesContext
+ */
+ protected void restoreChildState(FacesContext facesContext) {
+ Iterator<UIComponent> itr = dataChildren();
+
+ while (itr.hasNext()) {
+ this.restoreChildState(facesContext, (UIComponent) itr.next());
+ }
+ }
+
+ /**
+ * Restore values of {@link EditableValueHolder} fields after change current
+ * row.
+ *
+ * @param facesContext
+ * @param next
+ * @param childState
+ */
+ protected void restoreChildState(FacesContext facesContext, UIComponent component) {
+ String id = component.getId();
+
+ component.setId(id); // Forces client id to be reset
+
+ SavedState savedState = null;
+ @SuppressWarnings("unchecked")
+ Map<String, SavedState> savedStatesMap = (Map<String, SavedState>)
getStateHelper()
+ .get(PropertyKeys.childState);
+
+ if (savedStatesMap != null) {
+ savedState = savedStatesMap.get(component.getClientId(facesContext));
+ }
+
+ if (savedState == null) {
+ savedState = SavedState.EMPTY;
+ }
+
+ if (component instanceof IterationStateHolder) {
+ IterationStateHolder ish = (IterationStateHolder) component;
+
+ savedState.apply(ish);
+ } else if (component instanceof EditableValueHolder) {
+ EditableValueHolder evh = (EditableValueHolder) component;
+
+ savedState.apply(evh);
+ } else if (component instanceof UIForm) {
+ UIForm form = (UIForm) component;
+
+ savedState.apply(form);
+ }
+
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : component.getChildren()) {
+ restoreChildState(facesContext, child);
+ }
+ }
+
+ if (component.getFacetCount() > 0) {
+ for (UIComponent facet : component.getFacets().values()) {
+ restoreChildState(facesContext, facet);
+ }
+ }
+ }
+
+ public void setRowKey(Object rowKey) {
+ setRowKey(getFacesContext(), rowKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
javax.faces.component.UIComponentBase#queueEvent(javax.faces.event.FacesEvent)
+ */
+ @Override
+ public void queueEvent(FacesEvent event) {
+ super.queueEvent(new RowKeyContextEventWrapper(this, event, getRowKey()));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
javax.faces.component.UIComponentBase#broadcast(javax.faces.event.FacesEvent)
+ */
+ @Override
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+ if (!(event instanceof RowKeyContextEventWrapper)) {
+ if (!broadcastLocal(event)) {
+ super.broadcast(event);
+ }
+
+ return;
+ }
+
+ FacesContext context = getFacesContext();
+
+ // Set up the correct context and fire our wrapped event
+ RowKeyContextEventWrapper revent = (RowKeyContextEventWrapper) event;
+ Object oldRowKey = getRowKey();
+
+ setRowKey(context, revent.getRowKey());
+
+ FacesEvent rowEvent = revent.getFacesEvent();
+ UIComponent source = rowEvent.getComponent();
+ UIComponent compositeParent = null;
+
+ try {
+ if (!UIComponent.isCompositeComponent(source)) {
+ compositeParent = UIComponent.getCompositeComponentParent(source);
+ }
+
+ if (compositeParent != null) {
+ compositeParent.pushComponentToEL(context, null);
+ }
+
+ source.pushComponentToEL(context, null);
+ source.broadcast(rowEvent);
+ } finally {
+ source.popComponentFromEL(context);
+
+ if (compositeParent != null) {
+ compositeParent.popComponentFromEL(context);
+ }
+ }
+
+ setRowKey(context, oldRowKey);
+ }
+
+ /**
+ * Process events targetted for concrete implementation. Hook method called
+ * from {@link #broadcast(FacesEvent)}
+ *
+ * @param event -
+ * processed event.
+ * @return true if event processed, false if component must continue
+ * processing.
+ */
+
+ // TODO - is it still actual?
+ protected boolean broadcastLocal(FacesEvent event) {
+ return false;
+ }
+
+ /**
+ * @return the extendedDataModel
+ */
+ protected ExtendedDataModel<?> getExtendedDataModel() {
+ if (extendedDataModel == null) {
+ extendedDataModel = createExtendedDataModel();
+ }
+
+ return extendedDataModel;
+ }
+
+ /**
+ * @return
+ */
+ protected abstract ExtendedDataModel<?> createExtendedDataModel();
+
+ /**
+ * @param extendedDataModel the extendedDataModel to set
+ */
+ protected void setExtendedDataModel(ExtendedDataModel<?> extendedDataModel) {
+ this.extendedDataModel = extendedDataModel;
+ }
+
+ public String getVar() {
+ return (String) getStateHelper().get(PropertyKeys.var);
+ }
+
+ public void setVar(String var) {
+ getStateHelper().put(PropertyKeys.var, var);
+ }
+
+ public String getRowKeyVar() {
+ return (String) getStateHelper().get(PropertyKeys.rowKeyVar);
+ }
+
+ public void setRowKeyVar(String rowKeyVar) {
+ getStateHelper().put(PropertyKeys.rowKeyVar, rowKeyVar);
+ }
+
+ public String getStateVar() {
+ return (String) getStateHelper().get(PropertyKeys.stateVar);
+ }
+
+ public void setStateVar(String stateVar) {
+ getStateHelper().put(PropertyKeys.stateVar, stateVar);
+ }
+
+ //XXX - review and probably remove - useful method, should be left
+ public int getRowCount() {
+ return getExtendedDataModel().getRowCount();
+ }
+
+ public Object getRowData() {
+ return getExtendedDataModel().getRowData();
+ }
+
+ public boolean isRowAvailable() {
+ return getExtendedDataModel().isRowAvailable();
+ }
+
+ /**
+ * Boolean attribute that defines whether this iteration component will reset saved
children's state
+ * before rendering. By default state is reset if there are no faces messages with
severity error or higher.
+ * @return
+ */
+ public boolean isKeepSaved() {
+ Object value = getStateHelper().eval(PropertyKeys.keepSaved);
+
+ if (value == null) {
+ return keepSaved(getFacesContext());
+ } else {
+ return Boolean.valueOf(value.toString());
+ }
+ }
+
+ public void setKeepSaved(boolean keepSaved) {
+ getStateHelper().put(PropertyKeys.keepSaved, keepSaved);
+ }
+
+ /**
+ * Setup EL variable for different iteration. Value of row data and
+ * component state will be put into request scope attributes with names
+ * given by "var" and "varState" bean properties.
+ * <p/>
+ * Changed: does not check for row availability now
+ *
+ * @param faces current faces context
+ * @param localModel
+ * @param rowSelected
+ */
+ protected void setupVariable(FacesContext faces, boolean rowSelected) {
+ Map<String, Object> attrs = getVariablesMap(faces);
+
+ if (rowSelected) {
+
+ // Current row data.
+ setupVariable(getVar(), attrs, getRowData());
+
+ // Component state variable.
+ setupVariable(getStateVar(), attrs, getComponentState());
+
+ // Row key Data variable.
+ setupVariable(getRowKeyVar(), attrs, getRowKey());
+ } else {
+ removeVariable(getVar(), attrs);
+ removeVariable(getStateVar(), attrs);
+ removeVariable(getRowKeyVar(), attrs);
+ }
+ }
+
+ /**
+ * @return
+ */
+ public DataComponentState getComponentState() {
+ if (componentState != null) {
+ return componentState;
+ }
+
+ ValueExpression componentStateExpression =
getValueExpression("componentState");
+
+ if (componentStateExpression != null) {
+ componentState = (DataComponentState)
componentStateExpression.getValue(getFacesContext().getELContext());
+ }
+
+ if (componentState == null) {
+ componentState = createComponentState();
+
+ if ((componentStateExpression != null)
+ &&
!componentStateExpression.isReadOnly(getFacesContext().getELContext())) {
+ componentStateExpression.setValue(getFacesContext().getELContext(),
componentState);
+ }
+ }
+
+ return componentState;
+ }
+
+ protected abstract DataComponentState createComponentState();
+
+ /**
+ * @param var
+ * @param attrs
+ * @param rowData
+ */
+ private void setupVariable(String var, Map<String, Object> attrs, Object
rowData) {
+ if (var != null) {
+ attrs.put(var, rowData);
+ }
+ }
+
+ /**
+ * @param var
+ * @param attrs
+ * @param rowData
+ */
+ private void removeVariable(String var, Map<String, Object> attrs) {
+ if (var != null) {
+ attrs.remove(var);
+ }
+ }
+
+ public Converter getRowKeyConverter() {
+ if (this.rowKeyConverter != null) {
+ return this.rowKeyConverter;
+ }
+
+ return (Converter) getStateHelper().eval(PropertyKeys.rowKeyConverter);
+ }
+
+ public void setRowKeyConverter(Converter converter) {
+ StateHelper stateHelper = getStateHelper();
+ if (initialStateMarked()) {
+ stateHelper.put(PropertyKeys.rowKeyConverterSet, Boolean.TRUE);
+ }
+
+ this.rowKeyConverter = converter;
+ }
+
+ private boolean isSetRowKeyConverter() {
+ Boolean value = (Boolean) getStateHelper().get(PropertyKeys.rowKeyConverterSet);
+ return Boolean.TRUE.equals(value);
+ }
+
+ @Override
+ public String getClientId(FacesContext facesContext) {
+ if (facesContext == null) {
+ throw new NullPointerException("context");
+ }
+
+ if (null == clientId) {
+ StringBuilder id = new StringBuilder(super.getClientId(facesContext));
+ Object rowKey = getRowKey();
+
+ if (rowKey != null) {
+
+ // Use converter to get String representation ot the row key.
+ Converter rowKeyConverter = getRowKeyConverter();
+
+ if (null == rowKeyConverter) {
+
+ // Create default converter for a row key.
+ rowKeyConverter =
facesContext.getApplication().createConverter(rowKey.getClass());
+
+ // Store converter for a invokeOnComponents call.
+ if (null != rowKeyConverter) {
+ // TODO - review
+ setRowKeyConverter(rowKeyConverter);
+ }
+ }
+
+ String rowKeyString;
+
+ if (null != rowKeyConverter) {
+
+ // Temporary set clientId, to avoid infinite calls from converter.
+ clientId = id.toString();
+ rowKeyString = rowKeyConverter.getAsString(facesContext, this,
rowKey);
+ } else {
+ rowKeyString = rowKey.toString();
+ }
+
+
id.append(UINamingContainer.getSeparatorChar(facesContext)).append(rowKeyString);
+ }
+
+ Renderer renderer = getRenderer(facesContext);
+
+ if (null != renderer) {
+ clientId = renderer.convertClientId(facesContext, id.toString());
+ } else {
+ clientId = id.toString();
+ }
+ }
+
+ return clientId;
+ }
+
+ /**
+ * Save current state of data variable.
+ *
+ * @param faces current faces context
+ */
+
+ // TODO move into walk() method body
+ public void captureOrigValue(FacesContext faces) {
+ String var = getVar();
+
+ if (var != null) {
+ Map<String, Object> attrs = getVariablesMap(faces);
+
+ this.originalVarValue = attrs.get(var);
+ }
+
+ // TODO add support for another variables
+ }
+
+ /**
+ * Restore value of data variable after processing phase.
+ *
+ * @param faces current faces context
+ */
+ public void restoreOrigValue(FacesContext faces) {
+ String var = getVar();
+
+ if (var != null) {
+ Map<String, Object> attrs = getVariablesMap(faces);
+
+ if (this.originalVarValue != null) {
+ attrs.put(var, this.originalVarValue);
+ } else {
+ attrs.remove(var);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.faces.component.UIComponent#setValueExpression(java.lang.String,
javax.el.ValueExpression)
+ */
+ @Override
+ public void setValueExpression(String name, ValueExpression binding) {
+ if ("var".equals(name) || "rowKeyVar".equals(name) ||
"stateVar".equals(name)) {
+ throw new IllegalArgumentException(MessageFormat.format("{0} cannot be
EL-expression", name));
+ }
+
+ super.setValueExpression(name, binding);
+ }
+
+ /**
+ * Check for validation errors on children components. If true, saved values
+ * must be keep on render phase
+ *
+ * @param context
+ * @return
+ */
+ protected boolean keepSaved(FacesContext context) {
+
+ // For an any validation errors, children components state should be preserved
+ FacesMessage.Severity sev = context.getMaximumSeverity();
+
+ return (sev != null) && (FacesMessage.SEVERITY_ERROR.compareTo(sev) >=
0);
+ }
+
+ /**
+ * Perform iteration on all children components and all data rows with given
+ * visitor.
+ *
+ * @param faces
+ * @param visitor
+ */
+ protected void iterate(FacesContext faces, ComponentVisitor visitor) {
+
+ // stop if not rendered
+ if (!this.isRendered()) {
+ return;
+ }
+
+ // reset rowIndex
+ this.captureOrigValue(faces);
+ this.setRowKey(faces, null);
+
+ try {
+ Iterator<UIComponent> fixedChildren = fixedChildren();
+
+ while (fixedChildren.hasNext()) {
+ UIComponent component = fixedChildren.next();
+
+ visitor.processComponent(faces, component, null);
+ }
+
+ walk(faces, visitor, null);
+ } catch (Exception e) {
+ throw new FacesException(e);
+ } finally {
+ this.setRowKey(faces, null);
+ this.restoreOrigValue(faces);
+ }
+ }
+
+ /**
+ * Walk ( visit ) this component on all data-aware children for each row.
+ *
+ * @param faces
+ * @param visitor
+ */
+ public void walk(FacesContext faces, DataVisitor visitor, Object argument) {
+ Object key = getRowKey();
+ captureOrigValue(faces);
+
+ Range range = null;
+ DataComponentState componentState = getComponentState();
+
+ if (componentState != null) {
+ range = componentState.getRange();
+ }
+
+ getExtendedDataModel().walk(faces, visitor, range, argument);
+
+ setRowKey(faces, key);
+ restoreOrigValue(faces);
+ }
+
+ public void processDecodes(FacesContext faces) {
+ if (!this.isRendered()) {
+ return;
+ }
+
+ pushComponentToEL(faces, this);
+ preDecode(faces);
+ this.iterate(faces, decodeVisitor);
+ this.decode(faces);
+ popComponentFromEL(faces);
+ }
+
+ public void processValidators(FacesContext faces) {
+ if (!this.isRendered()) {
+ return;
+ }
+
+ pushComponentToEL(faces, this);
+ Application app = faces.getApplication();
+ app.publishEvent(faces, PreValidateEvent.class, this);
+ preValidate(faces);
+ this.iterate(faces, validateVisitor);
+ app.publishEvent(faces, PostValidateEvent.class, this);
+ popComponentFromEL(faces);
+ }
+
+ public void processUpdates(FacesContext faces) {
+ if (!this.isRendered()) {
+ return;
+ }
+
+ pushComponentToEL(faces, this);
+ preUpdate(faces);
+ this.iterate(faces, updateVisitor);
+
+ ExtendedDataModel<?> dataModel = getExtendedDataModel();
+
+ // If no validation errors, update values for serializable model,
+ // restored from view.
+ if ((dataModel instanceof SerializableDataModel) && (!isKeepSaved())) {
+ SerializableDataModel serializableModel = (SerializableDataModel) dataModel;
+
+ serializableModel.update();
+ }
+
+ popComponentFromEL(faces);
+ }
+
+ @Override
+ public void setId(String id) {
+ super.setId(id);
+ this.clientId = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.ajax4jsf.component.IterationStateHolder#getIterationState()
+ */
+ public Object getIterationState() {
+ assert rowKey == null;
+
+ return new IterationState(this.componentState, this.extendedDataModel);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.component.IterationStateHolder#setIterationState(java.lang.Object)
+ */
+ public void setIterationState(Object stateObject) {
+ assert rowKey == null;
+
+ // TODO - ?
+ // restoreChildState(getFacesContext());
+ if (stateObject != null) {
+ IterationState iterationState = (IterationState) stateObject;
+ iterationState.restoreComponentState(this);
+
+ this.componentState = iterationState.getComponentState();
+ this.extendedDataModel = iterationState.getDataModel();
+ } else {
+ this.componentState = null;
+ this.extendedDataModel = null;
+ }
+ }
+
+ protected void resetDataModel() {
+ this.extendedDataModel = null;
+ }
+
+ protected void resetChildState() {
+ getStateHelper().remove(PropertyKeys.childState);
+ }
+
+ protected void preDecode(FacesContext context) {
+ resetDataModel();
+
+ Object savedChildState = getStateHelper().get(PropertyKeys.childState);
+ // TODO - verify the check for null: savedChildState == null
+ if (savedChildState == null || !isKeepSaved()) {
+ resetChildState();
+ }
+ }
+
+ // TODO - do we need this method?
+ protected void preValidate(FacesContext context) {
+ }
+
+ // TODO - do we need this method?
+ protected void preUpdate(FacesContext context) {
+ }
+
+ protected void preEncodeBegin(FacesContext context) {
+ resetDataModel();
+
+ if (!isKeepSaved()) {
+ //TODO - this also resets state for the nested iteration components - is it
correct?
+ resetChildState();
+ }
+ }
+
+ @Override
+ public void markInitialState() {
+ super.markInitialState();
+
+ if (rowKeyConverter instanceof PartialStateHolder) {
+ ((PartialStateHolder) rowKeyConverter).markInitialState();
+ }
+ }
+
+ @Override
+ public void clearInitialState() {
+ super.clearInitialState();
+
+ if (rowKeyConverter instanceof PartialStateHolder) {
+ ((PartialStateHolder) rowKeyConverter).clearInitialState();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
javax.faces.component.UIComponentBase#saveState(javax.faces.context.FacesContext)
+ */
+ @Override
+ public Object saveState(FacesContext context) {
+ Object parentState = super.saveState(context);
+ Object savedComponentState = new IterationState(componentState,
extendedDataModel).saveState();
+
+ Object converterState = null;
+ boolean nullDelta = true;
+
+ boolean converterHasPartialState = false;
+
+ if (initialStateMarked()) {
+ if (!isSetRowKeyConverter() && rowKeyConverter != null &&
rowKeyConverter instanceof PartialStateHolder) {
+ // Delta
+ StateHolder holder = (StateHolder) rowKeyConverter;
+ if (!holder.isTransient()) {
+ Object attachedState = holder.saveState(context);
+ if (attachedState != null) {
+ nullDelta = false;
+ converterState = attachedState;
+ }
+ converterHasPartialState = true;
+ } else {
+ converterState = null;
+ }
+ } else if (isSetRowKeyConverter() || rowKeyConverter != null) {
+ // Full
+ converterState = saveAttachedState(context, rowKeyConverter);
+ nullDelta = false;
+ }
+
+ if (parentState == null && savedComponentState == null &&
nullDelta) {
+ // No values
+ return null;
+ }
+ } else {
+ converterState = saveAttachedState(context, rowKeyConverter);
+ }
+
+ return new Object[] {
+ parentState,
+ savedComponentState,
+ converterHasPartialState,
+ converterState
+ };
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.UIComponentBase#restoreState(javax.faces.context.FacesContext,
java.lang.Object)
+ */
+ @Override
+ public void restoreState(FacesContext context, Object stateObject) {
+ if (stateObject == null) {
+ return ;
+ }
+
+ Object[] state = (Object[]) stateObject;
+
+ super.restoreState(context, state[0]);
+
+ if (state[1] != null) {
+ IterationState iterationState = new IterationState();
+ iterationState.restoreState(state[1]);
+ iterationState.restoreComponentState(this);
+
+ // TODO update state model binding
+ componentState = iterationState.getComponentState();
+ extendedDataModel = iterationState.getDataModel();
+ }
+
+ boolean converterHasPartialState = Boolean.TRUE.equals(state[2]);
+ Object savedConverterState = state[3];
+ if (converterHasPartialState) {
+ ((StateHolder) rowKeyConverter).restoreState(context, savedConverterState);
+ } else {
+ rowKeyConverter = (Converter) UIComponentBase.restoreAttachedState(context,
savedConverterState);
+ }
+ }
+
+ private boolean matchesBaseId(String clientId, String baseId, char separatorChar) {
+ if (clientId.equals(baseId)) {
+ return true;
+ }
+
+ // if clientId.startsWith(baseId + separatorChar)
+ if (clientId.startsWith(baseId) && (clientId.length() >
baseId.length())
+ && (clientId.charAt(baseId.length()) == separatorChar)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean invokeOnComponent(FacesContext context, String clientId,
ContextCallback callback)
+ throws FacesException {
+
+ if ((null == context) || (null == clientId) || (null == callback)) {
+ throw new NullPointerException();
+ }
+
+ String baseId = super.getClientId(context);
+
+ if (!matchesBaseId(clientId, baseId,
UINamingContainer.getSeparatorChar(context))) {
+ return false;
+ }
+
+ boolean found = false;
+ Object oldRowKey = getRowKey();
+
+ // TODO - this does not seem right
+ captureOrigValue(context);
+
+ try {
+
+ // TODO - ?
+ // if (null != oldRowKey) {
+ setRowKey(context, null);
+
+ // }
+ if (clientId.equals(baseId)) {
+ callback.invokeContextCallback(context, this);
+ found = true;
+ } else {
+ Iterator<UIComponent> fixedChildrenItr = fixedChildren();
+
+ while (fixedChildrenItr.hasNext() && !found) {
+ UIComponent fixedChild = fixedChildrenItr.next();
+
+ found = fixedChild.invokeOnComponent(context, clientId, callback);
+ }
+ }
+
+ if (!found) {
+ Object newRowKey = null;
+
+ // 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) {
+ Converter keyConverter = getRowKeyConverter();
+
+ if (null != keyConverter) {
+ try {
+ //TODO: review
+ newRowKey = keyConverter.getAsObject(context, this,
rowKeyString);
+ } catch (ConverterException e) {
+
+ // TODO: LOG error
+ }
+ }
+ }
+
+ setRowKey(context, newRowKey);
+
+ if (isRowAvailable()) {
+ Iterator<UIComponent> dataChildrenItr = dataChildren();
+
+ while (dataChildrenItr.hasNext() && !found) {
+ UIComponent dataChild = dataChildrenItr.next();
+
+ found = dataChild.invokeOnComponent(context, clientId,
callback);
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new FacesException(e);
+ } finally {
+
+ // if (null != oldRowKey) {
+ try {
+ setRowKey(context, oldRowKey);
+ restoreOrigValue(context);
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
+ }
+
+ // }
+ }
+
+ return found;
+ }
+
+ // Tests whether we need to visit our children as part of
+ // a tree visit
+ private boolean doVisitChildren(VisitContext context, boolean visitRows) {
+
+ // Just need to check whether there are any ids under this
+ // subtree. Make sure row index is cleared out since
+ // getSubtreeIdsToVisit() needs our row-less client id.
+
+ // TODO check this
+ if (visitRows) {
+ setRowKey(context.getFacesContext(), null);
+ }
+
+ // TODO optimize for returned IDs
+ Collection<String> idsToVisit = context.getSubtreeIdsToVisit(this);
+
+ assert idsToVisit != null;
+
+ if (idsToVisit == VisitContext.ALL_IDS) {
+ // TODO
+ }
+
+ // All ids or non-empty collection means we need to visit our children.
+ return !idsToVisit.isEmpty();
+ }
+
+ private boolean visitComponents(Iterator<UIComponent> components, VisitContext
context, VisitCallback callback) {
+
+ while (components.hasNext()) {
+ UIComponent nextChild = components.next();
+
+ if (nextChild.visitTree(context, callback)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected boolean visitFixedChildren(VisitContext visitContext, VisitCallback
callback) {
+
+ return visitComponents(fixedChildren(), visitContext, callback);
+ }
+
+ protected boolean visitDataChildren(VisitContext visitContext, VisitCallback
callback, boolean visitRows) {
+
+ if (visitRows) {
+ FacesContext facesContext = visitContext.getFacesContext();
+
+ DataVisitorForVisitTree dataVisitor = new DataVisitorForVisitTree(callback,
visitContext);
+ this.walk(facesContext, dataVisitor, null);
+
+ return dataVisitor.getVisitResult();
+ } else {
+ return visitComponents(dataChildren(), visitContext, callback);
+ }
+ }
+
+ @Override
+ public boolean visitTree(VisitContext visitContext, VisitCallback callback) {
+
+ // First check to see whether we are visitable. If not
+ // short-circuit out of this subtree, though allow the
+ // visit to proceed through to other subtrees.
+ if (!isVisitable(visitContext)) {
+ return false;
+ }
+
+ // Clear out the row index is one is set so that
+ // we start from a clean slate.
+ FacesContext facesContext = visitContext.getFacesContext();
+
+ // NOTE: that the visitRows local will be obsolete once the
+ // appropriate visit hints have been added to the API
+ boolean visitRows = requiresRowIteration(facesContext);
+
+ Object oldRowKey = null;
+ if (visitRows) {
+ captureOrigValue(facesContext);
+ oldRowKey = getRowKey();
+ setRowKey(facesContext, null);
+ }
+
+ // Push ourselves to EL
+ pushComponentToEL(facesContext, null);
+
+ try {
+
+ // Visit ourselves. Note that we delegate to the
+ // VisitContext to actually perform the visit.
+ VisitResult result = visitContext.invokeVisitCallback(this, callback);
+
+ // If the visit is complete, short-circuit out and end the visit
+ if (result == VisitResult.COMPLETE) {
+ return true;
+ }
+
+ // Visit children, short-circuiting as necessary
+ if ((result == VisitResult.ACCEPT) && doVisitChildren(visitContext,
visitRows)) {
+ if (visitRows) {
+ setRowKey(facesContext, null);
+ }
+
+ if (visitFixedChildren(visitContext, callback)) {
+ return true;
+ }
+
+ if (visitContext instanceof ExtendedVisitContext) {
+ ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext)
visitContext;
+
+ Collection<String> directSubtreeIdsToVisit =
extendedVisitContext.getDirectSubtreeIdsToVisit(this);
+ if (directSubtreeIdsToVisit != VisitContext.ALL_IDS) {
+ if (directSubtreeIdsToVisit.isEmpty()) {
+ return false;
+ } else {
+ VisitContext directChildrenVisitContext =
+
extendedVisitContext.createNamingContainerVisitContext(this, directSubtreeIdsToVisit);
+
+ if (visitRows) {
+ setRowKey(facesContext, null);
+ }
+ if (visitFixedChildren(directChildrenVisitContext,
STUB_CALLBACK)) {
+ return false;
+ }
+ }
+ }
+ }
+
+ if (visitDataChildren(visitContext, callback, visitRows)) {
+ return true;
+ }
+ }
+ } finally {
+
+ // Clean up - pop EL and restore old row index
+ popComponentFromEL(facesContext);
+
+ if (visitRows) {
+ try {
+ setRowKey(facesContext, oldRowKey);
+ restoreOrigValue(facesContext);
+ } catch (Exception e) {
+
+ // TODO: handle exception
+ LOG.error(e.getMessage(), e);
+ }
+ }
+ }
+
+ // Return false to allow the visit to continue
+ return false;
+ }
+
+ /**
+ * @param facesContext
+ * @return
+ */
+ private boolean requiresRowIteration(FacesContext context) {
+ return (!PhaseId.RESTORE_VIEW.equals(context.getCurrentPhaseId()));
+ }
+
+ /**
+ * @param context
+ * @param substring
+ * @return
+ */
+ // TODO review!
+ protected String extractKeySegment(FacesContext context, String substring) {
+ char separatorChar = UINamingContainer.getSeparatorChar(context);
+ int separatorIndex = substring.indexOf(separatorChar);
+
+ if (separatorIndex < 0) {
+ return substring;
+ } else {
+ return substring.substring(0, separatorIndex);
+ }
+ }
+
+ /**
+ * Base class for visit data model at phases decode, validation and update model
+ *
+ * @author shura
+ */
+ protected abstract class ComponentVisitor implements DataVisitor {
+ public DataVisitResult process(FacesContext context, Object rowKey, Object
argument) {
+ setRowKey(context, rowKey);
+
+ if (isRowAvailable()) {
+ Iterator<UIComponent> childIterator = dataChildren();
+
+ while (childIterator.hasNext()) {
+ UIComponent component = childIterator.next();
+
+ processComponent(context, component, argument);
+ }
+ }
+
+ return DataVisitResult.CONTINUE;
+ }
+
+ 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) {
+ preEncodeBegin(getFacesContext());
+ }
+ }
+
+ protected DataComponentState getLocalComponentState() {
+ return componentState;
+ }
+}
Copied:
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/UISequence.java (from
rev 19038,
branches/RF-7560/core/impl/src/main/java/org/richfaces/component/UISequence.java)
===================================================================
--- branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/UISequence.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/component/UISequence.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,305 @@
+/*
+ * 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.sql.ResultSet;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UINamingContainer;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.model.ArrayDataModel;
+import javax.faces.model.DataModel;
+import javax.faces.model.ListDataModel;
+import javax.faces.model.ResultDataModel;
+import javax.faces.model.ResultSetDataModel;
+import javax.faces.model.ScalarDataModel;
+import javax.servlet.jsp.jstl.sql.Result;
+
+import org.ajax4jsf.model.DataComponentState;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.SequenceDataModel;
+import org.ajax4jsf.model.SequenceRange;
+import org.ajax4jsf.model.SequenceState;
+
+/**
+ * @author Nick Belaevski
+ */
+public class UISequence extends UIDataAdaptor {
+
+ private Object iterationStatusVarObject;
+
+ protected enum PropertyKeys {
+ first, rows, value, iterationStatusVar
+ }
+
+ protected void updateState(SequenceState state) {
+ state.setFirst(getActualFirst());
+ state.setRows(getActualRows());
+ }
+
+ protected void updateState() {
+ DataComponentState localState = getLocalComponentState();
+ if (localState instanceof SequenceState) {
+ updateState((SequenceState) localState);
+ }
+ }
+
+ protected int getActualFirst() {
+ return getFirst();
+ }
+
+ protected int getActualRows() {
+ return getRows();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected DataModel<?> createFacesModel(Object value) {
+ DataModel<?> model = null;
+
+ if (value == null) {
+ model = new ListDataModel(Collections.EMPTY_LIST);
+ } else if (value instanceof DataModel) {
+ model = (DataModel) value;
+ } else if (value instanceof List) {
+ model = new ListDataModel((List) value);
+ } else if (Object[].class.isAssignableFrom(value.getClass())) {
+ model = new ArrayDataModel((Object[]) value);
+ } else if (value instanceof ResultSet) {
+ model = new ResultSetDataModel((ResultSet) value);
+ } else if (value instanceof Result) {
+ model = new ResultDataModel((Result) value);
+ } else {
+ model = new ScalarDataModel(value);
+ }
+
+ return model;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected ExtendedDataModel<?> createExtendedDataModel() {
+ ExtendedDataModel<?> model = null;
+
+ // Synthesize a DataModel around our current value if possible
+ Object value = getValue();
+
+ if (value instanceof ExtendedDataModel<?>) {
+ model = (ExtendedDataModel<?>) value;
+ } else {
+ model = new SequenceDataModel(createFacesModel(value));
+ }
+
+ return model;
+ }
+
+ @Override
+ protected DataComponentState createComponentState() {
+ SequenceState state = new SequenceState();
+
+ updateState(state);
+
+ return state;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.component.UIDataAdaptor#getRowKeyConverter()
+ */
+
+ // TODO make this a property of model
+
+ @Override
+ public Converter getRowKeyConverter() {
+ return getFacesContext().getApplication().createConverter(Integer.class);
+ }
+
+ public int getFirst() {
+ return (Integer) getStateHelper().eval(PropertyKeys.first, 0);
+ }
+
+ public void setFirst(int first) {
+ getStateHelper().put(PropertyKeys.first, first);
+ updateState();
+ }
+
+ public int getRows() {
+ return (Integer) getStateHelper().eval(PropertyKeys.rows, 0);
+ }
+
+ public void setRows(int rows) {
+ getStateHelper().put(PropertyKeys.rows, rows);
+ updateState();
+ }
+
+ public Object getValue() {
+ return getStateHelper().eval(PropertyKeys.value);
+ }
+
+ public void setValue(Object value) {
+ resetDataModel();
+ getStateHelper().put(PropertyKeys.value, value);
+ }
+
+ public String getIterationStatusVar() {
+ return (String) getStateHelper().get(PropertyKeys.iterationStatusVar);
+ }
+
+ public void setIterationStatusVar(String iterationStatusVar) {
+ getStateHelper().put(PropertyKeys.iterationStatusVar, iterationStatusVar);
+ }
+
+ public int getRowIndex() {
+ return getExtendedDataModel().getRowIndex();
+ }
+
+ @Override
+ public void captureOrigValue(FacesContext faces) {
+ super.captureOrigValue(faces);
+
+ String iterationStatusVar = getIterationStatusVar();
+ if (iterationStatusVar != null) {
+ Map<String, Object> variablesMap = getVariablesMap(faces);
+
+ iterationStatusVarObject = variablesMap.get(iterationStatusVar);
+ }
+ }
+
+ @Override
+ public void restoreOrigValue(FacesContext faces) {
+ super.restoreOrigValue(faces);
+
+ String iterationStatusVar = getIterationStatusVar();
+ if (iterationStatusVar != null) {
+ Map<String, Object> variablesMap = getVariablesMap(faces);
+
+ if (iterationStatusVarObject != null) {
+ variablesMap.put(iterationStatusVar, iterationStatusVarObject);
+ } else {
+ variablesMap.remove(iterationStatusVar);
+ }
+ }
+ }
+
+ @Override
+ protected void setupVariable(FacesContext faces, boolean rowSelected) {
+ super.setupVariable(faces, rowSelected);
+
+ //TODO nick - should iterationStatus be available out of iteration?
+ // if yes, better name than "iterationStatusVar" is
required
+ String iterationStatusVar = getIterationStatusVar();
+ if (iterationStatusVar != null) {
+ Map<String, Object> requestMap = getVariablesMap(faces);
+
+ if (rowSelected) {
+ Integer begin = null;
+ Integer end = null;
+
+ Range range = getComponentState().getRange();
+ if (range instanceof SequenceRange) {
+ SequenceRange sequenceRange = (SequenceRange) range;
+
+ begin = sequenceRange.getFirstRow();
+ int iRows = sequenceRange.getRows();
+
+ if (iRows > 0) {
+ // end is zero-based
+ end = begin + iRows - 1;
+ }
+ }
+
+ SequenceIterationStatus iterationStatus = new
SequenceIterationStatus(begin, end,
+ getRowIndex(), getRowCount());
+
+ requestMap.put(iterationStatusVar, iterationStatus);
+ } else {
+ requestMap.remove(iterationStatusVar);
+ }
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public void setValueBinding(String name, javax.faces.el.ValueBinding binding) {
+ if ("value".equals(name)) {
+ resetDataModel();
+ } else if ("first".equals(name) || "rows".equals(name)) {
+ updateState();
+ }
+
+ super.setValueBinding(name, binding);
+ }
+
+ @Override
+ public void setValueExpression(String name, ValueExpression binding) {
+ if ("value".equals(name)) {
+ resetDataModel();
+ } else if ("first".equals(name) || "rows".equals(name)) {
+ updateState();
+ }
+
+ super.setValueExpression(name, binding);
+ }
+
+ @Override
+ protected void preEncodeBegin(FacesContext context) {
+ super.preEncodeBegin(context);
+
+ updateState();
+ }
+
+ public int getRelativeRowIndex() {
+ int rowIndex = getRowIndex();
+ int rows = getRows();
+
+ if (rows > 1) {
+ return rowIndex % rows;
+ }
+
+ return rowIndex;
+ }
+
+ public String getRelativeClientId(FacesContext facesContext) {
+
+ //save current rowKey
+ Object savedRowKey = getRowKey();
+
+ setRowKey(null);
+
+ //retrieve base client id without rowkey part
+ StringBuilder baseId = new StringBuilder(getClientId(facesContext));
+
+ //restore rowKey
+ setRowKey(savedRowKey);
+
+ String result =
baseId.append(UINamingContainer.getSeparatorChar(facesContext)).append(getRelativeRowIndex())
+ .toString();
+
+ return result;
+ }
+}
Copied:
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxChildrenRenderer.java
(from rev 19038,
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxChildrenRenderer.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxChildrenRenderer.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,222 @@
+/**
+ * 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.renderkit;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.component.AjaxChildrenEncoder;
+import org.ajax4jsf.component.AjaxOutput;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.renderkit.AjaxRenderer;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+
+/**
+ * @author shura
+ */
+public abstract class AjaxChildrenRenderer extends AjaxComponentRendererBase implements
AjaxRenderer {
+ public static final String[] SPECIAL_COMPONENTS_TYPES =
{"org.ajax4jsf.Bundle" /* UILoadBundle.COMPONENT_TYPE */,
+ "org.apache.myfaces.AliasBean",
"org.apache.myfaces.AliasBeansScope"};
+
+ private static final String SPECIAL_TYPES_PARAMETER =
"org.ajax4jsf.CONTROL_COMPONENTS";
+ private static final Logger LOG = RichfacesLogger.RENDERKIT.getLogger();
+
+ private Set<String> specialComponentTypes = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.renderkit.AjaxRenderer#encodeAjaxChildren(javax.faces.context
+ * .FacesContext, javax.faces.component.UIComponent, java.lang.String,
+ * java.util.Set, java.util.Set)
+ */
+ public void encodeAjaxChildren(FacesContext context, UIComponent component, String
path, Set<String> ids,
+ Set<String> renderedAreas) throws IOException {
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(Messages.getMessage(Messages.ENCODE_CHILD_AJAX_INFO, path,
component.getId()));
+ }
+
+ String currentPath = path;
+
+ if (component instanceof NamingContainer) {
+ currentPath += component.getId() + NamingContainer.SEPARATOR_CHAR;
+
+ // Do not check children if we have no id to render under naming
+ // container.
+ if (AjaxContext.getCurrentInstance(context).isLimitToList() &&
noIdUnderPath(path, ids)) {
+ return;
+ }
+ }
+
+ for (Iterator<UIComponent> it = component.getFacetsAndChildren();
it.hasNext();) {
+ UIComponent element = (UIComponent) it.next();
+
+ encodeAjaxComponent(context, element, currentPath, ids, renderedAreas);
+ }
+ }
+
+ private boolean noIdUnderPath(String path, Set<String> ids) {
+
+ // Do we have an any component for the rendering under that container ?
+ boolean noSuchId = true;
+
+ for (String id : ids) {
+ if ((null != id) && id.startsWith(path)) {
+ noSuchId = false;
+
+ break;
+ }
+ }
+
+ return noSuchId;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.renderkit.AjaxRenderer#encodeAjaxComponent(javax.faces.context
+ * .FacesContext, javax.faces.component.UIComponent, java.lang.String,
+ * java.util.Set, java.util.Set)
+ */
+ public void encodeAjaxComponent(FacesContext context, UIComponent component, String
currentPath, Set<String> ids,
+ Set<String> renderedAreas) throws IOException
{
+
+ if (component.isRendered()) { // skip not-rendered components.
+ boolean found = false;
+ boolean limitToList =
AjaxContext.getCurrentInstance(context).isLimitToList();
+ String elementId = component.getId();
+ String absoluteId = currentPath + elementId;
+
+ if (!ids.isEmpty()) {
+
+ // list for rendering may contains absolute id ( best ),
+ // component Id or client ID
+ // String clientId = element.getClientId(context);
+ if (ids.contains(absoluteId) || ids.contains(elementId)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(Messages.getMessage(Messages.RENDER_AJAX_AREA_INFO,
absoluteId));
+ }
+
+ // renderChild(context, element);
+ found = true;
+ }
+ }
+
+ //
+ if (!found && limitToList && (component instanceof
NamingContainer)
+ && noIdUnderPath(absoluteId + NamingContainer.SEPARATOR_CHAR,
ids)) {
+ return;
+ }
+
+ if (!found && !limitToList && (component instanceof
AjaxOutput)) {
+ if (((AjaxOutput) component).isAjaxRendered()) {
+
+ // renderChild(context, element);
+ found = true;
+ }
+ }
+
+ if (!found) {
+ if (component instanceof AjaxChildrenEncoder) {
+ ((AjaxChildrenEncoder) component).encodeAjaxChild(context,
currentPath, ids, renderedAreas);
+ } else {
+
+ // Special case - for control components, not produced
+ // html code - such as message bundles loaders,
+ // MyFaces aliases etc. we call encodeBegin/end methods
+ // even if components not in rendered areas.
+ boolean special = isSpecialElement(context, component);
+
+ if (special) {
+ component.encodeBegin(context);
+ }
+
+ encodeAjaxChildren(context, component, currentPath, ids,
renderedAreas);
+
+ if (special) {
+ component.encodeEnd(context);
+ }
+ }
+ } else {
+ renderedAreas.add(component.getClientId(context));
+ component.encodeAll(context);
+ }
+ }
+ }
+
+ /**
+ * Detect component as special control case - such as messages bundle
+ * loader, alias bean components etc. Type of component get by reflection
+ * from static field COMPONENT_TYPE
+ *
+ * @param context
+ * @param component
+ * @return true if encode methods must be called for this component even in
+ * not-rendered parts.
+ */
+ private boolean isSpecialElement(FacesContext context, UIComponent component) {
+ if (specialComponentTypes == null) {
+ specialComponentTypes = new HashSet<String>(10);
+
+ for (int i = 0; i < SPECIAL_COMPONENTS_TYPES.length; i++) {
+ specialComponentTypes.add(SPECIAL_COMPONENTS_TYPES[i]);
+ }
+
+ String special =
context.getExternalContext().getInitParameter(SPECIAL_TYPES_PARAMETER);
+
+ if (null != special) {
+ String[] split = special.split(",");
+
+ for (int i = 0; i < split.length; i++) {
+ specialComponentTypes.add(split[i]);
+ }
+ }
+ }
+
+ boolean result;
+
+ try {
+ String componentType = (String)
component.getClass().getField("COMPONENT_TYPE").get(null);
+
+ result = specialComponentTypes.contains(componentType);
+ } catch (Exception e) {
+
+ // exception occurs if component not have accesible COMPONENT_TYPE
+ // constant
+ // we assume that component not in special types.
+ result = false;
+ }
+
+ return result;
+ }
+}
Copied:
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxComponentRendererBase.java
(from rev 19038,
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/AjaxComponentRendererBase.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxComponentRendererBase.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxComponentRendererBase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,33 @@
+/**
+ * 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.renderkit;
+
+
+/**
+ * Base class for all Ajax enabled components. Perform common task -
+ * output javasript for component.
+ *
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:49 $
+ */
+public abstract class AjaxComponentRendererBase extends RendererBase {
+}
Copied:
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/ComponentAttribute.java
(from rev 19038,
branches/RF-7560/core/commons/src/main/java/org/richfaces/renderkit/ComponentAttribute.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/ComponentAttribute.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/ComponentAttribute.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,142 @@
+/*
+ * 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.renderkit;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * @author Nick Belaevski
+ */
+public class ComponentAttribute implements Comparable<ComponentAttribute> {
+
+ public enum Kind {
+ BOOL,
+ GENERIC,
+ URI
+ }
+
+ private final String htmlAttributeName;
+
+ private String componentAttributeName;
+
+ private Object defaultValue;
+
+ private String[] eventNames = {};
+
+ private Kind kind = Kind.GENERIC;
+
+ //TODO handling for aliases: "styleClass" -> "class"
+
+ public ComponentAttribute(String htmlAttributeName) {
+ super();
+ this.htmlAttributeName = htmlAttributeName;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the defaultValue
+ */
+ public Object getDefaultValue() {
+ return this.defaultValue;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param defaultValue the defaultValue to set
+ */
+ public void setDefaultValue(Object dafaultValue) {
+ this.defaultValue = dafaultValue;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the kind
+ */
+ public Kind getKind() {
+ return this.kind;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param kind the kind to set
+ */
+ public void setKind(Kind kind) {
+ this.kind = kind;
+ }
+
+ public static final Map<String, ComponentAttribute>
createMap(ComponentAttribute... attributes) {
+ Map<String,ComponentAttribute> result = new TreeMap<String,
ComponentAttribute>();
+
+ for (ComponentAttribute componentAttribute : attributes) {
+ result.put(componentAttribute.getComponentAttributeName(),
componentAttribute);
+ }
+
+ return result;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getHtmlAttributeName() {
+ return htmlAttributeName;
+ }
+
+ /**
+ * @return the componentAttributeName
+ */
+ public String getComponentAttributeName() {
+ return (componentAttributeName == null) ? htmlAttributeName :
componentAttributeName;
+ }
+
+ /**
+ * @param componentAttributeName the componentAttributeName to set
+ * @return
+ */
+ public ComponentAttribute setComponentAttributeName(String componentAttributeName) {
+ this.componentAttributeName = componentAttributeName;
+
+ return this;
+ }
+
+ /**
+ * @return the eventNames
+ */
+ public String[] getEventNames() {
+ return eventNames;
+ }
+
+ /**
+ * @param eventNames the eventNames to set
+ * @return
+ */
+ public ComponentAttribute setEventNames(String... eventNames) {
+ this.eventNames = eventNames;
+
+ return this;
+ }
+
+ public int compareTo(ComponentAttribute o) {
+ return getHtmlAttributeName().compareTo(o.getHtmlAttributeName());
+ }
+}
Copied:
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
(from rev 19038,
branches/RF-7560/core/commons/src/main/java/org/richfaces/renderkit/RenderKitUtils.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,468 @@
+/*
+ * 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.renderkit;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.component.behavior.ClientBehaviorHint;
+import javax.faces.component.behavior.ClientBehaviorHolder;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.richfaces.renderkit.ComponentAttribute.Kind;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class RenderKitUtils {
+
+ /**
+ *
+ */
+ static final String BEHAVIOR_SOURCE_ID = "javax.faces.source";
+
+ /**
+ *
+ */
+ static final String BEHAVIOR_EVENT_NAME = "javax.faces.behavior.event";
+
+ /**
+ *
+ */
+ private static final String XHTML_ATTRIBUTE_PREFIX = "xml:";
+
+ /**
+ *
+ */
+ private static final String XHTML_CONTENT_TYPE = "application/xhtml+xml";
+
+ // TODO - check what's in MyFaces
+ private static final String ATTRIBUTES_THAT_ARE_SET = UIComponentBase.class.getName()
+ ".attributesThatAreSet";
+
+ private static final String[] BOOLEAN_ATTRIBUTE_NAMES = { "checked",
"compact", "declare", "defer", "disabled",
+ "ismap", "multiple", "nohref", "noshade",
"nowrap", "readonly", "selected" };
+
+ private static final String[] URI_ATTRIBUTE_NAMES = { "action",
"background", "cite", "classid", "codebase",
+ "data", "href", "longdesc", "profile",
"src", "usemap" };
+
+ private static final String[] XHTML_ATTRIBUTE_NAMES = { "lang" };
+
+ private static final String DISABLED_ATTRIBUTE_NAME = "disabled";
+
+ private RenderKitUtils() {
+ // utility constructor
+ }
+
+ private static Map<String, List<ClientBehavior>>
getClientBehaviorsMap(UIComponent component) {
+ Map<String, List<ClientBehavior>> result;
+ if (component instanceof ClientBehaviorHolder) {
+ ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder)
component;
+
+ result = clientBehaviorHolder.getClientBehaviors();
+ } else {
+ result = Collections.emptyMap();
+ }
+ return result;
+ }
+
+ static boolean isDisabled(UIComponent component) {
+ Object disabledAttributeValue =
component.getAttributes().get(DISABLED_ATTRIBUTE_NAME);
+ if (disabledAttributeValue == null) {
+ return false;
+ }
+
+ if (disabledAttributeValue instanceof Boolean) {
+ return Boolean.TRUE.equals(disabledAttributeValue);
+ }
+
+ return Boolean.valueOf(disabledAttributeValue.toString());
+ }
+
+ static String escape(String s) {
+ StringBuilder sb = new StringBuilder(s.length());
+ int start = 0;
+ int end;
+
+ while ((end = s.indexOf('\'', start)) >= 0) {
+ sb.append(s, start, end);
+ sb.append("\\'");
+
+ start = end + 1;
+ }
+
+ sb.append(s, start, s.length());
+
+ return sb.toString();
+ }
+
+ static boolean chain(StringBuilder sb, Object object, boolean isChained) {
+ if (object != null) {
+ String objectString = object.toString().trim();
+ if (objectString.length() != 0) {
+ final boolean localIsChained;
+
+ if (!isChained && sb.length() != 0) {
+ // extract previously stored handler
+ String previousHandlerString = sb.toString();
+ // clear builder object
+ sb.setLength(0);
+
+ // append escaped handler
+ sb.append("'");
+ sb.append(escape(previousHandlerString));
+ sb.append("'");
+
+ localIsChained = true;
+ } else {
+ // use passed in value of chained indicator
+ localIsChained = isChained;
+ }
+
+ if (localIsChained) {
+ sb.append(",'");
+ sb.append(escape(objectString));
+ sb.append("'");
+
+ return true;
+ } else {
+ sb.append(objectString);
+ return false;
+ }
+ }
+ }
+
+ // no changes, pass chained indicator we initially used
+ return isChained;
+ }
+
+ private static Object createBehaviorsChain(Object inlineHandlerValue,
ClientBehaviorContext behaviorContext,
+ List<ClientBehavior> behaviors) {
+
+ boolean isChained = false;
+ StringBuilder result = new StringBuilder();
+
+ isChained = chain(result, inlineHandlerValue, isChained);
+ for (ClientBehavior behavior : behaviors) {
+ isChained = chain(result, behavior.getScript(behaviorContext), isChained);
+
+ if (behavior.getHints().contains(ClientBehaviorHint.SUBMITTING)) {
+ break;
+ }
+ }
+
+ if (result.length() == 0) {
+ return null;
+ }
+
+ if (isChained) {
+ result.insert(0, "jsf.util.chain(");
+ result.append(")");
+ }
+
+ return result.toString();
+ }
+
+ public static boolean shouldRenderAttribute(Object attributeValue) {
+ if (attributeValue == null) {
+ return false;
+ } else if (attributeValue instanceof String) {
+ return ((String) attributeValue).length() > 0;
+ } else if (attributeValue instanceof Boolean &&
Boolean.FALSE.equals(attributeValue)) {
+ return false;
+ } else if (attributeValue instanceof Integer && (Integer) attributeValue
== Integer.MIN_VALUE) {
+ return false;
+ } else if (attributeValue instanceof Double && (Double) attributeValue ==
Double.MIN_VALUE) {
+ return false;
+ } else if (attributeValue instanceof Character && (Character)
attributeValue == Character.MIN_VALUE) {
+ return false;
+ } else if (attributeValue instanceof Float && (Float) attributeValue ==
Float.MIN_VALUE) {
+ return false;
+ } else if (attributeValue instanceof Short && (Short) attributeValue ==
Short.MIN_VALUE) {
+ return false;
+ } else if (attributeValue instanceof Byte && (Byte) attributeValue ==
Byte.MIN_VALUE) {
+ return false;
+ } else if (attributeValue instanceof Long && (Long) attributeValue ==
Long.MIN_VALUE) {
+ return false;
+ }
+
+ return attributeValue.toString().length() > 0;
+ }
+
+ public static String prefixAttributeName(String attributeName, boolean isXhtmlMode)
{
+ if (isXhtmlMode) {
+ if (Arrays.binarySearch(XHTML_ATTRIBUTE_NAMES, attributeName) >= 0) {
+ return XHTML_ATTRIBUTE_PREFIX + attributeName;
+ }
+ }
+
+ return attributeName;
+ }
+
+ public static String prefixAttributeName(String attributeName, ResponseWriter
responseWriter) {
+ return prefixAttributeName(attributeName,
XHTML_CONTENT_TYPE.equals(responseWriter.getContentType()));
+ }
+
+ public static void renderAttribute(FacesContext facesContext, String attributeName,
Object attributeValue)
+ throws IOException {
+
+ if (!shouldRenderAttribute(attributeValue)) {
+ return;
+ }
+
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ String prefixedAttributeName = prefixAttributeName(attributeName, writer);
+
+ if (Arrays.binarySearch(URI_ATTRIBUTE_NAMES, attributeName) >= 0) {
+ writer.writeURIAttribute(prefixedAttributeName, attributeValue, null);
+ } else if (Arrays.binarySearch(BOOLEAN_ATTRIBUTE_NAMES, attributeName) >= 0)
{
+ boolean booleanAttributeValue =
Boolean.valueOf(String.valueOf(attributeValue));
+ if (booleanAttributeValue) {
+ // TODO - is passing in Boolean.TRUE value documented somewhere?
+ writer.writeAttribute(prefixedAttributeName, Boolean.TRUE, null);
+ }
+ } else {
+ writer.writeAttribute(prefixedAttributeName, attributeValue, null);
+ }
+ }
+
+ public static Object getAttributeAndBehaviorsValue(FacesContext facesContext,
UIComponent component,
+ ComponentAttribute componentAttribute) {
+ if (facesContext == null) {
+ throw new NullPointerException("facesContext");
+ }
+
+ if (component == null) {
+ throw new NullPointerException("component");
+ }
+
+ if (componentAttribute == null) {
+ throw new NullPointerException("componentAttribute");
+ }
+
+ String componentAttributeName = componentAttribute.getComponentAttributeName();
+ Object attributeValue = component.getAttributes().get(componentAttributeName);
+
+ String[] eventNames = componentAttribute.getEventNames();
+ if (eventNames.length > 0) {
+ Map<String, List<ClientBehavior>> behaviorsMap =
getClientBehaviorsMap(component);
+ if (behaviorsMap.size() > 0) {
+ for (String eventName : eventNames) {
+ if (behaviorsMap.containsKey(eventName)) {
+ List<ClientBehavior> behaviorsList =
behaviorsMap.get(eventName);
+ if (!behaviorsList.isEmpty()) {
+ // TODO - parameters handling
+ ClientBehaviorContext behaviorContext =
+
ClientBehaviorContext.createClientBehaviorContext(facesContext, component, eventName,
+ null, null);
+ attributeValue = createBehaviorsChain(attributeValue,
behaviorContext, behaviorsList);
+ }
+ break;
+ }
+ }
+ }
+ }
+ return attributeValue;
+ }
+
+ public static void renderAttributeAndBehaviors(FacesContext facesContext, UIComponent
component,
+ ComponentAttribute componentAttribute) throws IOException {
+ Object attributeValue = getAttributeAndBehaviorsValue(facesContext, component,
componentAttribute);
+ renderAttribute(facesContext, componentAttribute.getHtmlAttributeName(),
attributeValue);
+ }
+
+ public static void renderPassThroughAttributesOptimized(FacesContext context,
UIComponent component,
+ Map<String, ComponentAttribute> knownAttributesMap) throws IOException {
+
+ boolean disabled = isDisabled(component);
+ Set<String> handledAttributes = new
HashSet<String>(knownAttributesMap.size());
+ Object attributesThatAreSetObject =
component.getAttributes().get(ATTRIBUTES_THAT_ARE_SET);
+ if (attributesThatAreSetObject instanceof Collection<?>) {
+ Collection<?> attributesThatAreSet = (Collection<?>)
attributesThatAreSetObject;
+ for (Object attributeNameObject : attributesThatAreSet) {
+ if (attributeNameObject == null) {
+ continue;
+ }
+
+ String attributeName = attributeNameObject.toString();
+
+ ComponentAttribute knownAttribute =
knownAttributesMap.get(attributeName);
+ if (knownAttribute != null) {
+ handledAttributes.add(knownAttribute.getHtmlAttributeName());
+
+ if (disabled && knownAttribute.getEventNames() != null) {
+ continue;
+ }
+
+ renderAttributeAndBehaviors(context, component, knownAttribute);
+ }
+ }
+
+ // render attributes that haven't been processed yet - there can be
behaviors
+ for (ComponentAttribute knownAttribute : knownAttributesMap.values()) {
+
+ if (handledAttributes.contains(knownAttribute.getHtmlAttributeName())) {
+ continue;
+ }
+
+ renderAttributeAndBehaviors(context, component, knownAttribute);
+ }
+ } else {
+ // switch to unoptimized mode
+ renderPassThroughAttributes(context, component, knownAttributesMap);
+ }
+ }
+
+ public static void renderPassThroughAttributes(FacesContext context, UIComponent
component,
+ Map<String, ComponentAttribute> knownAttributesMap) throws IOException {
+ Collection<ComponentAttribute> attributes = knownAttributesMap.values();
+
+ renderPassThroughAttributes(context, component, attributes);
+ }
+
+ public static void renderPassThroughAttributes(FacesContext context, UIComponent
component, Collection<ComponentAttribute> attributes)
+ throws IOException {
+ boolean disabled = isDisabled(component);
+ for (ComponentAttribute knownAttribute : attributes) {
+ if (!disabled || knownAttribute.getEventNames().length == 0) {
+ renderAttributeAndBehaviors(context, component, knownAttribute);
+ }
+ }
+ }
+
+ public static String decodeBehaviors(FacesContext context, UIComponent component) {
+ if (!(component instanceof ClientBehaviorHolder)) {
+ return null;
+ }
+
+ ClientBehaviorHolder holder = (ClientBehaviorHolder) component;
+ Map<String, List<ClientBehavior>> behaviors =
holder.getClientBehaviors();
+
+ if (behaviors == null || behaviors.isEmpty()) {
+ return null;
+ }
+
+ ExternalContext externalContext = context.getExternalContext();
+ Map<String, String> parametersMap =
externalContext.getRequestParameterMap();
+ String behaviorEvent = parametersMap.get(BEHAVIOR_EVENT_NAME);
+
+ if (behaviorEvent == null) {
+ return null;
+ }
+
+ List<ClientBehavior> behaviorsForEvent = behaviors.get(behaviorEvent);
+ String behaviorSource = parametersMap.get(BEHAVIOR_SOURCE_ID);
+ String clientId = component.getClientId(context);
+
+ if (behaviorSource != null && behaviorSource.equals(clientId)) {
+ if (behaviorsForEvent != null && !behaviorsForEvent.isEmpty()) {
+ for (ClientBehavior behavior : behaviorsForEvent) {
+ behavior.decode(context, component);
+ }
+
+ return behaviorEvent;
+ }
+ }
+
+ return null;
+ }
+
+ public static Attributes attributes() {
+ return new Attributes();
+ }
+
+ public static Attributes attributes(Enum<?> ... attrs) {
+ Attributes res = new Attributes();
+ for (Enum<?> attr : attrs) {
+ res.generic(attr.toString(), attr.toString());
+ }
+
+ return res;
+ }
+
+ public static Attributes attributes(String ... attrs) {
+ Attributes res = new Attributes();
+ for (String attr : attrs) {
+ res.generic(attr, attr);
+ }
+
+ return res;
+ }
+
+ @SuppressWarnings("serial")
+ public static final class Attributes extends TreeSet<ComponentAttribute> {
+
+ private ComponentAttribute last;
+
+ public void render(FacesContext context, UIComponent component) throws
IOException {
+ renderPassThroughAttributes(context, component, this);
+ }
+
+ public Attributes generic(String name, String componentAttribute, String...
events) {
+ ComponentAttribute attribute = createAttribute(name, componentAttribute);
+ attribute.setEventNames(events);
+ attribute.setKind(Kind.GENERIC);
+ return this;
+ }
+
+ private ComponentAttribute createAttribute(String name, String
componentAttribute) {
+ ComponentAttribute attribute = new ComponentAttribute(name);
+ attribute.setComponentAttributeName(componentAttribute);
+ add(attribute);
+ last = attribute;
+ return attribute;
+ }
+
+ public Attributes uri(String name, String componentAttribute) {
+ ComponentAttribute attribute = createAttribute(name, componentAttribute);
+ attribute.setKind(Kind.URI);
+ return this;
+ }
+
+ public Attributes bool(String name, String componentAttribute) {
+ ComponentAttribute attribute = createAttribute(name, componentAttribute);
+ attribute.setKind(Kind.BOOL);
+ return this;
+ }
+
+ public Attributes defaultValue(Object value){
+ last.setDefaultValue(value);
+ return this;
+ }
+
+ }
+
+}
Copied:
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/RendererBase.java
(from rev 19044,
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java)
===================================================================
--- branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/RendererBase.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/RendererBase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,284 @@
+/**
+ * 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.renderkit;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.renderkit.RendererUtils;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+import org.richfaces.skin.Skin;
+import org.richfaces.skin.SkinFactory;
+
+/**
+ * Base Renderer for all chameleon Skin's and components.
+ * At most, make all common procedures and realise concrete work in "template"
methods.
+ *
+ * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:51 $
+ */
+public abstract class RendererBase extends Renderer {
+
+ private static final Logger LOG = RichfacesLogger.RENDERKIT.getLogger();
+ private static final RendererUtils UTILS = RendererUtils.getInstance();
+
+ private SkinFactory skinFactory = null;
+
+ /*
+ * (non-Javadoc)
+ * @see javax.faces.render.Renderer#decode(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
+ */
+ @Override
+ public void decode(FacesContext context, UIComponent component) {
+
+ // Test for correct parameters.
+ checkNull(context, component, "decode");
+
+ if (!getComponentClass().isInstance(component)) {
+ throw new
IllegalArgumentException(Messages.getMessage(Messages.COMPONENT_CLASS_ERROR,
"",
+ getComponentClass().getName()));
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(Messages.getMessage(Messages.START_DECODING_COMPONENT_INFO,
component.getClientId(context),
+ component.getClass().getName()));
+ }
+
+ preDecode(context, component);
+
+ // TODO - create set od common decoders ( UIInput, ActionSource etc. ) for
process decoding.
+ if (component.isRendered()) {
+ String behaviorEventName = RenderKitUtils.decodeBehaviors(context,
component);
+ if (behaviorEventName != null) {
+ queueComponentEventForBehaviorEvent(context, component,
behaviorEventName);
+ }
+
+ doDecode(context, component);
+ }
+ }
+
+ protected void queueComponentEventForBehaviorEvent(FacesContext context, UIComponent
component, String eventName) {
+
+ }
+
+ protected void preDecode(FacesContext context, UIComponent component) {
+ }
+
+ protected void preEncodeBegin(FacesContext context, UIComponent component) throws
IOException {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
+ */
+ @Override
+ public void encodeBegin(FacesContext context, UIComponent component) throws
IOException {
+
+ // Test for correct parameters.
+ checkForCorrectParams(context, component, "encodeBegin");
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(Messages.getMessage(Messages.START_ENCODING_COMPONENT_INFO,
component.getClientId(context),
+ component.getClass().getName()));
+ }
+
+ preEncodeBegin(context, component);
+
+ if (component.isRendered()) {
+ ResponseWriter writer = context.getResponseWriter();
+
+ doEncodeBegin(writer, context, component);
+ }
+ }
+
+ private void checkForCorrectParams(FacesContext context, UIComponent component,
String exceptionMessageParam) {
+ checkNull(context, component, exceptionMessageParam);
+
+ if (!getComponentClass().isInstance(component)) {
+ throw new
IllegalArgumentException(Messages.getMessage(Messages.COMPONENT_CLASS_ERROR,
+ component.getClientId(context), getComponentClass().getName()));
+ }
+ }
+
+ private void checkNull(Object context, Object component, String
exceptionMessageParam) {
+ if (context == null) {
+ throw new
NullPointerException(Messages.getMessage(Messages.CONTEXT_NULL_ERROR,
exceptionMessageParam));
+ }
+
+ if (component == null) {
+ throw new
NullPointerException(Messages.getMessage(Messages.COMPONENT_NULL_ERROR,
exceptionMessageParam));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
+ */
+ @Override
+ public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
+
+ // Test for correct parameters.
+ checkForCorrectParams(context, component, "encodeBegin");
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(Messages.getMessage(Messages.CHILDREN_ENCODING_COMPONENT_INFO,
component.getClientId(context),
+ component.getClass().getName()));
+ }
+
+ preEncodeBegin(context, component);
+
+ if (component.isRendered()) {
+ ResponseWriter writer = context.getResponseWriter();
+
+ doEncodeChildren(writer, context, component);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
+ */
+ @Override
+ public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
+
+ // Test for correct parameters.
+ checkForCorrectParams(context, component, "encodeEnd");
+
+ if (component.isRendered()) {
+ ResponseWriter writer = context.getResponseWriter();
+
+ doEncodeEnd(writer, context, component);
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(Messages.getMessage(Messages.FINISH_ENCODING_COMPONENT_INFO,
component.getClientId(context),
+ component.getClass().getName()));
+ }
+ }
+
+ // ==========================================================
+ // Protected common methods - for all Renderer's
+
+ /**
+ * Calculate current Skin for rendering.
+ *
+ * @param context - current {@link FacesContext }
+ * @return
+ */
+ protected Skin getSkin(FacesContext context) {
+ if (skinFactory == null) {
+ skinFactory = SkinFactory.getInstance();
+ }
+
+ return skinFactory.getSkin(context);
+ }
+
+ /**
+ * Due to big number of common utility methods, base renderer divide to 2 classes -
renderer and utils.
+ * since use static methods of utility class breack object paradigm, we use getter
for concrete util instance.
+ * Developer can override any utility metod in 2 stages :
+ * 1) Create subclass of {@link RendererUtils} and override utility method.
+ * 2) Override this method for return instance of such subclass.
+ *
+ * @return Returns the utils.
+ */
+ public RendererUtils getUtils() {
+ return UTILS;
+ }
+
+ /**
+ * Get base component slass , targetted for this renderer. Used for check arguments
in decode/encode.
+ *
+ * @return
+ */
+ protected Class<? extends UIComponent> getComponentClass() {
+ //TODO - do we need this function?
+ return UIComponent.class;
+ }
+
+ /**
+ * Template method for custom decoding of concrete renderer.
+ * All parameters checking if performed in original {@see decode } method.
+ *
+ * @param context
+ * @param component
+ */
+ protected void doDecode(FacesContext context, UIComponent component) {
+ }
+
+ /**
+ * Template method for custom start encoding of concrete renderer.
+ * All parameters checking and writer is performed in original {@link encodeBegin }
method.
+ *
+ * @param writer
+ * @param context
+ * @param component
+ */
+ protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component)
+ throws IOException {
+ }
+
+ /**
+ * @param writer
+ * @param context
+ * @param component
+ */
+ protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component)
+ throws IOException {
+
+ // Hook method, must be overriden in renderers with special children processing
+ }
+
+ /**
+ * Template method for custom finish encoding of concrete renderer.
+ * All parameters checking and writer is performed in original {@link encodeEnd }
method.
+ *
+ * @param writer
+ * @param context
+ * @param component
+ * @throws IOException
+ */
+ protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ }
+
+ /**
+ * Render all children for given component.
+ *
+ * @param facesContext
+ * @param component
+ * @throws IOException
+ */
+ public void renderChildren(FacesContext facesContext, UIComponent component) throws
IOException {
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : component.getChildren()) {
+ child.encodeAll(facesContext);
+ }
+ }
+ }
+
+}
Copied:
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/SequenceRendererHelper.java
(from rev 19038,
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/SequenceRendererHelper.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/SequenceRendererHelper.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/SequenceRendererHelper.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,100 @@
+/*
+ * 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.renderkit;
+
+import org.richfaces.component.UISequence;
+import org.richfaces.component.util.HtmlUtil;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class SequenceRendererHelper {
+
+ private UISequence sequence;
+
+ private int rowIndex = -1;
+
+ private int columnIndex = 0;
+
+ private String[] rowClasses = null;
+
+ private String[] columnClasses = null;
+
+ public SequenceRendererHelper(UISequence sequence) {
+ super();
+ this.sequence = sequence;
+
+ this.rowClasses = splitClassesString((String)
sequence.getAttributes().get("rowClasses"));
+ this.columnClasses = splitClassesString((String)
sequence.getAttributes().get("columnClasses"));
+ }
+
+ private static String[] splitClassesString(String s) {
+ if (s != null) {
+ return s.split(",");
+ }
+
+ return null;
+ }
+
+ private static String getCorrespondingArrayItem(String[] strings, int idx) {
+ if (strings != null && strings.length > 0) {
+ return strings[idx % strings.length];
+ }
+
+ return null;
+ }
+
+ public UISequence getSequence() {
+ return sequence;
+ }
+
+ private void initialize() {
+ rowIndex = sequence.getRowIndex();
+ }
+
+ public void nextRow() {
+ if (rowIndex == -1) {
+ initialize();
+ }
+
+ rowIndex++;
+ columnIndex = 0;
+ }
+
+ public void nextColumn() {
+ columnIndex++;
+ }
+
+ public String getRowClass() {
+ String rowClass = (String) sequence.getAttributes().get("rowClass");
+ return HtmlUtil.concatClasses(getCorrespondingArrayItem(rowClasses, rowIndex),
rowClass);
+ }
+
+ public String getColumnClass() {
+ return getCorrespondingArrayItem(columnClasses, columnIndex);
+ }
+
+ public boolean hasWalkedOverRows() {
+ return rowIndex != -1;
+ }
+}
Modified:
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/util/FormUtil.java
===================================================================
---
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/util/FormUtil.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/renderkit/util/FormUtil.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -22,7 +22,6 @@
package org.richfaces.renderkit.util;
import org.ajax4jsf.renderkit.RendererUtils;
-import org.richfaces.component.EnclosingFormRequiredException;
import org.richfaces.component.SwitchType;
import javax.faces.component.UIComponent;
Copied:
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/view/facelets/EmptyHandler.java
(from rev 19038,
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/EmptyHandler.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/view/facelets/EmptyHandler.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/view/facelets/EmptyHandler.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,53 @@
+/**
+ * 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.view.facelets;
+
+import javax.el.ELException;
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.FaceletException;
+import javax.faces.view.facelets.TagConfig;
+import javax.faces.view.facelets.TagHandler;
+import java.io.IOException;
+
+/**
+ * This if "empty" facelets tag handler stub. This handler used to ignore tags
on a page.
+ * At most, it used to bypass <jsp:root> and other tags, so we can use same
markup for an facelets an jsp pages.
+ *
+ * @author asmirnov
+ */
+public class EmptyHandler extends TagHandler {
+ public EmptyHandler(TagConfig config) {
+ super(config);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext,
javax.faces.component.UIComponent)
+ */
+ public void apply(FaceletContext ctx, UIComponent parent)
+ throws IOException, FacesException, FaceletException, ELException {
+
+ this.nextHandler.apply(ctx, parent);
+ }
+}
Copied:
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/view/facelets/RowKeyConverterRule.java
(from rev 19038,
branches/RF-7560/core/impl/src/main/java/org/ajax4jsf/webapp/taglib/RowKeyConverterRule.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/view/facelets/RowKeyConverterRule.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/main/java/org/richfaces/view/facelets/RowKeyConverterRule.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,94 @@
+/**
+ * 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.view.facelets;
+
+import org.richfaces.component.UIDataAdaptor;
+
+import javax.faces.convert.Converter;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+/**
+ * Apply rowKeyConverter to component
+ *
+ * @author Maksim Kaszynski
+ * @since 3.3.1
+ */
+public class RowKeyConverterRule extends MetaRule {
+ public static final RowKeyConverterRule INSTANCE = new RowKeyConverterRule();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.sun.facelets.tag.MetaRule#applyRule(java.lang.String,
+ * com.sun.facelets.tag.TagAttribute,
+ * com.sun.facelets.tag.MetadataTarget)
+ */
+ @Override
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
{
+ if (meta.isTargetInstanceOf(UIDataAdaptor.class)) {
+ if ("rowKeyConverter".equals(name)) {
+ if (attribute.isLiteral()) {
+ return new StaticConverterMetadata(attribute.getValue());
+ } else {
+ return new DynamicConverterMetaData(attribute);
+ }
+ }
+ }
+
+ return null;
+ }
+
+ static final class DynamicConverterMetaData extends Metadata {
+ private final TagAttribute attribute;
+
+ public DynamicConverterMetaData(TagAttribute attribute) {
+ super();
+ this.attribute = attribute;
+ }
+
+ @Override
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((UIDataAdaptor) instance).setValueExpression("rowKeyConverter",
+ attribute.getValueExpression(ctx, Converter.class));
+ }
+ }
+
+ static final class StaticConverterMetadata extends Metadata {
+ private final String converterId;
+
+ public StaticConverterMetadata(String converterId) {
+ super();
+ this.converterId = converterId;
+ }
+
+ @Override
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ Converter converter =
ctx.getFacesContext().getApplication().createConverter(converterId);
+
+ ((UIDataAdaptor) instance).setRowKeyConverter(converter);
+ }
+ }
+}
Copied:
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/component/DataAdaptorTestCase.java
(from rev 19038,
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/DataAdaptorTestCase.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/component/DataAdaptorTestCase.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/component/DataAdaptorTestCase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -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(facesContext, 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(facesContext, 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(facesContext, 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(facesContext, 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(facesContext, 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(facesContext, rowKey);
+ childAdaptor.setRowKey(facesContext, childKey);
+
+ assertNull(input.getSubmittedValue());
+ assertNull(input.getLocalValue());
+ assertTrue(input.isValid());
+ assertFalse(input.isLocalValueSet());
+
+ input.setSubmittedValue("submittedValue");
+ input.setValue("value");
+
+ childAdaptor.setRowKey(facesContext, null);
+ mockDataAdaptor.setRowKey(facesContext, Integer.valueOf(3));
+ childAdaptor.setRowKey(facesContext, Integer.valueOf(0));
+
+ assertNull(input.getSubmittedValue());
+ assertNull(input.getLocalValue());
+ assertFalse(input.isLocalValueSet());
+
+ childAdaptor.setRowKey(facesContext, null);
+ mockDataAdaptor.setRowKey(facesContext, rowKey);
+ childAdaptor.setRowKey(facesContext, 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(facesContext, Integer.valueOf(1));
+ assertEquals(data.get(1), getVarValue());
+
+ new ValueChangeEvent(input, null, "testValue").queue();
+ mockDataAdaptor.setRowKey(facesContext, 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;
+ }
+
+}
Copied:
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/component/MockDataAdaptor.java
(from rev 19038,
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/MockDataAdaptor.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/component/MockDataAdaptor.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/component/MockDataAdaptor.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,66 @@
+/*
+ * 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.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);
+ }
+
+}
Copied:
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/component/MockDataAdaptorComponentState.java
(from rev 19038,
branches/RF-7560/core/impl/src/test/java/org/richfaces/component/MockDataAdaptorComponentState.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/component/MockDataAdaptorComponentState.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/component/MockDataAdaptorComponentState.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -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;
+ }
+}
Copied:
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/MockClientBehaviorHolder.java
(from rev 19038,
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/MockClientBehaviorHolder.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/MockClientBehaviorHolder.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/MockClientBehaviorHolder.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,58 @@
+/*
+ * 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.renderkit;
+
+import static org.jboss.test.faces.mock.FacesMockController.invokeCurrent;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorHolder;
+
+import org.easymock.IMocksControl;
+import org.jboss.test.faces.mock.component.MockUIComponent;
+
+public class MockClientBehaviorHolder extends MockUIComponent implements
ClientBehaviorHolder {
+
+ public MockClientBehaviorHolder(IMocksControl control, String name) {
+ super(control, name);
+ }
+
+ public void addClientBehavior(String eventName, ClientBehavior behavior) {
+ invokeCurrent(this, eventName, behavior);
+ }
+
+ public Map<String, List<ClientBehavior>> getClientBehaviors() {
+ return invokeCurrent(this);
+ }
+
+ public String getDefaultEventName() {
+ return invokeCurrent(this);
+ }
+
+ public Collection<String> getEventNames() {
+ return invokeCurrent(this);
+ }
+
+}
Copied:
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java
(from rev 19038,
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,377 @@
+/*
+ * 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.renderkit;
+
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.same;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.component.behavior.ClientBehaviorHint;
+import javax.faces.component.behavior.ClientBehaviorHolder;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.easymock.EasyMock;
+import org.jboss.test.faces.mock.MockFacesEnvironment;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class RenderKitUtilsMocksTest {
+
+ /**
+ *
+ */
+ private static final String CLIENT_ID = "submittedId";
+
+ private MockFacesEnvironment facesEnvironment;
+
+ private ResponseWriter responseWriter;
+
+ private FacesContext facesContext;
+
+ private ExternalContext externalContext;
+
+ private Map<String, Object> componentAttributes;
+
+ private Map<String, List<ClientBehavior>> behaviorsMap;
+
+ private Map<String, ComponentAttribute> knownAttributes;
+
+ @Before
+ public void setUp() throws Exception {
+ facesEnvironment =
MockFacesEnvironment.createEnvironment().withExternalContext();
+
+ facesContext = facesEnvironment.getFacesContext();
+ externalContext = facesEnvironment.getExternalContext();
+
+ responseWriter = facesEnvironment.createMock(ResponseWriter.class);
+ expect(facesContext.getResponseWriter()).andStubReturn(responseWriter);
+
expect(responseWriter.getContentType()).andStubReturn("application/xhtml+xml");
+
+ componentAttributes = new HashMap<String, Object>();
+ behaviorsMap = new HashMap<String, List<ClientBehavior>>();
+ knownAttributes = new TreeMap<String, ComponentAttribute>();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ this.facesEnvironment.verify();
+ this.facesEnvironment.release();
+
+ this.facesEnvironment = null;
+ this.responseWriter = null;
+ this.facesContext = null;
+ this.externalContext = null;
+ this.componentAttributes = null;
+ this.behaviorsMap = null;
+ this.knownAttributes = null;
+ }
+
+ private UIComponent createMockComponent() {
+ UIComponent component = facesEnvironment.createMock(UIComponent.class);
+ expect(component.getAttributes()).andStubReturn(componentAttributes);
+ expect(component.getClientId(same(facesContext))).andStubReturn(CLIENT_ID);
+ return component;
+ }
+
+ private ClientBehaviorHolder createMockClientBehaviorHolder() {
+ UIComponent component =
facesEnvironment.createMock(MockClientBehaviorHolder.class);
+ expect(component.getClientId(same(facesContext))).andStubReturn(CLIENT_ID);
+ expect(component.getAttributes()).andStubReturn(componentAttributes);
+ ClientBehaviorHolder behaviorHolder = (ClientBehaviorHolder) component;
+ expect(behaviorHolder.getClientBehaviors()).andStubReturn(behaviorsMap);
+ expect(behaviorHolder.getEventNames()).andStubReturn(
+ Arrays.asList("click", "action", "mousemove",
"keypress", "blur", "contextmenu"));
+ return behaviorHolder;
+ }
+
+ @Test
+ public void testRenderPassThroughAttributes() throws Exception {
+ knownAttributes.put("disabled", new
ComponentAttribute("disabled"));
+ knownAttributes.put("checked", new
ComponentAttribute("checked"));
+ knownAttributes.put("style", new
ComponentAttribute("style"));
+ knownAttributes.put("src", new ComponentAttribute("src"));
+ knownAttributes.put("lang", new ComponentAttribute("lang"));
+ knownAttributes.put("class", new
ComponentAttribute("class").setComponentAttributeName("styleClass"));
+
+ componentAttributes.put("disabled", Boolean.TRUE);
+ componentAttributes.put("checked", Boolean.FALSE);
+ componentAttributes.put("style", "color:red");
+ componentAttributes.put("src", "urn:abc");
+ componentAttributes.put("facelets.Mark", 123);
+ componentAttributes.put("lang", "ru");
+ componentAttributes.put("styleClass", "rich-component");
+
+ UIComponent component = createMockComponent();
+
+ responseWriter.writeAttribute(eq("disabled"), eq(Boolean.TRUE),
EasyMock.<String>isNull());
+ // checked attribute shouldn't be rendered - it's 'false'
+ responseWriter.writeAttribute(eq("style"), eq("color:red"),
EasyMock.<String>isNull());
+ responseWriter.writeURIAttribute(eq("src"), eq("urn:abc"),
EasyMock.<String>isNull());
+ // facelets.Mark shouldn't be rendered - it's unknown
+ responseWriter.writeAttribute(eq("xml:lang"), eq("ru"),
EasyMock.<String>isNull());
+ responseWriter.writeAttribute(eq("class"),
eq("rich-component"), EasyMock.<String>isNull());
+
+ facesEnvironment.replay();
+
+ RenderKitUtils.renderPassThroughAttributes(facesContext, component,
knownAttributes);
+ }
+
+ private ClientBehavior createClientBehavior(String handlerData,
Set<ClientBehaviorHint> hints) {
+ ClientBehavior behavior = facesEnvironment.createMock(ClientBehavior.class);
+ expect(behavior.getScript(EasyMock.<ClientBehaviorContext>
notNull())).andStubReturn(
+ MessageFormat.format("prompt({0})", handlerData));
+
+ expect(behavior.getHints()).andStubReturn(hints);
+ return behavior;
+ }
+
+ @Test
+ public void testBehaviors() throws Exception {
+ knownAttributes.put("onclick", new
ComponentAttribute("onclick")
+ .setEventNames(new String[] { "click", "action" }));
+ knownAttributes.put("onmousemove", new
ComponentAttribute("onmousemove")
+ .setEventNames(new String[] { "mousemove" }));
+ knownAttributes.put("onkeypress", new
ComponentAttribute("onkeypress")
+ .setEventNames(new String[] { "keypress" }));
+ knownAttributes.put("oncontextmenu", new
ComponentAttribute("oncontextmenu")
+ .setEventNames(new String[] { "contextmenu" }));
+
+ componentAttributes.put("onkeypress", "alert(keypress)");
+ componentAttributes.put("onmousemove", "alert(mousemove)");
+ componentAttributes.put("onclick", "alert(click)");
+
+ Set<ClientBehaviorHint> emptyHintsSet =
EnumSet.noneOf(ClientBehaviorHint.class);
+ Set<ClientBehaviorHint> submittingHintsSet =
EnumSet.of(ClientBehaviorHint.SUBMITTING);
+
+ ClientBehavior keypressBehavior = createClientBehavior("keypress",
emptyHintsSet);
+ ClientBehavior actionBehavior1 = createClientBehavior("action1",
emptyHintsSet);
+ ClientBehavior actionBehavior2 = createClientBehavior("action2",
submittingHintsSet);
+ ClientBehavior actionBehavior3 = createClientBehavior("action3",
emptyHintsSet);
+ ClientBehavior contextmenuBehavior =
createClientBehavior("contextmenu", emptyHintsSet);
+
+ behaviorsMap.put("keypress", Arrays.asList(keypressBehavior));
+ behaviorsMap.put("action", Arrays.asList(actionBehavior1,
actionBehavior2, actionBehavior3));
+ behaviorsMap.put("contextmenu", Arrays.asList(contextmenuBehavior));
+
+ ClientBehaviorHolder behaviorHolder = createMockClientBehaviorHolder();
+ UIComponent component = (UIComponent) behaviorHolder;
+
+ responseWriter.writeAttribute(eq("onkeypress"),
eq("jsf.util.chain('alert(keypress)','prompt(keypress)')"),
+ EasyMock.<String>isNull());
+ responseWriter.writeAttribute(eq("onclick"),
+
eq("jsf.util.chain('alert(click)','prompt(action1)','prompt(action2)')"),
EasyMock.<String>isNull());
+ responseWriter.writeAttribute(eq("onmousemove"),
eq("alert(mousemove)"), EasyMock.<String>isNull());
+ responseWriter.writeAttribute(eq("oncontextmenu"),
eq("prompt(contextmenu)"), EasyMock.<String>isNull());
+
+ facesEnvironment.replay();
+
+ RenderKitUtils.renderPassThroughAttributes(facesContext, component,
knownAttributes);
+ }
+
+ private UIComponent setupBehaviorsTestForDisabledComponent() throws IOException {
+ knownAttributes.put("style", new
ComponentAttribute("style"));
+ knownAttributes.put("onclick", new
ComponentAttribute("onclick")
+ .setEventNames(new String[] { "click", "action" }));
+ knownAttributes.put("onmousemove", new
ComponentAttribute("onmousemove")
+ .setEventNames(new String[] { "mousemove" }));
+
+ componentAttributes.put("onmousemove", "alert(mousemove)");
+ componentAttributes.put("onclick", "alert(click)");
+ componentAttributes.put("style", "color:green");
+
+ Set<ClientBehaviorHint> emptyHintsSet =
EnumSet.noneOf(ClientBehaviorHint.class);
+
+ ClientBehavior actionBehavior1 = createClientBehavior("action1",
emptyHintsSet);
+ behaviorsMap.put("action", Arrays.asList(actionBehavior1));
+
+ ClientBehaviorHolder behaviorHolder = createMockClientBehaviorHolder();
+ UIComponent component = (UIComponent) behaviorHolder;
+ return component;
+ }
+
+ @Test
+ public void testBehaviorsForDisabledComponent() throws Exception {
+ componentAttributes.put("disabled", Boolean.TRUE);
+ UIComponent component = setupBehaviorsTestForDisabledComponent();
+
+ responseWriter.writeAttribute(eq("style"), eq("color:green"),
EasyMock.<String>isNull());
+
+ facesEnvironment.replay();
+
+ RenderKitUtils.renderPassThroughAttributes(facesContext, component,
knownAttributes);
+ }
+
+ @Test
+ public void testBehaviorsForNonDisabledComponent() throws Exception {
+ componentAttributes.put("disabled", Boolean.FALSE);
+ UIComponent component = setupBehaviorsTestForDisabledComponent();
+
+ responseWriter.writeAttribute(eq("onclick"),
eq("jsf.util.chain('alert(click)','prompt(action1)')"),
+ EasyMock.<String>isNull());
+ responseWriter.writeAttribute(eq("onmousemove"),
+ eq("alert(mousemove)"), EasyMock.<String>isNull());
+ responseWriter.writeAttribute(eq("style"), eq("color:green"),
EasyMock.<String>isNull());
+
+ facesEnvironment.replay();
+
+ RenderKitUtils.renderPassThroughAttributes(facesContext, component,
knownAttributes);
+ }
+
+ public void checkDisabled(Object attributeValue, boolean expectedValue) throws
Exception {
+ componentAttributes.put("disabled", attributeValue);
+
+ UIComponent component = createMockComponent();
+ facesEnvironment.replay();
+ assertTrue(expectedValue == RenderKitUtils.isDisabled(component));
+ }
+
+ @Test
+ public void testIsDisabled() throws Exception {
+ checkDisabled(Boolean.TRUE, true);
+ }
+
+ @Test
+ public void testIsDisabledString() throws Exception {
+ checkDisabled("true", true);
+ }
+
+ @Test
+ public void testIsNonDisabled() throws Exception {
+ checkDisabled(Boolean.FALSE, false);
+ }
+
+ @Test
+ public void testIsNonDisabledString() throws Exception {
+ checkDisabled("false", false);
+ }
+
+ @Test
+ public void testIsNonDisabledNull() throws Exception {
+ checkDisabled(null, false);
+ }
+
+ private UIComponent setupTestDecodeBehaviors(String behaviorSourceId, String
behaviorEventName) throws Exception {
+ ClientBehaviorHolder behaviorHolder = createMockClientBehaviorHolder();
+ UIComponent component = (UIComponent) behaviorHolder;
+
+ Map<String, String> requestParameterMap = new HashMap<String,
String>();
+ requestParameterMap.put(RenderKitUtils.BEHAVIOR_SOURCE_ID, behaviorSourceId);
+ requestParameterMap.put(RenderKitUtils.BEHAVIOR_EVENT_NAME, behaviorEventName);
+
expect(externalContext.getRequestParameterMap()).andStubReturn(requestParameterMap);
+
+ ClientBehavior actionBehavior = createClientBehavior("action1",
EnumSet.of(ClientBehaviorHint.SUBMITTING));
+ ClientBehavior actionBehavior1 = createClientBehavior("action2",
EnumSet.of(ClientBehaviorHint.SUBMITTING));
+ behaviorsMap.put("action", Arrays.asList(actionBehavior,
actionBehavior1));
+
+ ClientBehavior blurBehavior = createClientBehavior("blur1",
EnumSet.of(ClientBehaviorHint.SUBMITTING));
+ behaviorsMap.put("blur", Arrays.asList(blurBehavior));
+
+ return component;
+ }
+
+ @Test
+ public void testDecodeActionBehaviors() throws Exception {
+ UIComponent component = setupTestDecodeBehaviors(CLIENT_ID, "action");
+
+ List<ClientBehavior> behaviors = behaviorsMap.get("action");
+ for (ClientBehavior clientBehavior : behaviors) {
+ clientBehavior.decode(same(facesContext), same(component));
+ expectLastCall();
+ }
+
+ facesEnvironment.replay();
+
+ assertEquals("action", RenderKitUtils.decodeBehaviors(facesContext,
component));
+ }
+
+ @Test
+ public void testDecodeBlurBehaviors() throws Exception {
+ UIComponent component = setupTestDecodeBehaviors(CLIENT_ID, "blur");
+
+ List<ClientBehavior> behaviors = behaviorsMap.get("blur");
+ for (ClientBehavior clientBehavior : behaviors) {
+ clientBehavior.decode(same(facesContext), same(component));
+ expectLastCall();
+ }
+
+ facesEnvironment.replay();
+
+ assertEquals("blur", RenderKitUtils.decodeBehaviors(facesContext,
component));
+ }
+
+ @Test
+ public void testDecodeNonMatchingClientId() throws Exception {
+ UIComponent component = setupTestDecodeBehaviors("wrongId",
"action");
+
+ //nothing should be called - clientId is not matched
+
+ facesEnvironment.replay();
+
+ assertNull(RenderKitUtils.decodeBehaviors(facesContext, component));
+ }
+
+ @Test
+ public void testDecodeNoSubmittedBehavior() throws Exception {
+ UIComponent component = setupTestDecodeBehaviors(CLIENT_ID, null);
+
+ //nothing should be called - no behavior event information was submitted
+
+ facesEnvironment.replay();
+
+ assertNull(RenderKitUtils.decodeBehaviors(facesContext, component));
+ }
+
+ @Test
+ public void testDecodeContextMenuBehaviors() throws Exception {
+ UIComponent component = setupTestDecodeBehaviors(CLIENT_ID,
"contextmenu");
+
+ //nothing should be called - no context menu behaviors were created
+
+ facesEnvironment.replay();
+
+ assertNull(RenderKitUtils.decodeBehaviors(facesContext, component));
+ }
+}
\ No newline at end of file
Copied:
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java
(from rev 19038,
branches/RF-7560/core/commons/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java)
===================================================================
---
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java
(rev 0)
+++
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,110 @@
+/*
+ * 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.renderkit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class RenderKitUtilsTest {
+
+ @Test
+ public void testEscape() throws Exception {
+ assertEquals("", RenderKitUtils.escape(""));
+ assertEquals("abcd", RenderKitUtils.escape("abcd"));
+ assertEquals("\\'abcd",
RenderKitUtils.escape("'abcd"));
+ assertEquals("abcd\\'",
RenderKitUtils.escape("abcd'"));
+ assertEquals("ab\\'cd",
RenderKitUtils.escape("ab'cd"));
+ assertEquals("ab\\'\\'cd",
RenderKitUtils.escape("ab''cd"));
+ assertEquals("ab\\'c\\'d",
RenderKitUtils.escape("ab'c'd"));
+ }
+
+ @Test
+ public void testChain() throws Exception {
+ StringBuilder sb = new StringBuilder();
+
+ assertFalse(RenderKitUtils.chain(sb, "", false));
+ assertTrue(sb.length() == 0);
+ assertFalse(RenderKitUtils.chain(sb, null, false));
+ assertTrue(sb.length() == 0);
+
+ assertFalse(RenderKitUtils.chain(sb, "test", false));
+ assertEquals("test", sb.toString());
+
+ assertFalse(RenderKitUtils.chain(sb, "", false));
+ assertEquals("test", sb.toString());
+
+ assertTrue(RenderKitUtils.chain(sb, "another'object", false));
+ assertEquals("'test','another\\'object'",
sb.toString());
+
+ assertTrue(RenderKitUtils.chain(sb, "one more", true));
+ assertEquals("'test','another\\'object','one
more'", sb.toString());
+ }
+
+ @Test
+ public void testShouldRenderAttribute() throws Exception {
+ assertFalse(RenderKitUtils.shouldRenderAttribute(null));
+
+ assertFalse(RenderKitUtils.shouldRenderAttribute(""));
+ assertTrue(RenderKitUtils.shouldRenderAttribute("test"));
+
+ assertTrue(RenderKitUtils.shouldRenderAttribute(new Object()));
+
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Long.valueOf(10)));
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Long.valueOf(0)));
+ assertFalse(RenderKitUtils.shouldRenderAttribute(Long.MIN_VALUE));
+
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Integer.valueOf(10)));
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Integer.valueOf(0)));
+ assertFalse(RenderKitUtils.shouldRenderAttribute(Integer.MIN_VALUE));
+
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Short.valueOf((short) 10)));
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Short.valueOf((short) 0)));
+ assertFalse(RenderKitUtils.shouldRenderAttribute(Short.MIN_VALUE));
+
+
assertTrue(RenderKitUtils.shouldRenderAttribute(Character.valueOf('a')));
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Character.valueOf((char) 13)));
+ assertFalse(RenderKitUtils.shouldRenderAttribute(Character.MIN_VALUE));
+
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Byte.valueOf((byte) 10)));
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Byte.valueOf((byte) 0)));
+ assertFalse(RenderKitUtils.shouldRenderAttribute(Byte.MIN_VALUE));
+
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Double.valueOf(10)));
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Double.valueOf(0)));
+ assertFalse(RenderKitUtils.shouldRenderAttribute(Double.MIN_VALUE));
+
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Float.valueOf(10)));
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Float.valueOf(0)));
+ assertFalse(RenderKitUtils.shouldRenderAttribute(Float.MIN_VALUE));
+
+ assertTrue(RenderKitUtils.shouldRenderAttribute(Boolean.TRUE));
+ assertFalse(RenderKitUtils.shouldRenderAttribute(Boolean.FALSE));
+ }
+
+}
\ No newline at end of file
Modified:
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/util/FormUtilTest.java
===================================================================
---
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/util/FormUtilTest.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/common/ui/src/test/java/org/richfaces/renderkit/util/FormUtilTest.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -27,7 +27,6 @@
import javax.faces.component.UIViewRoot;
import org.jboss.test.faces.AbstractFacesTest;
-import org.richfaces.component.EnclosingFormRequiredException;
import org.richfaces.component.SwitchType;
/**
Modified:
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java
===================================================================
---
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -32,7 +32,6 @@
import javax.faces.event.ActionEvent;
import org.ajax4jsf.renderkit.HandlersChain;
-import org.ajax4jsf.renderkit.RendererBase;
import org.richfaces.log.RichfacesLogger;
import org.richfaces.log.Logger;
Modified:
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/LogRendererBase.java
===================================================================
---
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/LogRendererBase.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/LogRendererBase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -21,7 +21,6 @@
*/
package org.richfaces.renderkit;
-import org.ajax4jsf.renderkit.RendererBase;
import org.richfaces.component.LogMode;
/**
Modified:
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxOutputPanelRenderer.java
===================================================================
---
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxOutputPanelRenderer.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxOutputPanelRenderer.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -30,10 +30,10 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractOutputPanel;
+import org.richfaces.renderkit.RendererBase;
/**
* @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
Modified:
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java
===================================================================
---
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -37,10 +37,10 @@
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.renderkit.HandlersChain;
-import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractPoll;
+import org.richfaces.renderkit.RendererBase;
/**
* @author shura
Modified:
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
===================================================================
---
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -36,10 +36,10 @@
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.renderkit.HandlersChain;
-import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractPush;
+import org.richfaces.renderkit.RendererBase;
import org.richfaces.resource.PushResource;
/**
Modified:
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java
===================================================================
---
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -33,13 +33,13 @@
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.renderkit.HandlersChain;
-import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.ajax4jsf.renderkit.RendererUtils.ScriptHashVariableWrapper;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractAjaxStatus;
import org.richfaces.component.util.HtmlUtil;
+import org.richfaces.renderkit.RendererBase;
/**
* @author Nick Belaevski
Modified:
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/MediaOutputRenderer.java
===================================================================
---
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/MediaOutputRenderer.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/core/ui/src/main/java/org/richfaces/renderkit/html/MediaOutputRenderer.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -34,10 +34,10 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.Messages;
-import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractMediaOutput;
+import org.richfaces.renderkit.RendererBase;
/**
* @author shura
Copied:
branches/RF-7560/ui/input/ui/src/main/java/org/richfaces/renderkit/InputRendererBase.java
(from rev 19038,
branches/RF-7560/core/impl/src/main/java/org/richfaces/renderkit/InputRendererBase.java)
===================================================================
---
branches/RF-7560/ui/input/ui/src/main/java/org/richfaces/renderkit/InputRendererBase.java
(rev 0)
+++
branches/RF-7560/ui/input/ui/src/main/java/org/richfaces/renderkit/InputRendererBase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -0,0 +1,83 @@
+/**
+ * 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.renderkit;
+
+import org.ajax4jsf.util.SelectUtils;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import java.util.Map;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 23.01.2007
+ */
+public class InputRendererBase extends AjaxComponentRendererBase {
+ protected Class getComponentClass() {
+ return UIInput.class;
+ }
+
+ protected void doDecode(FacesContext context, UIComponent component) {
+ String clientId = component.getClientId(context);
+ Map requestParameterMap = context.getExternalContext().getRequestParameterMap();
+ String newValue = (String) requestParameterMap.get(clientId);
+
+ if (null != newValue) {
+ UIInput input = (UIInput) component;
+
+ input.setSubmittedValue(newValue);
+ }
+ }
+
+ public Object getConvertedValue(FacesContext context, UIComponent component, Object
val) throws ConverterException {
+ return SelectUtils.getConvertedUIInputValue(context, (UIInput) component,
(String) val);
+ }
+
+ public String getInputValue(FacesContext context, UIComponent component) {
+ UIInput input = (UIInput) component;
+ String value = (String) input.getSubmittedValue();
+
+ if (value == null) {
+ Object curVal = input.getValue();
+ Converter converter = SelectUtils.getConverterForProperty(context, input,
"value");
+
+ if (converter != null) {
+ value = converter.getAsString(context, input, curVal);
+ } else {
+ if (curVal == null) {
+ value = "";
+ } else {
+ value = curVal.toString();
+ }
+ }
+ }
+
+ if (value == null) {
+ value = "";
+ }
+
+ return value;
+ }
+}
Modified:
branches/RF-7560/ui/iteration/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java
===================================================================
---
branches/RF-7560/ui/iteration/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/iteration/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -33,7 +33,6 @@
import org.ajax4jsf.model.DataVisitResult;
import org.ajax4jsf.model.DataVisitor;
-import org.ajax4jsf.renderkit.RendererBase;
import org.richfaces.component.Row;
/**
Modified:
branches/RF-7560/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
===================================================================
---
branches/RF-7560/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -39,7 +39,6 @@
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.renderkit.AjaxEventOptions;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
-import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.AbstractDataScroller;
import org.richfaces.event.DataScrollerEvent;
Modified:
branches/RF-7560/ui/iteration/ui/src/main/java/org/richfaces/renderkit/SubTableToggleControlRendererBase.java
===================================================================
---
branches/RF-7560/ui/iteration/ui/src/main/java/org/richfaces/renderkit/SubTableToggleControlRendererBase.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/iteration/ui/src/main/java/org/richfaces/renderkit/SubTableToggleControlRendererBase.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -33,7 +33,6 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractSubTable;
Modified:
branches/RF-7560/ui/output/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java
===================================================================
---
branches/RF-7560/ui/output/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/output/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -22,10 +22,10 @@
package org.richfaces.renderkit.html;
-import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.AbstractDivPanel;
import org.richfaces.renderkit.RenderKitUtils;
+import org.richfaces.renderkit.RendererBase;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
Modified:
branches/RF-7560/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelBaseRenderer.java
===================================================================
---
branches/RF-7560/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelBaseRenderer.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelBaseRenderer.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -27,8 +27,8 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
-import org.ajax4jsf.renderkit.RendererBase;
import org.richfaces.component.UIPanel;
+import org.richfaces.renderkit.RendererBase;
/**
* @author amarkhel
Modified:
branches/RF-7560/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java
===================================================================
---
branches/RF-7560/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java 2010-08-31
16:59:42 UTC (rev 19051)
+++
branches/RF-7560/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java 2010-08-31
17:20:11 UTC (rev 19052)
@@ -16,11 +16,11 @@
import javax.faces.context.FacesContext;
import org.ajax4jsf.javascript.ScriptUtils;
-import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils;
import org.richfaces.component.AbstractPopupPanel;
import org.richfaces.json.JSONException;
import org.richfaces.json.JSONMap;
+import org.richfaces.renderkit.RendererBase;
//TODO nick - JSF have concept of library, it should be used instead of '/' in
resource names
@ResourceDependencies( { @ResourceDependency(name = "jquery.js"),
@ResourceDependency(name = "richfaces.js"),