myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject svn commit: r1774639 - in /myfaces/core/branches/2.3.x: api/src/main/java/javax/faces/component/search/ impl/src/main/java/org/apache/myfaces/component/search/ impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/ impl/src/test/java/org/ap...
Date Fri, 16 Dec 2016 16:50:05 GMT
Author: tandraschko
Date: Fri Dec 16 16:50:05 2016
New Revision: 1774639

URL: http://svn.apache.org/viewvc?rev=1774639&view=rev
Log:
MYFACES-4075 SearchExpression API (reworked hints + added unit test)

Modified:
    myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/component/search/SearchExpressionHint.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/IdSearchKeywordResolver.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/SearchExpressionHandlerImpl.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/AttachedObjectTargetImpl.java
    myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/component/search/SearchExpressionImplTest.java
    myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/component/search/search1.xhtml

Modified: myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/component/search/SearchExpressionHint.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/component/search/SearchExpressionHint.java?rev=1774639&r1=1774638&r2=1774639&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/component/search/SearchExpressionHint.java
(original)
+++ myfaces/core/branches/2.3.x/api/src/main/java/javax/faces/component/search/SearchExpressionHint.java
Fri Dec 16 16:50:05 2016
@@ -32,7 +32,9 @@ public enum SearchExpressionHint
     /**
      * Indicate that the method is collecting a list of real UIComponent instances.
      */
-    RESOLVE_COMPONENT_LIST,
+    SKIP_VIRTUAL_COMPONENTS,
+    
+    RESOLVE_SINGLE_COMPONENT,
     
     /**
      * Indicate that some expressions can be resolved on the client side.

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/IdSearchKeywordResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/IdSearchKeywordResolver.java?rev=1774639&r1=1774638&r2=1774639&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/IdSearchKeywordResolver.java
(original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/IdSearchKeywordResolver.java
Fri Dec 16 16:50:05 2016
@@ -48,7 +48,7 @@ public class IdSearchKeywordResolver ext
         final String targetId = extractId(command);
         if (expressionContext.getSearchExpressionContext().getExpressionHints() != null
                 && expressionContext.getSearchExpressionContext().getExpressionHints().contains(
-                        SearchExpressionHint.RESOLVE_COMPONENT_LIST))
+                        SearchExpressionHint.SKIP_VIRTUAL_COMPONENTS))
         {
             // Avoid visit tree because in this case we need real component instances.
             // This means components inside UIData will not be scanned. 
@@ -68,7 +68,15 @@ public class IdSearchKeywordResolver ext
                             if (targetId.equals(target.getId()))
                             {
                                 expressionContext.invokeContextCallback(target);
-                                return VisitResult.COMPLETE;
+                                
+                                if (expressionContext.getSearchExpressionContext().getExpressionHints()
!= null
+                                        && expressionContext.getSearchExpressionContext().getExpressionHints().contains(
+                                                SearchExpressionHint.RESOLVE_SINGLE_COMPONENT))
+                                {
+                                    return VisitResult.COMPLETE;
+                                }
+                                
+                                return VisitResult.ACCEPT;
                             }
                             else
                             {

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/SearchExpressionHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/SearchExpressionHandlerImpl.java?rev=1774639&r1=1774638&r2=1774639&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/SearchExpressionHandlerImpl.java
(original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/component/search/SearchExpressionHandlerImpl.java
Fri Dec 16 16:50:05 2016
@@ -21,6 +21,7 @@ package org.apache.myfaces.component.sea
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import javax.faces.FacesException;
@@ -40,13 +41,28 @@ import javax.faces.context.FacesContext;
 public class SearchExpressionHandlerImpl extends SearchExpressionHandler
 {
 
+    protected Set<SearchExpressionHint> addHint(Set<SearchExpressionHint> hints,
SearchExpressionHint hint)
+    {
+        // already available
+        if (hints.contains(hint))
+        {
+            return hints;
+        }
+        
+        Set<SearchExpressionHint> newHints = new HashSet<SearchExpressionHint>(hints);
+        newHints.add(hint);
+
+        return newHints;
+    }
+    
     @Override
     public String resolveClientId(SearchExpressionContext searchExpressionContext, String
expression)
     {
         FacesContext facesContext = searchExpressionContext.getFacesContext();
         UIComponent source = searchExpressionContext.getSource();
         CollectClientIdCallback callback = new CollectClientIdCallback();
-        Set<SearchExpressionHint> hints = searchExpressionContext.getExpressionHints();
+        Set<SearchExpressionHint> hints = addHint(searchExpressionContext.getExpressionHints(),
+                SearchExpressionHint.RESOLVE_SINGLE_COMPONENT);
         SearchExpressionHandler handler = facesContext.getApplication().getSearchExpressionHandler();
         if (handler.isPassthroughExpression(searchExpressionContext, expression))
         {
@@ -185,7 +201,8 @@ public class SearchExpressionHandlerImpl
     {
         FacesContext facesContext = searchExpressionContext.getFacesContext();
         SingleInvocationCallback checkCallback = new SingleInvocationCallback(callback);
-        Set<SearchExpressionHint> hints = searchExpressionContext.getExpressionHints();
+        Set<SearchExpressionHint> hints = addHint(searchExpressionContext.getExpressionHints(),
+                SearchExpressionHint.RESOLVE_SINGLE_COMPONENT);
         facesContext.getApplication().getSearchExpressionHandler().invokeOnComponent(
                 searchExpressionContext, searchExpressionContext.getSource(), expression,
checkCallback);
 
@@ -424,7 +441,7 @@ public class SearchExpressionHandlerImpl
                     {
                         target = parent.findComponent(expression);
                         if (target == null && !searchExpressionContext.getExpressionHints().contains(
-                                SearchExpressionHint.RESOLVE_COMPONENT_LIST))
+                                SearchExpressionHint.SKIP_VIRTUAL_COMPONENTS))
                         {
                             contextClientId = parent.getClientId(facesContext);
                             // If no component is found,

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/AttachedObjectTargetImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/AttachedObjectTargetImpl.java?rev=1774639&r1=1774638&r2=1774639&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/AttachedObjectTargetImpl.java
(original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/AttachedObjectTargetImpl.java
Fri Dec 16 16:50:05 2016
@@ -76,7 +76,7 @@ public class AttachedObjectTargetImpl im
             for (String target : targetsArray)
             {
                 Set<SearchExpressionHint> expressionHints = new HashSet<SearchExpressionHint>(2);
-                expressionHints.add(SearchExpressionHint.RESOLVE_COMPONENT_LIST);
+                expressionHints.add(SearchExpressionHint.SKIP_VIRTUAL_COMPONENTS);
                 SearchExpressionContext searchContext = SearchExpressionContext.createSearchExpressionContext(
                                     facesContext, facetBase, expressionHints, null);
                 facesContext.getApplication().getSearchExpressionHandler()

Modified: myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/component/search/SearchExpressionImplTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/component/search/SearchExpressionImplTest.java?rev=1774639&r1=1774638&r2=1774639&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/component/search/SearchExpressionImplTest.java
(original)
+++ myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/component/search/SearchExpressionImplTest.java
Fri Dec 16 16:50:05 2016
@@ -19,6 +19,7 @@
 
 package org.apache.myfaces.component.search;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
@@ -151,6 +152,62 @@ public class SearchExpressionImplTest ex
     }
     
     @Test
+    public void testResolveComponent() throws Exception
+    {
+        startViewRequest("/search1.xhtml");
+        processLifecycleExecute();
+        executeBeforeRender();
+        executeBuildViewCycle();
+
+        SearchExpressionContext searchContext = 
+                SearchExpressionContext.createSearchExpressionContext(facesContext, facesContext.getViewRoot());
+
+        CollectComponentsCallback callback = new CollectComponentsCallback();
+        facesContext.getApplication().getSearchExpressionHandler().resolveComponent(
+                searchContext, "@id(name)", callback);
+        
+        Assert.assertEquals(1, callback.getComponents().size());
+        
+        processRemainingPhases();
+    }
+    
+    @Test
+    public void testResolveComponents() throws Exception
+    {
+        startViewRequest("/search1.xhtml");
+        processLifecycleExecute();
+        executeBeforeRender();
+        executeBuildViewCycle();
+
+        SearchExpressionContext searchContext = 
+                SearchExpressionContext.createSearchExpressionContext(facesContext, facesContext.getViewRoot());
+
+        CollectComponentsCallback callback = new CollectComponentsCallback();
+        facesContext.getApplication().getSearchExpressionHandler().resolveComponents(
+                searchContext, "@id(name)", callback);
+        
+        Assert.assertEquals(2, callback.getComponents().size());
+        
+        processRemainingPhases();
+    }
+    
+    class CollectComponentsCallback implements ContextCallback
+    {
+        private ArrayList<UIComponent> components = new ArrayList<>();
+        
+        @Override
+        public void invokeContextCallback(FacesContext context, UIComponent target)
+        {
+            components.add(target);
+        }
+        
+        public ArrayList<UIComponent> getComponents()
+        {
+            return components;
+        }
+    }
+    
+    @Test
     public void testResolveClientId1() throws Exception
     {
         startViewRequest("/search1.xhtml");

Modified: myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/component/search/search1.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/component/search/search1.xhtml?rev=1774639&r1=1774638&r2=1774639&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/component/search/search1.xhtml
(original)
+++ myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/component/search/search1.xhtml
Fri Dec 16 16:50:05 2016
@@ -27,15 +27,15 @@
 <h:body>
     <h:panelGrid columns="1">
         <h:form id="mainForm">
-            
+
             <h:outputLabel id="labelName" for="name" value="Name: "/>
             <div>
             <h:inputText id="name" value="NAME"/>
             </div>
             <h:message id="msgName" for="name"/>
-            
+
             <h:outputText id="showName" value="showName"/>
-            
+
             <h:dataTable id="table" value="#{searchBean.model}" var="row">
                 <h:column>
                     <h:outputText id="baseText" value="#{row.text}"/>
@@ -49,7 +49,11 @@
                     </h:dataTable>
                 </h:column>
             </h:dataTable>
-            
+
+        </h:form>
+
+        <h:form id="otherForm">
+            <h:inputText id="name" value="NAME"/>
         </h:form>
     </h:panelGrid>
 </h:body>



Mime
View raw message