Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2013 Thomas Asel.
  *
  * Licensed 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 de.thomasasel.jsf.inspector;
import  javax.faces.application.Resource;
import  javax.faces.component.UIComponent;
import  javax.faces.component.visit.VisitCallback;
import  javax.faces.component.visit.VisitContext;
import  javax.faces.component.visit.VisitResult;

Traverses the component tree and creates a record of the found components. The results are stored in the TreeInspectionVisitContext passed to visit(javax.faces.component.visit.VisitContext, javax.faces.component.UIComponent)

Author(s):
Thomas Asel
See also:
javax.faces.component.visit.VisitCallback
class TreeInspectionVisitor implements VisitCallback {
        
    private Map<ComponentTypeList<String>> components = new HashMap<ComponentTypeList<String>>();
    private Map<ComponentTypeList<String>> composites = new HashMap<ComponentTypeList<String>>();
    
    

Parameters:
ctx Instance of TreeInspectionVisitContext
target
Returns:
    @Override
    public VisitResult visit(VisitContext context, UIComponent target) {
        ComponentType componentType = build(target); 
        
        if (componentType.isComposite()) {
            if (.get(componentType) == null) {
                .put(componentTypenew ArrayList<String>());
            }
            .get(componentType).add(target.getClientId());
        } else {
            if (.get(componentType) == null) {
                .put(componentTypenew ArrayList<String>());
            }
            .get(componentType).add(target.getClientId());
        }
        
        return VisitResult.ACCEPT;
        
    }

     
Builder method, used to create the appropriate sub-type of ComponentType depending on the nature of target.

Parameters:
target
Returns:
    static ComponentType build(UIComponent target) {
        String identifier;
        
        if (UIComponent.isCompositeComponent(target)) {
            Resource resource = (Resource) target.getAttributes().get(Resource.COMPONENT_RESOURCE_KEY);
            identifier = resource.getResourceName();
            return new CompositeType(identifier);
        } else {
            identifier = target.getClass().getName();
            return new NonCompositeType(identifier);
        }
    }
    public Map<ComponentTypeList<String>> getComponents() {
        return ;
    }
    public Map<ComponentTypeList<String>> getComposites() {
        return ;
    }
    
New to GrepCode? Check out our FAQ X