Author: nbelaevski
Date: 2010-04-08 11:37:06 -0400 (Thu, 08 Apr 2010)
New Revision: 16748
Added:
root/framework/trunk/api/src/main/java/org/richfaces/component/AjaxContainer.java
root/framework/trunk/api/src/main/java/org/richfaces/component/MetaComponentResolver.java
root/ui/trunk/components/core/src/main/java/org/richfaces/component/AbstractRegion.java
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
root/framework/trunk/impl/src/main/java/org/richfaces/context/ExtendedPartialVisitContext.java
root/ui/trunk/components/core/src/main/resources/META-INF/a4j.taglib.xml
Log:
https://jira.jboss.org/jira/browse/RF-7650
Added: root/framework/trunk/api/src/main/java/org/richfaces/component/AjaxContainer.java
===================================================================
--- root/framework/trunk/api/src/main/java/org/richfaces/component/AjaxContainer.java
(rev 0)
+++
root/framework/trunk/api/src/main/java/org/richfaces/component/AjaxContainer.java 2010-04-08
15:37:06 UTC (rev 16748)
@@ -0,0 +1,35 @@
+/*
+ * 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 javax.faces.context.PartialViewContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface AjaxContainer {
+
+ public static final String META_COMPONENT_ID = "region";
+
+ public static final String DEFAULT_RENDER_ID =
PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS;
+}
Added:
root/framework/trunk/api/src/main/java/org/richfaces/component/MetaComponentResolver.java
===================================================================
---
root/framework/trunk/api/src/main/java/org/richfaces/component/MetaComponentResolver.java
(rev 0)
+++
root/framework/trunk/api/src/main/java/org/richfaces/component/MetaComponentResolver.java 2010-04-08
15:37:06 UTC (rev 16748)
@@ -0,0 +1,39 @@
+/*
+ * 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 javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface MetaComponentResolver {
+
+ // TODO - do we want to make this configurable in web.xml?
+ public static final char META_COMPONENT_SEPARATOR_CHAR = '@';
+
+ public String resolveClientId(FacesContext facesContext, UIComponent
contextComponent,
+ String componentId, String metaId);
+
+}
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2010-04-07
23:22:06 UTC (rev 16747)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2010-04-08
15:37:06 UTC (rev 16748)
@@ -23,17 +23,11 @@
package org.ajax4jsf.renderkit;
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.component.JavaScriptParameter;
-import org.ajax4jsf.javascript.JSEncoder;
-import org.ajax4jsf.javascript.JSFunctionDefinition;
-import org.ajax4jsf.javascript.JSReference;
-import org.ajax4jsf.util.HtmlDimensions;
+import static
org.richfaces.component.MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR;
import java.io.IOException;
-
import java.lang.reflect.Array;
-
+import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
@@ -53,12 +47,23 @@
import javax.faces.component.UIParameter;
import javax.faces.component.UIViewRoot;
import javax.faces.component.ValueHolder;
+import javax.faces.component.behavior.ClientBehaviorHolder;
import javax.faces.component.behavior.ClientBehaviorContext.Parameter;
-import javax.faces.component.behavior.ClientBehaviorHolder;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.convert.Converter;
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.component.JavaScriptParameter;
+import org.ajax4jsf.javascript.JSEncoder;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.JSReference;
+import org.ajax4jsf.util.HtmlDimensions;
+import org.richfaces.component.AjaxContainer;
+import org.richfaces.component.MetaComponentResolver;
+import org.richfaces.log.RichfacesLogger;
+import org.slf4j.Logger;
+
/**
* Util class for common render operations - render passthru html attributes,
* iterate over child components etc.
@@ -68,8 +73,11 @@
*
*/
public class RendererUtils {
+
public static final String DUMMY_FORM_ID = ":_form";
+ private static final Logger LOGGER = RichfacesLogger.RENDERKIT.getLogger();
+
// we'd better use this instance multithreadly quickly
private static final RendererUtils INSTANCE = new RendererUtils();
@@ -78,10 +86,13 @@
*/
private static Map<String, String> substitutions = new HashMap<String,
String>();
private static Set<String> requiredAttributes = new HashSet<String>();
+ private static Map<String, String> metaComponentSubstitutions = new
HashMap<String, String>();
static {
substitutions.put(HTML.CLASS_ATTRIBUTE, "styleClass");
requiredAttributes.add(HTML.ALT_ATTRIBUTE);
+ metaComponentSubstitutions.put(AjaxContainer.META_COMPONENT_ID,
AjaxContainer.DEFAULT_RENDER_ID);
+
Arrays.sort(HTML.PASS_THRU);
Arrays.sort(HTML.PASS_THRU_EVENTS);
Arrays.sort(HTML.PASS_THRU_BOOLEAN);
@@ -306,7 +317,7 @@
*/
public void encodePassThruWithExclusions(FacesContext context, UIComponent component,
String exclusions,
String defaultHtmlEvent) throws IOException {
-
+
if (null != exclusions) {
String[] exclusionsArray = exclusions.split(",");
@@ -316,7 +327,7 @@
public void encodePassThruWithExclusionsArray(FacesContext context, UIComponent
component, String[] exclusions,
String defaultHtmlEvent) throws IOException {
-
+
ResponseWriter writer = context.getResponseWriter();
Map<String, Object> attributes = component.getAttributes();
@@ -373,7 +384,7 @@
public void encodeAttributesFromArray(FacesContext context, UIComponent component,
String[] attrs)
throws IOException {
-
+
ResponseWriter writer = context.getResponseWriter();
Map<String, Object> attributes = component.getAttributes();
@@ -413,7 +424,7 @@
*/
public void encodeAttribute(FacesContext context, UIComponent component, Object
property, String attributeName)
throws IOException {
-
+
ResponseWriter writer = context.getResponseWriter();
Object value = component.getAttributes().get(property);
@@ -805,7 +816,7 @@
*/
public void encodeBeginForm(FacesContext context, UIComponent component,
ResponseWriter writer, String clientId)
throws IOException {
-
+
String actionURL = getActionUrl(context);
String encodeActionURL =
context.getExternalContext().encodeActionURL(actionURL);
@@ -933,9 +944,69 @@
} else if (AjaxRendererUtils.FORM.equals(id)) {
result.add(getNestingForm(context, component).getClientId(context));
} else {
- UIComponent foundComponent = findComponentFor(component, id);
+ String componentId;
+ String metaComponentId;
- result.add((foundComponent != null) ?
foundComponent.getClientId(context) : id);
+ int idx = id.indexOf(META_COMPONENT_SEPARATOR_CHAR);
+ if (idx >= 0) {
+ componentId = id.substring(0, idx);
+ metaComponentId = id.substring(idx + 1);
+ } else {
+ componentId = id;
+ metaComponentId = null;
+ }
+
+ if (metaComponentId == null) {
+ UIComponent foundComponent = findComponentFor(component,
componentId);
+ if (foundComponent != null) {
+ result.add(foundComponent.getClientId(context));
+ } else {
+ result.add(componentId);
+ }
+ } else {
+ UIComponent foundComponent;
+
+ if (componentId != null && componentId.length() != 0) {
+ foundComponent = findComponentFor(component, componentId);
+ } else {
+ foundComponent = component;
+ }
+
+ String convertedId = null;
+
+ while (foundComponent != null) {
+ if (foundComponent instanceof MetaComponentResolver) {
+ MetaComponentResolver metadataConversionComponent =
+ (MetaComponentResolver) foundComponent;
+
+ convertedId =
metadataConversionComponent.resolveClientId(context, component,
+ componentId, metaComponentId);
+
+ if (convertedId != null) {
+ break;
+ }
+ }
+
+ foundComponent = foundComponent.getParent();
+ }
+
+ if (convertedId == null) {
+ convertedId =
metaComponentSubstitutions.get(metaComponentId);
+ }
+
+ if (convertedId != null) {
+ if (AjaxRendererUtils.ALL.equals(convertedId)) {
+ result.clear();
+ result.add(AjaxRendererUtils.ALL);
+ break;
+ } else {
+ result.add(convertedId);
+ }
+ } else {
+ LOGGER.warn(
+ MessageFormat.format("''{0}'' cannot
be resolved in the current context", id));
+ }
+ }
}
}
}
@@ -1029,7 +1100,7 @@
public static void writeEventHandlerFunction(FacesContext context, UIComponent
component, String eventName)
throws IOException {
-
+
ResponseWriter writer = context.getResponseWriter();
Object script = component.getAttributes().get(eventName);
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/context/ExtendedPartialVisitContext.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/context/ExtendedPartialVisitContext.java 2010-04-07
23:22:06 UTC (rev 16747)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/ExtendedPartialVisitContext.java 2010-04-08
15:37:06 UTC (rev 16748)
@@ -21,6 +21,8 @@
*/
package org.richfaces.context;
+import static
org.richfaces.component.MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR;
+
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Collections;
@@ -53,9 +55,6 @@
*/
private static final int SHORT_ID_IN_CLIENTID_SEGMENTS_NUMBER = 2;
- // TODO - make this configurable in web.xml
- private static final char SUB_COMPONENT_SEPARATOR = '@';
-
private static final String ANY_WILDCARD = "*";
private final class CollectionProxy extends AbstractCollection<String> {
@@ -302,7 +301,7 @@
private IdParser getIdParser(String id) {
if (idParser == null) {
- idParser = new IdParser(UINamingContainer.getSeparatorChar(facesContext),
SUB_COMPONENT_SEPARATOR);
+ idParser = new IdParser(UINamingContainer.getSeparatorChar(facesContext),
META_COMPONENT_SEPARATOR_CHAR);
}
idParser.setId(id);
@@ -418,7 +417,7 @@
if (!n.isPatternNode()) {
String shortId = n.getSource();
if (shortId != null) {
- int sepIdx = shortId.indexOf(SUB_COMPONENT_SEPARATOR);
+ int sepIdx = shortId.indexOf(META_COMPONENT_SEPARATOR_CHAR);
if (sepIdx > 0) {
shortId = shortId.substring(0, sepIdx);
}
@@ -485,7 +484,7 @@
subComponentId.length());
sb.append(extendedClientId);
- sb.append(SUB_COMPONENT_SEPARATOR);
+ sb.append(META_COMPONENT_SEPARATOR_CHAR);
sb.append(subComponentId);
extendedClientId = sb.toString();
@@ -502,7 +501,7 @@
subComponentId.length());
sb.append(componentId);
- sb.append(SUB_COMPONENT_SEPARATOR);
+ sb.append(META_COMPONENT_SEPARATOR_CHAR);
sb.append(subComponentId);
componentId = sb.toString();
Added:
root/ui/trunk/components/core/src/main/java/org/richfaces/component/AbstractRegion.java
===================================================================
---
root/ui/trunk/components/core/src/main/java/org/richfaces/component/AbstractRegion.java
(rev 0)
+++
root/ui/trunk/components/core/src/main/java/org/richfaces/component/AbstractRegion.java 2010-04-08
15:37:06 UTC (rev 16748)
@@ -0,0 +1,49 @@
+/*
+ * 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 javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.Tag;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@JsfComponent(
+ tag = @Tag(name = "region")
+)
+public abstract class AbstractRegion extends UIComponentBase implements
MetaComponentResolver, AjaxContainer {
+
+ public String resolveClientId(FacesContext facesContext, UIComponent
contextComponent,
+ String componentId, String metaId) {
+
+ if (META_COMPONENT_ID.equals(metaId)) {
+ return getClientId(facesContext);
+ }
+
+ return null;
+ }
+}
Modified: root/ui/trunk/components/core/src/main/resources/META-INF/a4j.taglib.xml
===================================================================
--- root/ui/trunk/components/core/src/main/resources/META-INF/a4j.taglib.xml 2010-04-07
23:22:06 UTC (rev 16747)
+++ root/ui/trunk/components/core/src/main/resources/META-INF/a4j.taglib.xml 2010-04-08
15:37:06 UTC (rev 16748)
@@ -77,6 +77,12 @@
</component>
</tag>
<tag>
+ <tag-name>region</tag-name>
+ <component>
+ <component-type>org.richfaces.Region</component-type>
+ </component>
+ </tag>
+ <tag>
<tag-name>ajax</tag-name>
<behavior>
<behavior-id>org.ajax4jsf.behavior.Ajax</behavior-id>