Search in sources :

Example 1 with ComponentContainerHandler

use of org.apache.myfaces.view.facelets.tag.ComponentContainerHandler in project myfaces by apache.

the class CompositeComponentResourceTagHandler method applyNextHandlerIfNotApplied.

@SuppressWarnings("unchecked")
protected void applyNextHandlerIfNotApplied(FaceletContext ctx, UIComponent c) throws IOException {
    // Apply all facelets not applied yet.
    CompositeComponentBeanInfo beanInfo = (CompositeComponentBeanInfo) c.getAttributes().get(UIComponent.BEANINFO_KEY);
    BeanDescriptor beanDescriptor = beanInfo.getBeanDescriptor();
    boolean insertChildrenUsed = (beanDescriptor.getValue(InsertChildrenHandler.INSERT_CHILDREN_USED) != null);
    List<String> insertFacetList = (List<String>) beanDescriptor.getValue(InsertFacetHandler.INSERT_FACET_USED);
    if (nextHandler instanceof jakarta.faces.view.facelets.CompositeFaceletHandler) {
        for (FaceletHandler handler : ((jakarta.faces.view.facelets.CompositeFaceletHandler) nextHandler).getHandlers()) {
            if (handler instanceof jakarta.faces.view.facelets.FacetHandler) {
                if (insertFacetList == null || !insertFacetList.contains(((jakarta.faces.view.facelets.FacetHandler) handler).getFacetName(ctx))) {
                    handler.apply(ctx, c);
                }
            } else if (handler instanceof InsertFacetHandler) {
                if (insertFacetList == null || !insertFacetList.contains(((InsertFacetHandler) handler).getFacetName(ctx))) {
                    handler.apply(ctx, c);
                }
            } else if (insertChildrenUsed) {
                if (!(handler instanceof jakarta.faces.view.facelets.ComponentHandler || handler instanceof ComponentContainerHandler || handler instanceof TextHandler)) {
                    handler.apply(ctx, c);
                }
            } else {
                handler.apply(ctx, c);
            }
        }
    } else {
        if (nextHandler instanceof jakarta.faces.view.facelets.FacetHandler) {
            if (insertFacetList == null || !insertFacetList.contains(((jakarta.faces.view.facelets.FacetHandler) nextHandler).getFacetName(ctx))) {
                nextHandler.apply(ctx, c);
            }
        } else if (nextHandler instanceof InsertFacetHandler) {
            if (insertFacetList == null || !insertFacetList.contains(((InsertFacetHandler) nextHandler).getFacetName(ctx))) {
                nextHandler.apply(ctx, c);
            }
        } else if (insertChildrenUsed) {
            if (!(nextHandler instanceof jakarta.faces.view.facelets.ComponentHandler || nextHandler instanceof ComponentContainerHandler || nextHandler instanceof TextHandler)) {
                nextHandler.apply(ctx, c);
            }
        } else {
            nextHandler.apply(ctx, c);
        }
    }
    // Check for required facets
    Map<String, PropertyDescriptor> facetPropertyDescriptorMap = (Map<String, PropertyDescriptor>) beanDescriptor.getValue(UIComponent.FACETS_KEY);
    if (facetPropertyDescriptorMap != null) {
        List<String> facetsRequiredNotFound = null;
        for (Map.Entry<String, PropertyDescriptor> entry : facetPropertyDescriptorMap.entrySet()) {
            ValueExpression requiredExpr = (ValueExpression) entry.getValue().getValue("required");
            if (requiredExpr != null) {
                Boolean required = (Boolean) requiredExpr.getValue(ctx.getFacesContext().getELContext());
                if (Boolean.TRUE.equals(required)) {
                    initFacetHandlersMap(ctx);
                    if (!_facetHandlersMap.containsKey(entry.getKey())) {
                        if (facetsRequiredNotFound == null) {
                            facetsRequiredNotFound = new ArrayList(facetPropertyDescriptorMap.size());
                        }
                        facetsRequiredNotFound.add(entry.getKey());
                    }
                }
            }
        }
        if (facetsRequiredNotFound != null && !facetsRequiredNotFound.isEmpty()) {
            throw new TagException(getTag(), "The following facets are required by the component: " + facetsRequiredNotFound);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) FaceletHandler(jakarta.faces.view.facelets.FaceletHandler) ComponentContainerHandler(org.apache.myfaces.view.facelets.tag.ComponentContainerHandler) TextHandler(jakarta.faces.view.facelets.TextHandler) List(java.util.List) ArrayList(java.util.ArrayList) PropertyDescriptor(java.beans.PropertyDescriptor) ComponentHandler(jakarta.faces.view.facelets.ComponentHandler) BeanDescriptor(java.beans.BeanDescriptor) TagException(jakarta.faces.view.facelets.TagException) ValueExpression(jakarta.el.ValueExpression) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ValueExpression (jakarta.el.ValueExpression)1 ComponentHandler (jakarta.faces.view.facelets.ComponentHandler)1 FaceletHandler (jakarta.faces.view.facelets.FaceletHandler)1 TagException (jakarta.faces.view.facelets.TagException)1 TextHandler (jakarta.faces.view.facelets.TextHandler)1 BeanDescriptor (java.beans.BeanDescriptor)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ComponentContainerHandler (org.apache.myfaces.view.facelets.tag.ComponentContainerHandler)1