Package org.apache.myfaces.view.facelets

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


                //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


        // our id
        String id = ctx.generateUniqueId(_delegate.getTagId());

        // Cast to use UniqueIdVendor stuff
        FaceletCompositionContext mctx = (FaceletCompositionContext) FaceletCompositionContext.getCurrentInstance(ctx);
               
        // grab our component
        UIComponent c = null;
        //boolean componentFoundInserted = false;

        //Used to preserve the original parent. Note when the view is being refreshed, the real parent could be
        //another component.
        UIComponent oldParent = parent;
       
        if (mctx.isRefreshingSection())
        {
            if (_relocatableResourceHandler != null)
            {
                c = _relocatableResourceHandler.findChildByTagId(ctx, parent, id);
            }
            else
            {
                c = ComponentSupport.findChildByTagId(parent, id);
            }
        }
        boolean componentFound = false;
        if (c != null)
        {
            componentFound = true;
           
            mctx.incrementUniqueComponentId();
           
            // mark all children for cleaning
            if (log.isLoggable(Level.FINE))
            {
                log.fine(_delegate.getTag() + " Component[" + id + "] Found, marking children for cleanup");
            }
            mctx.markForDeletion(c);
        }
        else
        {
            c = this.createComponent(ctx);
            if (log.isLoggable(Level.FINE))
            {
                log.fine(_delegate.getTag() + " Component[" + id + "] Created: " + c.getClass().getName());
            }
           
            _delegate.setAttributes(ctx, c);

            // mark it owned by a facelet instance
            c.getAttributes().put(ComponentSupport.MARK_CREATED, id);

            if (facesContext.isProjectStage(ProjectStage.Development))
            {
                c.getAttributes().put(UIComponent.VIEW_LOCATION_KEY,
                        _delegate.getTag().getLocation());
            }

            // assign our unique id
            if (this._id != null)
            {
                mctx.incrementUniqueComponentId();
                c.setId(this._id.getValue(ctx));
            }
            else
            {
                String componentId = mctx.generateUniqueComponentId();
                UniqueIdVendor uniqueIdVendor = mctx.getUniqueIdVendorFromStack();
                if (uniqueIdVendor == null)
                {
                    uniqueIdVendor = facesContext.getViewRoot();
                   
                    if (uniqueIdVendor == null)
                    {
                        // facesContext.getViewRoot() returns null here if we are in
                        // phase restore view, so we have to try to get the view root
                        // via the method in ComponentSupport and our parent
                        uniqueIdVendor = ComponentSupport.getViewRoot(ctx, parent);
                    }
                }
                if (uniqueIdVendor != null)
                {
                    // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
                    // and call createUniqueId()
                    String uid = uniqueIdVendor.createUniqueId(facesContext, componentId);
                    c.setId(uid);
                }
            }

            if (this._rendererType != null)
            {
                c.setRendererType(this._rendererType);
            }

            // hook method
            _delegate.onComponentCreated(ctx, c, parent);
        }
        c.pushComponentToEL(facesContext, c);

        if (c instanceof UniqueIdVendor)
        {
            mctx.pushUniqueIdVendorToStack((UniqueIdVendor)c);
        }
        // first allow c to get populated
        _delegate.applyNextHandler(ctx, c);

        boolean oldProcessingEvents = facesContext.isProcessingEvents();
        // finish cleaning up orphaned children
        if (componentFound)
        {
            mctx.finalizeForDeletion(c);

            //if (!componentFoundInserted)
            //{
                if (mctx.isRefreshingSection())
                {
                    facesContext.setProcessingEvents(false);
                    if (_relocatableResourceHandler != null &&
                        parent != null && !parent.equals(c.getParent()))
                    {
                        // Replace parent with the relocated parent.
                        parent = c.getParent();
                    }
                }
                if (facetName == null)
                {
                    parent.getChildren().remove(c);
                }
                else
                {
                    ComponentSupport.removeFacet(ctx, parent, c, facetName);
                }
                if (mctx.isRefreshingSection())
                {
                    facesContext.setProcessingEvents(oldProcessingEvents);
                }
            //}
        }


        if (!componentFound)
        {
            if (c instanceof ClientBehaviorHolder && !UIComponent.isCompositeComponent(c))
            {
                Iterator<AjaxHandler> it = ((AbstractFaceletContext) ctx).getAjaxHandlers();
                if (it != null)
                {
                    while(it.hasNext())
                    {
                        it.next().applyAttachedObject(facesContext, c);
                    }
                }
            }
           
            if (c instanceof EditableValueHolder)
            {
                // add default validators here, because this feature
                // is only available in facelets (see MYFACES-2362 for details)
                addEnclosingAndDefaultValidators(ctx, mctx, facesContext, (EditableValueHolder) c);
            }
        }
       
        _delegate.onComponentPopulated(ctx, c, oldParent);

        if (componentFound && mctx.isRefreshingSection())
        {
            facesContext.setProcessingEvents(false);
        }
        if (facetName == null)
        {
            parent.getChildren().add(c);
        }
        else
        {
            ComponentSupport.addFacet(ctx, parent, c, facetName);
        }
        if (componentFound && mctx.isRefreshingSection())
        {
            facesContext.setProcessingEvents(oldProcessingEvents);
        }

        if (c instanceof UniqueIdVendor)
        {
            mctx.popUniqueIdVendorToStack();
        }

        c.popComponentFromEL(facesContext);
       
        if (mctx.isMarkInitialState())
        {
            //Call it only if we are using partial state saving
            c.markInitialState();
        }
    }
View Full Code Here

    private void setResourceIdOnFaceletsMode(FacesContext facesContext, UIComponent component,
            Class<?> inspectedClass)
    {
        if (component.getId() == null)
        {
            FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(facesContext);
            if (mctx != null)
            {
                UIViewRoot root = facesContext.getViewRoot();
                root.getAttributes().put(RESOURCE_DEPENDENCY_UNIQUE_ID_KEY, Boolean.TRUE);
                try
                {
                    String uid = root.createUniqueId(facesContext, null);
                    component.setId(uid);
                }
                finally
                {
                    root.getAttributes().put(RESOURCE_DEPENDENCY_UNIQUE_ID_KEY, Boolean.FALSE);
                }
                if (!mctx.isUsingPSSOnThisView())
                {
                    // Now set the identifier that will help to know which classes has been already inspected.
                    component.getAttributes().put(
                            RequestViewContext.RESOURCE_DEPENDENCY_INSPECTED_CLASS, inspectedClass);
                }
                else if (mctx.isRefreshTransientBuildOnPSSPreserveState())
                {
                    component.getAttributes().put(
                            RequestViewContext.RESOURCE_DEPENDENCY_INSPECTED_CLASS, inspectedClass);
                }
            }
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

     *      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());
                }
            }
        }
        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)
            {
                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

            if (getFor() == null)
            {
                throw new TagException(_delegate.getTag(), "is nested inside a composite component"
                        + " but does not have a for attribute.");
            }
            FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx);
            mctx.addAttachedObjectHandler(parent, _delegate);
        }
        else
        {
            throw new TagException(_delegate.getTag(),
                    "Parent not composite component or an instance of ValueHolder: " + parent);
View Full Code Here

        // our id
        String id = ctx.generateUniqueId(_delegate.getTagId());

        // Cast to use UniqueIdVendor stuff
        FaceletCompositionContext mctx = (FaceletCompositionContext) FaceletCompositionContext.getCurrentInstance(ctx);
               
        // grab our component
        UIComponent c = null;
        //boolean componentFoundInserted = false;

        //Used to preserve the original parent. Note when the view is being refreshed, the real parent could be
        //another component.
        UIComponent oldParent = parent;
       
        if (mctx.isRefreshingSection())
        {
            if (_relocatableResourceHandler != null)
            {
                c = _relocatableResourceHandler.findChildByTagId(ctx, parent, id);
            }
            else
            {
                c = ComponentSupport.findChildByTagId(parent, id);
            }
        }
        boolean componentFound = false;
        if (c != null)
        {
            componentFound = true;
           
            mctx.incrementUniqueComponentId();
           
            // mark all children for cleaning
            if (log.isLoggable(Level.FINE))
            {
                log.fine(_delegate.getTag() + " Component[" + id + "] Found, marking children for cleanup");
            }

            // The call for mctx.markForDeletion(c) is always necessary, because
            // component resource relocation occur as an effect of PostAddToViewEvent,
            // so at this point it is unknown if the component was relocated or not.
            mctx.markForDeletion(c);

            if (_relocatableResourceHandler != null)
            {
                mctx.markRelocatableResourceForDeletion(c);
            }
        }
        else
        {
            c = this.createComponent(ctx);
            if (log.isLoggable(Level.FINE))
            {
                log.fine(_delegate.getTag() + " Component[" + id + "] Created: " + c.getClass().getName());
            }
           
            _delegate.setAttributes(ctx, c);

            // mark it owned by a facelet instance
            c.getAttributes().put(ComponentSupport.MARK_CREATED, id);

            if (facesContext.isProjectStage(ProjectStage.Development))
            {
                c.getAttributes().put(UIComponent.VIEW_LOCATION_KEY,
                        _delegate.getTag().getLocation());
            }

            // assign our unique id
            if (this._id != null)
            {
                mctx.incrementUniqueComponentId();
                c.setId(this._id.getValue(ctx));
            }
            else
            {
                String componentId = mctx.generateUniqueComponentId();
                UniqueIdVendor uniqueIdVendor = mctx.getUniqueIdVendorFromStack();
                if (uniqueIdVendor == null)
                {
                    uniqueIdVendor = facesContext.getViewRoot();
                   
                    if (uniqueIdVendor == null)
                    {
                        // facesContext.getViewRoot() returns null here if we are in
                        // phase restore view, so we have to try to get the view root
                        // via the method in ComponentSupport and our parent
                        uniqueIdVendor = ComponentSupport.getViewRoot(ctx, parent);
                    }
                }
                if (uniqueIdVendor != null)
                {
                    // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot
                    // and call createUniqueId()
                    String uid = uniqueIdVendor.createUniqueId(facesContext, componentId);
                    c.setId(uid);
                }
            }

            if (this._rendererType != null)
            {
                c.setRendererType(this._rendererType);
            }

            // hook method
            _delegate.onComponentCreated(ctx, c, parent);
           
            if (mctx.isRefreshingTransientBuild() && _relocatableResourceHandler != null)
            {
                mctx.markRelocatableResourceForDeletion(c);
            }
        }
        c.pushComponentToEL(facesContext, c);

        if (c instanceof UniqueIdVendor)
        {
            mctx.pushUniqueIdVendorToStack((UniqueIdVendor)c);
        }
        // first allow c to get populated
        _delegate.applyNextHandler(ctx, c);

        boolean oldProcessingEvents = facesContext.isProcessingEvents();
        // finish cleaning up orphaned children
        if (componentFound)
        {
            mctx.finalizeForDeletion(c);

            //if (!componentFoundInserted)
            //{
                if (mctx.isRefreshingSection())
                {
                    facesContext.setProcessingEvents(false);
                    if (_relocatableResourceHandler != null &&
                        parent != null && !parent.equals(c.getParent()))
                    {
                        // Replace parent with the relocated parent.
                        parent = c.getParent();
                    }
                }
                if (facetName == null)
                {
                    parent.getChildren().remove(c);
                }
                else
                {
                    ComponentSupport.removeFacet(ctx, parent, c, facetName);
                }
                if (mctx.isRefreshingSection())
                {
                    facesContext.setProcessingEvents(oldProcessingEvents);
                }
            //}
        }


        if (!componentFound)
        {
            if (c instanceof ClientBehaviorHolder && !UIComponent.isCompositeComponent(c))
            {
                Iterator<AjaxHandler> it = ((AbstractFaceletContext) ctx).getAjaxHandlers();
                if (it != null)
                {
                    while(it.hasNext())
                    {
                        it.next().applyAttachedObject(facesContext, c);
                    }
                }
            }
           
            if (c instanceof EditableValueHolder)
            {
                // add default validators here, because this feature
                // is only available in facelets (see MYFACES-2362 for details)
                addEnclosingAndDefaultValidators(ctx, mctx, facesContext, (EditableValueHolder) c);
            }
        }
       
        _delegate.onComponentPopulated(ctx, c, oldParent);

        if (componentFound && mctx.isRefreshingSection())
        {
            facesContext.setProcessingEvents(false);
        }
        if (facetName == null)
        {
            parent.getChildren().add(c);
        }
        else
        {
            ComponentSupport.addFacet(ctx, parent, c, facetName);
        }
        if (componentFound && mctx.isRefreshingSection())
        {
            facesContext.setProcessingEvents(oldProcessingEvents);
        }

        if (c instanceof UniqueIdVendor)
        {
            mctx.popUniqueIdVendorToStack();
        }

        c.popComponentFromEL(facesContext);
       
        if (mctx.isMarkInitialState())
        {
            //Call it only if we are using partial state saving
            c.markInitialState();
        }
    }
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

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.