You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2018/11/07 21:41:08 UTC
[myfaces] branch master updated: refactored
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/master by this push:
new 5a90c97 refactored
5a90c97 is described below
commit 5a90c97126343666058cf9e538b399586e804f49
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Wed Nov 7 22:41:04 2018 +0100
refactored
---
.../javax/faces/component/UIComponentBase.java | 2 +-
.../main/java/javax/faces/component/UIForm.java | 3 +-
.../javax/faces/component/_ComponentUtils.java | 27 ++----
.../search/FormSearchKeywordResolver.java | 20 +---
.../NamingContainerSearchKeywordResolver.java | 20 +---
.../component/search/SearchComponentUtils.java | 43 ---------
.../search/SearchExpressionHandlerImpl.java | 3 +-
.../apache/myfaces/shared/util/ComponentUtils.java | 102 +++++++--------------
.../myfaces/view/facelets/compiler/UILeaf.java | 5 +-
.../view/facelets/tag/jsf/ComponentSupport.java | 21 ++---
10 files changed, 57 insertions(+), 189 deletions(-)
diff --git a/api/src/main/java/javax/faces/component/UIComponentBase.java b/api/src/main/java/javax/faces/component/UIComponentBase.java
index b1e47a7..0353e1a 100755
--- a/api/src/main/java/javax/faces/component/UIComponentBase.java
+++ b/api/src/main/java/javax/faces/component/UIComponentBase.java
@@ -910,7 +910,7 @@ public abstract class UIComponentBase extends UIComponent
// NamingContainer but UniqueIdVendor is UIViewRoot. Anyway we just can't be 100% sure about this
// fact, so it is better to scan for the closest UniqueIdVendor. If it is not found use
// viewRoot.createUniqueId, otherwise use UniqueIdVendor.createUniqueId(context,seed).
- UniqueIdVendor parentUniqueIdVendor = _ComponentUtils.findParentUniqueIdVendor(this);
+ UniqueIdVendor parentUniqueIdVendor = _ComponentUtils.closest(UniqueIdVendor.class, this);
if (parentUniqueIdVendor == null)
{
UIViewRoot viewRoot = context.getViewRoot();
diff --git a/api/src/main/java/javax/faces/component/UIForm.java b/api/src/main/java/javax/faces/component/UIForm.java
index a5f9c2c..fb8b180 100755
--- a/api/src/main/java/javax/faces/component/UIForm.java
+++ b/api/src/main/java/javax/faces/component/UIForm.java
@@ -45,6 +45,7 @@ public class UIForm extends UIComponentBase implements NamingContainer, UniqueId
*
* @since 2.0
*/
+ @Override
public String createUniqueId(FacesContext context, String seed)
{
StringBuilder bld = null;
@@ -56,7 +57,7 @@ public class UIForm extends UIComponentBase implements NamingContainer, UniqueId
if (!isPrependId() && seed==null )
{
bld = new StringBuilder();
- UniqueIdVendor parentUniqueIdVendor = _ComponentUtils.findParentUniqueIdVendor(this);
+ UniqueIdVendor parentUniqueIdVendor = _ComponentUtils.closest(UniqueIdVendor.class, this);
if (parentUniqueIdVendor == null)
{
UIViewRoot viewRoot = context.getViewRoot();
diff --git a/api/src/main/java/javax/faces/component/_ComponentUtils.java b/api/src/main/java/javax/faces/component/_ComponentUtils.java
index 39540ca..66965aa 100755
--- a/api/src/main/java/javax/faces/component/_ComponentUtils.java
+++ b/api/src/main/java/javax/faces/component/_ComponentUtils.java
@@ -90,36 +90,23 @@ class _ComponentUtils
return null;
}
- static UIForm findParentUIForm(UIComponent component)
+ static <T> T closest(Class<T> type, UIComponent base)
{
- UIComponent parent = component.getParent();
+ UIComponent parent = base.getParent();
- while (parent != null)
+ while (parent != null)
{
- if (parent instanceof UIForm)
+ if (type.isAssignableFrom(parent.getClass()))
{
- return (UIForm) parent;
+ return (T) parent;
}
- parent = parent.getParent();
- }
- return null;
- }
-
- static UniqueIdVendor findParentUniqueIdVendor(UIComponent component)
- {
- UIComponent parent = component.getParent();
- while (parent != null)
- {
- if (parent instanceof UniqueIdVendor)
- {
- return (UniqueIdVendor) parent;
- }
parent = parent.getParent();
}
+
return null;
}
-
+
static UIComponent getRootComponent(UIComponent component)
{
UIComponent parent;
diff --git a/impl/src/main/java/org/apache/myfaces/component/search/FormSearchKeywordResolver.java b/impl/src/main/java/org/apache/myfaces/component/search/FormSearchKeywordResolver.java
index de0842c..171f16d 100644
--- a/impl/src/main/java/org/apache/myfaces/component/search/FormSearchKeywordResolver.java
+++ b/impl/src/main/java/org/apache/myfaces/component/search/FormSearchKeywordResolver.java
@@ -25,6 +25,7 @@ import javax.faces.component.search.SearchExpressionContext;
import javax.faces.component.search.SearchExpressionHint;
import javax.faces.component.search.SearchKeywordContext;
import javax.faces.component.search.SearchKeywordResolver;
+import org.apache.myfaces.shared.util.ComponentUtils;
/**
*
@@ -36,26 +37,9 @@ public class FormSearchKeywordResolver extends SearchKeywordResolver
@Override
public void resolve(SearchKeywordContext expressionContext, UIComponent current, String keyword)
{
- expressionContext.invokeContextCallback(closest(UIForm.class, current));
+ expressionContext.invokeContextCallback(ComponentUtils.closest(UIForm.class, current));
}
- private static <T> T closest(Class<T> type, UIComponent base)
- {
- UIComponent parent = base.getParent();
-
- while (parent != null)
- {
- if (type.isAssignableFrom(parent.getClass()))
- {
- return (T) parent;
- }
-
- parent = parent.getParent();
- }
-
- return null;
- }
-
@Override
public boolean isResolverForKeyword(SearchExpressionContext searchExpressionContext, String keyword)
{
diff --git a/impl/src/main/java/org/apache/myfaces/component/search/NamingContainerSearchKeywordResolver.java b/impl/src/main/java/org/apache/myfaces/component/search/NamingContainerSearchKeywordResolver.java
index 22b0b72..2596c6b 100644
--- a/impl/src/main/java/org/apache/myfaces/component/search/NamingContainerSearchKeywordResolver.java
+++ b/impl/src/main/java/org/apache/myfaces/component/search/NamingContainerSearchKeywordResolver.java
@@ -24,6 +24,7 @@ import javax.faces.component.UIComponent;
import javax.faces.component.search.SearchExpressionContext;
import javax.faces.component.search.SearchKeywordContext;
import javax.faces.component.search.SearchKeywordResolver;
+import org.apache.myfaces.shared.util.ComponentUtils;
/**
*
@@ -35,26 +36,9 @@ public class NamingContainerSearchKeywordResolver extends SearchKeywordResolver
@Override
public void resolve(SearchKeywordContext expressionContext, UIComponent current, String keyword)
{
- expressionContext.invokeContextCallback((UIComponent) closest(NamingContainer.class, current));
+ expressionContext.invokeContextCallback((UIComponent) ComponentUtils.closest(NamingContainer.class, current));
}
-
- private static <T> T closest(Class<T> type, UIComponent base)
- {
- UIComponent parent = base.getParent();
-
- while (parent != null)
- {
- if (type.isAssignableFrom(parent.getClass()))
- {
- return (T) parent;
- }
- parent = parent.getParent();
- }
-
- return null;
- }
-
@Override
public boolean isResolverForKeyword(SearchExpressionContext searchExpressionContext, String keyword)
{
diff --git a/impl/src/main/java/org/apache/myfaces/component/search/SearchComponentUtils.java b/impl/src/main/java/org/apache/myfaces/component/search/SearchComponentUtils.java
deleted file mode 100644
index 67b5987..0000000
--- a/impl/src/main/java/org/apache/myfaces/component/search/SearchComponentUtils.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.myfaces.component.search;
-
-import javax.faces.component.UIComponent;
-
-/**
- *
- */
-public class SearchComponentUtils
-{
-
- public static UIComponent getRootComponent(UIComponent component)
- {
- UIComponent parent;
- for (;;)
- {
- parent = component.getParent();
- if (parent == null)
- {
- return component;
- }
- component = parent;
- }
- }
-}
diff --git a/impl/src/main/java/org/apache/myfaces/component/search/SearchExpressionHandlerImpl.java b/impl/src/main/java/org/apache/myfaces/component/search/SearchExpressionHandlerImpl.java
index a0205a5..99aabd0 100644
--- a/impl/src/main/java/org/apache/myfaces/component/search/SearchExpressionHandlerImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/component/search/SearchExpressionHandlerImpl.java
@@ -34,6 +34,7 @@ import javax.faces.component.search.SearchExpressionHint;
import javax.faces.component.search.SearchKeywordContext;
import javax.faces.context.FacesContext;
import org.apache.myfaces.shared.renderkit.html.util.SharedStringBuilder;
+import org.apache.myfaces.shared.util.ComponentUtils;
/**
*
@@ -388,7 +389,7 @@ public class SearchExpressionHandlerImpl extends SearchExpressionHandler
char separatorChar = facesContext.getNamingContainerSeparatorChar();
if (topExpression.charAt(0) == separatorChar)
{
- UIComponent findBase = SearchComponentUtils.getRootComponent(previous);
+ UIComponent findBase = ComponentUtils.getRootComponent(previous);
handler.invokeOnComponent(searchExpressionContext, findBase, topExpression.substring(1), topCallback);
return;
}
diff --git a/impl/src/main/java/org/apache/myfaces/shared/util/ComponentUtils.java b/impl/src/main/java/org/apache/myfaces/shared/util/ComponentUtils.java
index 22048e3..01ad772 100644
--- a/impl/src/main/java/org/apache/myfaces/shared/util/ComponentUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/shared/util/ComponentUtils.java
@@ -19,82 +19,11 @@
package org.apache.myfaces.shared.util;
-import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
-import javax.faces.component.UniqueIdVendor;
-/**
- *
- * @since 1.0.2
- */
public class ComponentUtils
{
-
- /**
- * Return the parent NamingContainer of the component passed as argument.
- *
- * @param component
- * @return
- */
- public static UIComponent findParentNamingContainer(UIComponent component)
- {
- return findParentNamingContainer(component, true);
- }
-
- /**
- * Return the parent NamingContainer of the component passed as argument.
- *
- * @param component
- * @param returnRootIfNotFound
- * @return
- */
- public static UIComponent findParentNamingContainer(UIComponent component, boolean returnRootIfNotFound)
- {
- UIComponent parent = component.getParent();
- if (returnRootIfNotFound && parent == null)
- {
- return component;
- }
- while (parent != null)
- {
- if (parent instanceof NamingContainer)
- {
- return parent;
- }
-
- if (returnRootIfNotFound)
- {
- UIComponent nextParent = parent.getParent();
- if (nextParent == null)
- {
- return parent; // Root
- }
- parent = nextParent;
- }
- else
- {
- parent = parent.getParent();
- }
- }
- return null;
- }
-
- public static UniqueIdVendor findParentUniqueIdVendor(UIComponent component)
- {
- UIComponent parent = component.getParent();
-
- while (parent != null)
- {
- if (parent instanceof UniqueIdVendor)
- {
- return (UniqueIdVendor) parent;
- }
- parent = parent.getParent();
- }
- return null;
- }
-
public static String getPathToComponent(UIComponent component)
{
StringBuilder buf = new StringBuilder();
@@ -147,4 +76,35 @@ public class ComponentUtils
getPathToComponent(component.getParent(), buf);
}
+
+ public static <T> T closest(Class<T> type, UIComponent base)
+ {
+ UIComponent parent = base.getParent();
+
+ while (parent != null)
+ {
+ if (type.isAssignableFrom(parent.getClass()))
+ {
+ return (T) parent;
+ }
+
+ parent = parent.getParent();
+ }
+
+ return null;
+ }
+
+ public static UIComponent getRootComponent(UIComponent component)
+ {
+ UIComponent parent;
+ for (;;)
+ {
+ parent = component.getParent();
+ if (parent == null)
+ {
+ return component;
+ }
+ component = parent;
+ }
+ }
}
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UILeaf.java b/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UILeaf.java
index 54d7d1c..01d3b36 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UILeaf.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UILeaf.java
@@ -31,6 +31,7 @@ import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.component.ContextCallback;
import javax.faces.component.UIComponent;
+import javax.faces.component.UINamingContainer;
import javax.faces.component.UIViewRoot;
import javax.faces.component.UniqueIdVendor;
import javax.faces.component.search.UntargetableComponent;
@@ -84,7 +85,7 @@ class UILeaf extends UIComponent implements UntargetableComponent, Map<String, O
// NamingContainer but UniqueIdVendor is UIViewRoot. Anyway we just can't be 100% sure about this
// fact, so it is better to scan for the closest UniqueIdVendor. If it is not found use
// viewRoot.createUniqueId, otherwise use UniqueIdVendor.createUniqueId(context,seed).
- UniqueIdVendor parentUniqueIdVendor = ComponentUtils.findParentUniqueIdVendor(this);
+ UniqueIdVendor parentUniqueIdVendor = ComponentUtils.closest(UniqueIdVendor.class, this);
if (parentUniqueIdVendor == null)
{
UIViewRoot viewRoot = context.getViewRoot();
@@ -111,7 +112,7 @@ class UILeaf extends UIComponent implements UntargetableComponent, Map<String, O
// idWasNull = true;
}
- UIComponent namingContainer = ComponentUtils.findParentNamingContainer(this, false);
+ UIComponent namingContainer = ComponentUtils.closest(UINamingContainer.class, this);
if (namingContainer != null)
{
String containerClientId = namingContainer.getContainerClientId(context);
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
index 4f7fb2f..a7d0a27 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
@@ -122,8 +122,7 @@ public final class ComponentSupport
return null;
}
- public static String findFacetNameByComponentInstance(
- UIComponent parent, UIComponent instance)
+ public static String findFacetNameByComponentInstance(UIComponent parent, UIComponent instance)
{
if (parent.getFacetCount() > 0)
{
@@ -131,8 +130,7 @@ public final class ComponentSupport
{
UIComponent facet = entry.getValue();
// check if this is a dynamically generated UIPanel
- if (Boolean.TRUE.equals(facet.getAttributes()
- .get(FACET_CREATED_UIPANEL_MARKER)))
+ if (Boolean.TRUE.equals(facet.getAttributes().get(FACET_CREATED_UIPANEL_MARKER)))
{
// only check the children and facets of the panel
if (facet.getChildCount() > 0)
@@ -169,8 +167,7 @@ public final class ComponentSupport
return null;
}
- public static UIComponent findChildInFacetByTagId(
- UIComponent parent, String id, String facetName)
+ public static UIComponent findChildInFacetByTagId(UIComponent parent, String id, String facetName)
{
if (parent.getFacetCount() > 0)
{
@@ -178,8 +175,7 @@ public final class ComponentSupport
if (facet != null)
{
// check if this is a dynamically generated UIPanel
- if (Boolean.TRUE.equals(facet.getAttributes()
- .get(FACET_CREATED_UIPANEL_MARKER)))
+ if (Boolean.TRUE.equals(facet.getAttributes().get(FACET_CREATED_UIPANEL_MARKER)))
{
// only check the children and facets of the panel
if (facet.getChildCount() > 0)
@@ -215,8 +211,7 @@ public final class ComponentSupport
return null;
}
- public static UIComponent findChildInChildrenByTagId(
- UIComponent parent, String id)
+ public static UIComponent findChildInChildrenByTagId(UIComponent parent, String id)
{
if (parent.getChildCount() > 0)
{
@@ -260,8 +255,7 @@ public final class ComponentSupport
{
UIComponent facet = itr.next();
// check if this is a dynamically generated UIPanel
- if (Boolean.TRUE.equals(facet.getAttributes()
- .get(FACET_CREATED_UIPANEL_MARKER)))
+ if (Boolean.TRUE.equals(facet.getAttributes().get(FACET_CREATED_UIPANEL_MARKER)))
{
// only check the children and facets of the panel
if (facet.getChildCount() > 0)
@@ -309,8 +303,7 @@ public final class ComponentSupport
Map.Entry<String, UIComponent> entry = itr.next();
UIComponent facet = entry.getValue();
// check if this is a dynamically generated UIPanel
- if (Boolean.TRUE.equals(facet.getAttributes()
- .get(FACET_CREATED_UIPANEL_MARKER)))
+ if (Boolean.TRUE.equals(facet.getAttributes().get(FACET_CREATED_UIPANEL_MARKER)))
{
// only check the children and facets of the panel
if (facet.getChildCount() > 0)