Package org.apache.myfaces.view.facelets

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


                   
                    if (FaceletViewDeclarationLanguageBase.isDynamicComponentNeedsRefresh(ctx.getFacesContext()))
                    {
                        FaceletViewDeclarationLanguageBase.resetDynamicComponentNeedsRefreshFlag(
                                ctx.getFacesContext());
                        FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx);
                        if (mctx.isUsingPSSOnThisView())
                        {
                            FaceletViewDeclarationLanguage.cleanTransientBuildOnRestore(faces);
                        }
                        else
                        {
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

     *      javax.faces.component.UIComponent)
     */
    public void apply(FacesContext facesContext, UIComponent parent) throws IOException, FacesException,
            FaceletException, ELException
    {
        FaceletCompositionContext myFaceletContext = null;
        boolean faceletCompositionContextInitialized = false;
        boolean recordUniqueIds = false;
        myFaceletContext = FaceletCompositionContext.getCurrentInstance(facesContext);
        if (myFaceletContext == null)
        {
            myFaceletContext = new FaceletCompositionContextImpl(_factory, facesContext);
            myFaceletContext.init(facesContext);
            faceletCompositionContextInitialized = true;
            if (_encodingHandler && !myFaceletContext.isBuildingViewMetadata()
                    && MyfacesConfig.getCurrentInstance(
                    facesContext.getExternalContext()).isViewUniqueIdsCacheEnabled() &&
                    _refreshPeriod <= 0)
            {
                List<String> uniqueIdList = ((EncodingHandler)_root).getUniqueIdList();
                if (uniqueIdList == null)
                {
                    myFaceletContext.initUniqueIdRecording();
                    recordUniqueIds = true;
                }
                else
                {
                    myFaceletContext.setUniqueIdsIterator(uniqueIdList.iterator());
                }
            }
            if (parent instanceof UIViewRoot)
            {
                ComponentSupport.setCachedFacesContext((UIViewRoot)parent, facesContext);
            }
        }
        DefaultFaceletContext ctx = new DefaultFaceletContext(facesContext, this, myFaceletContext);
       
        //Set FACELET_CONTEXT_KEY on FacesContext attribute map, to
        //reflect the current facelet context instance
        FaceletContext oldCtx = (FaceletContext)
                facesContext.getAttributes().put(FaceletContext.FACELET_CONTEXT_KEY, ctx);
       
        ctx.pushPageContext(new PageContextImpl());
       
        try
        {
            // push the parent as a UniqueIdVendor to the stack here,
            // if there is no UniqueIdVendor on the stack yet
            boolean pushedUniqueIdVendor = false;
            if (parent instanceof UniqueIdVendor
                && ctx.getFaceletCompositionContext().getUniqueIdVendorFromStack() == null)
            {
                ctx.getFaceletCompositionContext().pushUniqueIdVendorToStack((UniqueIdVendor) parent);
                pushedUniqueIdVendor = true;
            }
           
            this.refresh(parent);
            myFaceletContext.markForDeletion(parent);
            _root.apply(ctx, parent);
            if (faceletCompositionContextInitialized &&
                parent instanceof UIViewRoot)
            {
                UIComponent metadataFacet = parent.getFacet(UIViewRoot.METADATA_FACET_NAME);
                if (metadataFacet != null)
                {
                    // Ensure metadata facet is removed from deletion, so if by some reason
                    // is not refreshed, its content will not be removed from the component tree.
                    // This behavior is preferred, even if the spec suggest to include it using
                    // a trick with the template client.
                    myFaceletContext.removeComponentForDeletion(metadataFacet);
                }
                if (myFaceletContext.isRefreshingTransientBuild())
                {
                    myFaceletContext.finalizeRelocatableResourcesForDeletion((UIViewRoot) parent);
                }
            }
            myFaceletContext.finalizeForDeletion(parent);
            this.markApplied(parent);
           
            // remove the UniqueIdVendor from the stack again
            if (pushedUniqueIdVendor)
            {
                ctx.getFaceletCompositionContext().popUniqueIdVendorToStack();
            }
        }
        finally
        {
            ctx.popPageContext();
           
            if (faceletCompositionContextInitialized)
            {
                if (parent instanceof UIViewRoot)
                {
                    ComponentSupport.setCachedFacesContext((UIViewRoot)parent, null);
                }
                myFaceletContext.release(facesContext);
                List<String> uniqueIdList = ((EncodingHandler)_root).getUniqueIdList();
                if (recordUniqueIds &&  uniqueIdList == null)
                {
                    uniqueIdList = Collections.unmodifiableList(
                            myFaceletContext.getUniqueIdList());
                    ((EncodingHandler)_root).setUniqueIdList(uniqueIdList);
                }
            }
           
            if (oldCtx != null)
View Full Code Here

   
    public void applyDynamicComponentHandler(FacesContext facesContext,
            UIComponent parent, String baseKey)
         throws IOException, FacesException, FaceletException, ELException
    {
        FaceletCompositionContext fcctx = null;
        boolean faceletCompositionContextInitialized = false;
        fcctx = FaceletCompositionContext.getCurrentInstance(facesContext);
        boolean pushDynCompSection = false;
        if (fcctx == null)
        {
            fcctx = new FaceletCompositionContextImpl(_factory, facesContext,
                baseKey);
            fcctx.init(facesContext);
            faceletCompositionContextInitialized = true;
        }
        else
        {
            pushDynCompSection = true;
            fcctx.pushDynamicComponentSection(baseKey);
        }
        // Disable dynamic component top level if the parent is a
        // dynamic wrapper, to allow the content to be reorganized properly under
        // a refresh.
        if (parent.getAttributes().containsKey("oam.vf.DYN_WRAPPER"))
        {
            fcctx.setDynamicComponentTopLevel(false);
        }
       
        FaceletContext oldCtx = (FaceletContext) facesContext.getAttributes().get(
            FaceletContext.FACELET_CONTEXT_KEY);
        DefaultFaceletContext ctx = new DefaultFaceletContext(facesContext, this, fcctx);
       
        //Set FACELET_CONTEXT_KEY on FacesContext attribute map, to
        //reflect the current facelet context instance
        facesContext.getAttributes().put(FaceletContext.FACELET_CONTEXT_KEY, ctx);
       
        ctx.pushPageContext(new PageContextImpl());
       
        try
        {
            // push the parent as a UniqueIdVendor to the stack here,
            // if there is no UniqueIdVendor on the stack yet
            boolean pushedUniqueIdVendor = false;
            if (parent instanceof UniqueIdVendor
                && ctx.getFaceletCompositionContext().getUniqueIdVendorFromStack() == null)
            {
                ctx.getFaceletCompositionContext().pushUniqueIdVendorToStack((UniqueIdVendor) parent);
                pushedUniqueIdVendor = true;
            }
           
            //this.refresh(parent);
            //myFaceletContext.markForDeletion(parent);
            _root.apply(ctx, parent);
            //myFaceletContext.finalizeForDeletion(parent);
            //this.markApplied(parent);
           
            // remove the UniqueIdVendor from the stack again
            if (pushedUniqueIdVendor)
            {
                ctx.getFaceletCompositionContext().popUniqueIdVendorToStack();
            }
        }
        finally
        {
            ctx.popPageContext();
            facesContext.getAttributes().put(FaceletContext.FACELET_CONTEXT_KEY, oldCtx);
           
            if (pushDynCompSection)
            {
                fcctx.popDynamicComponentSection();
            }
            if (faceletCompositionContextInitialized)
            {
                fcctx.release(facesContext);
            }
        }
    }   
View Full Code Here

        try
        {
            // push the parent as a UniqueIdVendor to the stack here,
            // if there is no UniqueIdVendor on the stack yet
            boolean pushedUniqueIdVendor = false;
            FaceletCompositionContext mctx = ctx.getFaceletCompositionContext();
            if (parent instanceof UniqueIdVendor
                && ctx.getFaceletCompositionContext().getUniqueIdVendorFromStack() == null)
            {
                mctx.pushUniqueIdVendorToStack((UniqueIdVendor) parent);
                pushedUniqueIdVendor = true;
            }
           
            f.refresh(parent);
            mctx.markForDeletion(parent);
            DefaultFaceletContext ctxWrapper = new DefaultFaceletContext( (DefaultFaceletContext)ctx, f, true);
            //Update FACELET_CONTEXT_KEY on FacesContext attribute map, to
            //reflect the current facelet context instance
            ctx.getFacesContext().getAttributes().put(FaceletContext.FACELET_CONTEXT_KEY, ctxWrapper);
            f._root.apply(ctxWrapper, parent);
            ctx.getFacesContext().getAttributes().put(FaceletContext.FACELET_CONTEXT_KEY, ctx);
            mctx.finalizeForDeletion(parent);
            f.markApplied(parent);
           
            // remove the UniqueIdVendor from the stack again
            if (pushedUniqueIdVendor)
            {
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

            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(UIPanel.COMPONENT_TYPE);
            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(),null);
                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

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.