Package org.apache.myfaces.view.facelets

Examples of org.apache.myfaces.view.facelets.FaceletCompositionContext


    }
   
    private void checkFacetRequired(FaceletContext ctx, UIComponent parent, String name)
    {
        AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
        FaceletCompositionContext fcc = actx.getFaceletCompositionContext();
        UIComponent innerCompositeComponent = fcc.getCompositeComponentFromStack();
       
        CompositeComponentBeanInfo beanInfo =
            (CompositeComponentBeanInfo) innerCompositeComponent.getAttributes()
            .get(UIComponent.BEANINFO_KEY);
       
View Full Code Here


    }

    public void apply(FaceletContext ctx, UIComponent parent)
            throws IOException
    {
        FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx);
        AbstractFaceletContext actx = (AbstractFaceletContext)ctx;
        UIComponent compositeBaseParent = actx.isBuildingCompositeComponentMetadata() ? parent : parent.getParent();
       
        // Store the current Location on the parent (the location is needed
        // to resolve the related composite component via #{cc} properly).
        if (_interfaceHandler != null)
        {
            if (!compositeBaseParent.getAttributes().containsKey(CompositeComponentELUtils.LOCATION_KEY))
            {
                compositeBaseParent.getAttributes()
                    .put(CompositeComponentELUtils.LOCATION_KEY, this._interfaceHandler.getLocation());
            }
        }
        else if (_implementationHandler != null)
        {
            if (!compositeBaseParent.getAttributes().containsKey(CompositeComponentELUtils.LOCATION_KEY))
            {
                compositeBaseParent.getAttributes()
                    .put(CompositeComponentELUtils.LOCATION_KEY, this._implementationHandler.getLocation());
            }
        }
       
        // Only apply if we are building composite component metadata,
        // in other words we are calling ViewDeclarationLanguage.getComponentMetadata
        if ( actx.isBuildingCompositeComponentMetadata() )
        {
            CompositeComponentBeanInfo tempBeanInfo =
                (CompositeComponentBeanInfo) compositeBaseParent.getAttributes()
                .get(UIComponent.BEANINFO_KEY);
           
            if (tempBeanInfo == null)
            {
                if (_cacheable)
                {
                    if (_cachedBeanInfo == null)
                    {
                        tempBeanInfo  = _createCompositeComponentMetadata(ctx, compositeBaseParent);
                        compositeBaseParent.getAttributes().put(
                                UIComponent.BEANINFO_KEY, tempBeanInfo);
                       
                        try
                        {
                            mctx.pushCompositeComponentToStack(compositeBaseParent);
                           
                            // Store the ccLevel key here
                            if (!compositeBaseParent.getAttributes().containsKey(CompositeComponentELUtils.LEVEL_KEY))
                            {
                                compositeBaseParent.getAttributes()
                                    .put(CompositeComponentELUtils.LEVEL_KEY, mctx.getCompositeComponentLevel());
                            }

                            _nextHandler.apply(ctx, parent);
                           
                            Collection<String> declaredDefaultValues = null;
                           
                            for (PropertyDescriptor pd : tempBeanInfo.getPropertyDescriptors())
                            {
                                if (pd.getValue("default") != null)
                                {
                                    if (declaredDefaultValues  == null)
                                    {
                                        declaredDefaultValues = new ArrayList<String>();
                                    }
                                    declaredDefaultValues.add(pd.getName());
                                }
                            }
                            if (declaredDefaultValues == null)
                            {
                                declaredDefaultValues = Collections.emptyList();
                            }
                            tempBeanInfo.getBeanDescriptor().
                                    setValue(UIComponent.ATTRS_WITH_DECLARED_DEFAULT_VALUES, declaredDefaultValues);
                        }
                        finally
                        {
                            mctx.popCompositeComponentToStack();
                           
                            _cachedBeanInfo = tempBeanInfo;
                        }
                    }
                    else
                    {
                        // Put the cached instance, but in that case it is not necessary to call
                        // nextHandler
                        compositeBaseParent.getAttributes().put(
                                UIComponent.BEANINFO_KEY, _cachedBeanInfo);
                    }
                }
                else
                {
                    tempBeanInfo = _createCompositeComponentMetadata(ctx, compositeBaseParent);
                    compositeBaseParent.getAttributes().put(
                            UIComponent.BEANINFO_KEY, tempBeanInfo);
                   
                    try
                    {
                        mctx.pushCompositeComponentToStack(compositeBaseParent);
                       
                        // Store the ccLevel key here
                        if (!compositeBaseParent.getAttributes().containsKey(CompositeComponentELUtils.LEVEL_KEY))
                        {
                            compositeBaseParent.getAttributes()
                                .put(CompositeComponentELUtils.LEVEL_KEY, mctx.getCompositeComponentLevel());
                        }
                   
                        _nextHandler.apply(ctx, parent);
                       
                        Collection<String> declaredDefaultValues = null;
                       
                        for (PropertyDescriptor pd : tempBeanInfo.getPropertyDescriptors())
                        {
                            if (pd.getValue("default") != null)
                            {
                                if (declaredDefaultValues  == null)
                                {
                                    declaredDefaultValues = new ArrayList<String>();
                                }
                                declaredDefaultValues.add(pd.getName());
                            }
                        }
                        if (declaredDefaultValues == null)
                        {
                            declaredDefaultValues = Collections.emptyList();
                        }
                        tempBeanInfo.getBeanDescriptor().
                                setValue(UIComponent.ATTRS_WITH_DECLARED_DEFAULT_VALUES, declaredDefaultValues);
                    }
                    finally
                    {
                        mctx.popCompositeComponentToStack();
                    }
                }
            }
        }
        else
        {
            try
            {
                mctx.pushCompositeComponentToStack(compositeBaseParent);

                // Store the ccLevel key here
                if (!compositeBaseParent.getAttributes().containsKey(CompositeComponentELUtils.LEVEL_KEY))
                {
                    compositeBaseParent.getAttributes()
                        .put(CompositeComponentELUtils.LEVEL_KEY, mctx.getCompositeComponentLevel());
                }
           
                _nextHandler.apply(ctx, parent);
            }
            finally
            {
                mctx.popCompositeComponentToStack();
            }
        }
    }
View Full Code Here

        }
        if (! (parent instanceof UIViewRoot) )
        {
            throw new TagException(this.tag, "Parent UIComponent "+parent.getId()+" should be instance of UIViewRoot");
        }
        FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx);
        if (mctx.isBuildingViewMetadata())
        {
            UIComponent metadataFacet = parent.getFacet(UIViewRoot.METADATA_FACET_NAME);
            if (metadataFacet == null)
            {
                metadataFacet = ctx.getFacesContext().getApplication().createComponent(
                        ctx.getFacesContext(), UIPanel.COMPONENT_TYPE, null);
                metadataFacet.setId(UIViewRoot.METADATA_FACET_NAME);
                metadataFacet.getAttributes().put(ComponentSupport.FACET_CREATED_UIPANEL_MARKER, true);
                metadataFacet.getAttributes().put(ComponentSupport.COMPONENT_ADDED_BY_HANDLER_MARKER, Boolean.TRUE);
                parent.getFacets().put(UIViewRoot.METADATA_FACET_NAME, metadataFacet);
            }
        }

        // We have to do nextHandler.apply() in any case, because even if we're not building ViewMetadata
        // we still need to do it so that the mark/delete components can be applied correctly.
        // (The only tag that needs to do something special is f:event, because in this case
        // ComponentHandler.isNew(parent) does not work for UIViewRoot.)
        parent.getAttributes().put(FacetHandler.KEY, UIViewRoot.METADATA_FACET_NAME);
        mctx.startMetadataSection();
        try
        {
            this.nextHandler.apply(ctx, parent);
        }
        finally
        {
            mctx.endMetadataSection();
            parent.getAttributes().remove(FacetHandler.KEY);
        }
    }
View Full Code Here

                //Apply this handler directly over the parent
                applyAttachedObject(ctx.getFacesContext(), parent);
            }
            else if (UIComponent.isCompositeComponent(parent))
            {
                FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx);
                // It is supposed that for composite components, this tag should
                // add itself as a target, but note that on whole api does not exists
                // some tag that expose client behaviors as targets for composite
                // components. In RI, there exists a tag called composite:clientBehavior,
                // but does not appear on spec or javadoc, maybe because this could be
                // understand as an implementation detail, after all there exists a key
                // called AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY that could be
                // used to create a tag outside jsf implementation to attach targets.
                mctx.addAttachedObjectHandler(
                        parent, this);
            }
            else
            {
                throw new TagException(this.tag,
View Full Code Here

        // is feasible but also will be affected by <c:if> blocks inside a facet.
        // The only solution that will generate real unique ids is use the parent id and the
        // facet name and derive an unique id that cannot be generated by SectionUniqueIdCounter,
        // doing the same trick as with metadata: use a double __ and add a prefix (f).
        // Note this id will never be printed into the response, because this is just a container.
        FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx);
        UniqueIdVendor uniqueIdVendor = mctx.getUniqueIdVendorFromStack();
        if (uniqueIdVendor == null)
        {
            uniqueIdVendor = ComponentSupport.getViewRoot(ctx, parent);
        }
        if (uniqueIdVendor != null)
        {
            // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
            // and call createUniqueId(). See ComponentTagHandlerDelegate
            int index = facetName.indexOf('.');
            String cleanFacetName = facetName;
            if (index >= 0)
            {
                cleanFacetName = facetName.replace('.', '_');
            }
            panel.setId(uniqueIdVendor.createUniqueId(facesContext,
                    mctx.getSharedStringBuilder()
                      .append(parent.getId())
                      .append("__f_")
                      .append(cleanFacetName).toString()));
        }
        panel.getAttributes().put(FACET_CREATED_UIPANEL_MARKER, Boolean.TRUE);
View Full Code Here

            FacesContext facesContext = ctx.getFacesContext();
           
            ViewDeclarationLanguage vdl = facesContext.getApplication().getViewHandler().
                getViewDeclarationLanguage(facesContext, facesContext.getViewRoot().getViewId());

            FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx);
            List<AttachedObjectHandler> handlers = mctx.getAttachedObjectHandlers(c);
           
            if (handlers != null)
            {
                vdl.retargetAttachedObjects(facesContext, c, handlers);
               
                // remove the list of handlers, as it is no longer necessary
                mctx.removeAttachedObjectHandlers(c);
            }
           
            vdl.retargetMethodExpressions(facesContext, c);
           
            if ( FaceletCompositionContext.getCurrentInstance(ctx).isMarkInitialState())
View Full Code Here

    }
   
    protected void applyCompositeComponentFacelet(FaceletContext faceletContext, UIComponent compositeComponentBase)
        throws IOException
    {
        FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(faceletContext);
        AbstractFaceletContext actx = (AbstractFaceletContext) faceletContext;
        UIPanel compositeFacetPanel
                = (UIPanel) compositeComponentBase.getFacets().get(UIComponent.COMPOSITE_FACET_NAME);
        if (compositeFacetPanel == null)
        {
            compositeFacetPanel = (UIPanel)
                faceletContext.getFacesContext().getApplication().createComponent(
                    faceletContext.getFacesContext(), UIPanel.COMPONENT_TYPE, null);
            compositeFacetPanel.getAttributes().put(ComponentSupport.COMPONENT_ADDED_BY_HANDLER_MARKER,
                    Boolean.TRUE);
            compositeComponentBase.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, compositeFacetPanel);
           
            // Set an id to the created facet component, to prevent id generation and make
            // partial state saving work without problem.
            UniqueIdVendor uniqueIdVendor = mctx.getUniqueIdVendorFromStack();
            if (uniqueIdVendor == null)
            {
                uniqueIdVendor = ComponentSupport.getViewRoot(faceletContext, compositeComponentBase);
            }
            if (uniqueIdVendor != null)
            {
                // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
                // and call createUniqueId()
                String uid = uniqueIdVendor.createUniqueId(faceletContext.getFacesContext(),
                        mctx.getSharedStringBuilder()
                        .append(compositeComponentBase.getId())
                        .append("__f_")
                        .append("cc_facet").toString());
                compositeFacetPanel.setId(uid);
            }           
        }
       
        // Before call applyCompositeComponent we need to add ajax behaviors
        // to the current compositeComponentBase. Note that super.applyNextHandler()
        // has already been called, but this point is before vdl.retargetAttachedObjects,
        // so we can't but this on ComponentTagHandlerDelegate, if we want this to be
        // applied correctly.
        Iterator<AjaxHandler> it = ((AbstractFaceletContext) faceletContext).getAjaxHandlers();
        if (it != null)
        {
            while(it.hasNext())
            {
                mctx.addAttachedObjectHandler(
                        compositeComponentBase, it.next());
            }
        }   
       
        VariableMapper orig = faceletContext.getVariableMapper();
View Full Code Here

            {
                AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
                // Pop the current composite component on stack, so #{cc} references
                // can be resolved correctly, because they are relative to the page
                // that define it.
                FaceletCompositionContext fcc = actx.getFaceletCompositionContext();
                UIComponent innerCompositeComponent = fcc.getCompositeComponentFromStack();
                fcc.popCompositeComponentToStack();
                // Pop the template context, so ui:xx tags and nested composite component
                // cases could work correctly
                TemplateContext itc = actx.popTemplateContext();
                try
                {
                    handler.apply(ctx, parent);
                }
                finally
                {
                    actx.pushTemplateContext(itc);
                    fcc.pushCompositeComponentToStack(innerCompositeComponent);
                }
                return true;
               
            }
            else
            {
                checkFacetRequired(ctx, parent, name);
                return true;
            }
        }
        else
        {
            AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
            // Pop the current composite component on stack, so #{cc} references
            // can be resolved correctly, because they are relative to the page
            // that define it.
            FaceletCompositionContext fcc = actx.getFaceletCompositionContext();
            UIComponent innerCompositeComponent = fcc.getCompositeComponentFromStack();
            fcc.popCompositeComponentToStack();
            // Pop the template context, so ui:xx tags and nested composite component
            // cases could work correctly
            TemplateContext itc = actx.popTemplateContext();
            try
            {
                for (FaceletHandler handler : _componentHandlers)
                {
                    handler.apply(ctx, parent);
                }
            }
            finally
            {
                actx.pushTemplateContext(itc);
                fcc.pushCompositeComponentToStack(innerCompositeComponent);
            }
            return true;
        }
    }
View Full Code Here

    }
   
    private void checkFacetRequired(FaceletContext ctx, UIComponent parent, String name)
    {
        AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
        FaceletCompositionContext fcc = actx.getFaceletCompositionContext();
        UIComponent innerCompositeComponent = fcc.getCompositeComponentFromStack();
       
        CompositeComponentBeanInfo beanInfo =
            (CompositeComponentBeanInfo) innerCompositeComponent.getAttributes()
            .get(UIComponent.BEANINFO_KEY);
       
View Full Code Here

    }

    public void apply(FaceletContext ctx, UIComponent parent)
            throws IOException
    {
        FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx);
        AbstractFaceletContext actx = (AbstractFaceletContext)ctx;
        UIComponent compositeBaseParent = actx.isBuildingCompositeComponentMetadata() ? parent : parent.getParent();
       
        // Store the current Location on the parent (the location is needed
        // to resolve the related composite component via #{cc} properly).
        if (_interfaceHandler != null)
        {
            if (!compositeBaseParent.getAttributes().containsKey(CompositeComponentELUtils.LOCATION_KEY))
            {
                compositeBaseParent.getAttributes()
                    .put(CompositeComponentELUtils.LOCATION_KEY, this._interfaceHandler.getLocation());
            }
        }
        else if (_implementationHandler != null)
        {
            if (!compositeBaseParent.getAttributes().containsKey(CompositeComponentELUtils.LOCATION_KEY))
            {
                compositeBaseParent.getAttributes()
                    .put(CompositeComponentELUtils.LOCATION_KEY, this._implementationHandler.getLocation());
            }
        }
       
        // Only apply if we are building composite component metadata,
        // in other words we are calling ViewDeclarationLanguage.getComponentMetadata
        if ( actx.isBuildingCompositeComponentMetadata() )
        {
            CompositeComponentBeanInfo tempBeanInfo =
                (CompositeComponentBeanInfo) compositeBaseParent.getAttributes()
                .get(UIComponent.BEANINFO_KEY);
           
            if (tempBeanInfo == null)
            {
                if (_cacheable)
                {
                    if (_cachedBeanInfo == null)
                    {
                        _cachedBeanInfo = _createCompositeComponentMetadata(ctx, compositeBaseParent);
                        compositeBaseParent.getAttributes().put(
                                UIComponent.BEANINFO_KEY, _cachedBeanInfo);
                       
                        try
                        {
                            mctx.pushCompositeComponentToStack(compositeBaseParent);
                           
                            // Store the ccLevel key here
                            if (!compositeBaseParent.getAttributes().containsKey(CompositeComponentELUtils.LEVEL_KEY))
                            {
                                compositeBaseParent.getAttributes()
                                    .put(CompositeComponentELUtils.LEVEL_KEY, mctx.getCompositeComponentLevel());
                            }

                            _nextHandler.apply(ctx, parent);
                           
                            Collection<String> declaredDefaultValues = null;
                           
                            for (PropertyDescriptor pd : _cachedBeanInfo.getPropertyDescriptors())
                            {
                                if (pd.getValue("default") != null)
                                {
                                    if (declaredDefaultValues  == null)
                                    {
                                        declaredDefaultValues = new ArrayList<String>();
                                    }
                                    declaredDefaultValues.add(pd.getName());
                                }
                            }
                            if (declaredDefaultValues == null)
                            {
                                declaredDefaultValues = Collections.emptyList();
                            }
                            _cachedBeanInfo.getBeanDescriptor().
                                    setValue(UIComponent.ATTRS_WITH_DECLARED_DEFAULT_VALUES, declaredDefaultValues);
                        }
                        finally
                        {
                            mctx.popCompositeComponentToStack();
                        }
                    }
                    else
                    {
                        // Put the cached instance, but in that case it is not necessary to call
                        // nextHandler
                        compositeBaseParent.getAttributes().put(
                                UIComponent.BEANINFO_KEY, _cachedBeanInfo);
                    }
                }
                else
                {
                    tempBeanInfo = _createCompositeComponentMetadata(ctx, compositeBaseParent);
                    compositeBaseParent.getAttributes().put(
                            UIComponent.BEANINFO_KEY, tempBeanInfo);
                   
                    try
                    {
                        mctx.pushCompositeComponentToStack(compositeBaseParent);
                       
                        // Store the ccLevel key here
                        if (!compositeBaseParent.getAttributes().containsKey(CompositeComponentELUtils.LEVEL_KEY))
                        {
                            compositeBaseParent.getAttributes()
                                .put(CompositeComponentELUtils.LEVEL_KEY, mctx.getCompositeComponentLevel());
                        }
                   
                        _nextHandler.apply(ctx, parent);
                       
                        Collection<String> declaredDefaultValues = null;
                       
                        for (PropertyDescriptor pd : tempBeanInfo.getPropertyDescriptors())
                        {
                            if (pd.getValue("default") != null)
                            {
                                if (declaredDefaultValues  == null)
                                {
                                    declaredDefaultValues = new ArrayList<String>();
                                }
                                declaredDefaultValues.add(pd.getName());
                            }
                        }
                        if (declaredDefaultValues == null)
                        {
                            declaredDefaultValues = Collections.emptyList();
                        }
                        tempBeanInfo.getBeanDescriptor().
                                setValue(UIComponent.ATTRS_WITH_DECLARED_DEFAULT_VALUES, declaredDefaultValues);
                    }
                    finally
                    {
                        mctx.popCompositeComponentToStack();
                    }
                }
            }
        }
        else
        {
            try
            {
                mctx.pushCompositeComponentToStack(compositeBaseParent);

                // Store the ccLevel key here
                if (!compositeBaseParent.getAttributes().containsKey(CompositeComponentELUtils.LEVEL_KEY))
                {
                    compositeBaseParent.getAttributes()
                        .put(CompositeComponentELUtils.LEVEL_KEY, mctx.getCompositeComponentLevel());
                }
           
                _nextHandler.apply(ctx, parent);
            }
            finally
            {
                mctx.popCompositeComponentToStack();
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.myfaces.view.facelets.FaceletCompositionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.