Package org.apache.myfaces.view.facelets

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


        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;
            }
           
            this.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);
            this.markApplied(parent);
           
            // remove the UniqueIdVendor from the stack again
            if (pushedUniqueIdVendor)
            {
View Full Code Here


            // our id
            String id = ctx.generateUniqueId(this.id);

            // grab our component
            UIComponent c = null;
            FaceletCompositionContext mctx= FaceletCompositionContext.getCurrentInstance(ctx);
            boolean componentFoundInserted = false;
           
            String componentId = mctx.generateUniqueComponentId();
           
            if (mctx.isRefreshingTransientBuild())
            {
                c = ComponentSupport.findChildByTagId(parent, id);
            }
            boolean componentFound = false;
            if (c != null)
            {
                componentFound = true;
                // mark all children for cleaning
                mctx.markForDeletion(c);
            }
            else
            {
                Instruction[] applied;
                if (this.literal)
                {
                    applied = this.instructions;
                }
                else
                {
                    int size = this.instructions.length;
                    applied = new Instruction[size];
                    // Create a new list with all of the necessary applied
                    // instructions
                    Instruction ins;
                    for (int i = 0; i < size; i++)
                    {
                        ins = this.instructions[i];
                        applied[i] = ins.apply(ctx.getExpressionFactory(), ctx);
                    }
                }

                c = new UIInstructions(txt, applied);
                // mark it owned by a facelet instance
                //c.setId(ComponentSupport.getViewRoot(ctx, parent).createUniqueId());

                UniqueIdVendor uniqueIdVendor
                        = FaceletCompositionContext.getCurrentInstance(ctx).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(). Also, note that UIViewRoot.createUniqueId() javadoc
                    // says we could send as seed the facelet generated id.
                    String uid = uniqueIdVendor.createUniqueId(ctx.getFacesContext(), componentId);
                    c.setId(uid);
                }               
                //c.getAttributes().put(ComponentSupport.MARK_CREATED, id);
                ((UIInstructions)c).setMarkCreated(id);
            }
           
            boolean oldProcessingEvents = ctx.getFacesContext().isProcessingEvents();
            // finish cleaning up orphaned children
            if (componentFound)
            {
                mctx.finalizeForDeletion(c);
                if (!componentFoundInserted)
                {
                    if (mctx.isRefreshingTransientBuild())
                    {
                        ctx.getFacesContext().setProcessingEvents(false);
                    }
                    parent.getChildren().remove(c);
                    if (mctx.isRefreshingTransientBuild())
                    {
                        ctx.getFacesContext().setProcessingEvents(oldProcessingEvents);
                    }
                }
            }
            if (!componentFoundInserted)
            {
                if (componentFound && mctx.isRefreshingTransientBuild())
                {
                    ctx.getFacesContext().setProcessingEvents(false);
                }
                this.addComponent(ctx, parent, c);
                if (componentFound && mctx.isRefreshingTransientBuild())
                {
                    ctx.getFacesContext().setProcessingEvents(oldProcessingEvents);
                }
            }
        }
View Full Code Here

     */
    public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
            ELException
    {
        AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
        FaceletCompositionContext fcc = FaceletCompositionContext.getCurrentInstance(ctx);
        String path;
        boolean markInitialState = false;
        if (!src.isLiteral())
        {
            String uniqueId = fcc.startComponentUniqueIdSection();
            //path = getSrcValue(actx, fcc, parent, uniqueId);
            String restoredPath = (String) ComponentSupport.restoreInitialTagState(ctx, fcc, parent, uniqueId);
            if (restoredPath != null)
            {
                // If is not restore view phase, the path value should be
                // evaluated and if is not equals, trigger markInitialState stuff.
                if (!PhaseId.RESTORE_VIEW.equals(ctx.getFacesContext().getCurrentPhaseId()))
                {
                    path = this.src.getValue(ctx);
                    if (path == null || path.length() == 0)
                    {
                        return;
                    }
                    if (!path.equals(restoredPath))
                    {
                        markInitialState = true;
                    }
                }
                else
                {
                    path = restoredPath;
                }
            }
            else
            {
                //No state restored, calculate path
                path = this.src.getValue(ctx);
            }
            ComponentSupport.saveInitialTagState(ctx, fcc, parent, uniqueId, path);
        }
        else
        {
            path = this.src.getValue(ctx);
        }
        try
        {
            if (path == null || path.length() == 0)
            {
                return;
            }
            VariableMapper orig = ctx.getVariableMapper();
            ctx.setVariableMapper(new VariableMapperWrapper(orig));
            try
            {
                //Only ui:param could be inside ui:include.
                //this.nextHandler.apply(ctx, null);
               
                URL url = null;
                boolean oldMarkInitialState = false;
                Boolean isBuildingInitialState = null;
                // if we are in ProjectStage Development and the path equals "javax.faces.error.xhtml"
                // we should include the default error page
                if (ctx.getFacesContext().isProjectStage(ProjectStage.Development)
                        && ERROR_PAGE_INCLUDE_PATH.equals(path))
                {
                    url =ClassUtils.getResource(ERROR_FACELET);
                }
                if (markInitialState)
                {
                    //set markInitialState flag
                    oldMarkInitialState = fcc.isMarkInitialState();
                    fcc.setMarkInitialState(true);
                    isBuildingInitialState = (Boolean) ctx.getFacesContext().getAttributes().put(
                            "javax.faces.IS_BUILDING_INITIAL_STATE", Boolean.TRUE);
                }
                try
                {
                    if (_params != null)
                    {
                        // ui:include defines a new TemplateContext, but ui:param EL expressions
                        // defined inside should be built before the new context is setup, to
                        // apply then after. The final effect is EL expressions will be resolved
                        // correctly when nested ui:params with the same name or based on other
                        // ui:params are used.
                       
                        String[] names = new String[_params.length];
                        ValueExpression[] values = new ValueExpression[_params.length];
                       
                        for (int i = 0; i < _params.length; i++)
                        {
                            names[i] = _params[i].getName(ctx);
                            values[i] = _params[i].getValue(ctx);
                        }
                       
                        actx.pushTemplateContext(new TemplateContextImpl());
                       
                        for (int i = 0; i < _params.length; i++)
                        {
                            _params[i].apply(ctx, parent, names[i], values[i]);
                        }
                    }
                    else
                    {
                        actx.pushTemplateContext(new TemplateContextImpl());
                    }
                    if (url == null)
                    {
                        ctx.includeFacelet(parent, path);
                    }
                    else
                    {
                        ctx.includeFacelet(parent, url);
                    }
                }
                finally
                {
                    if (markInitialState)
                    {
                        //unset markInitialState flag
                        if (isBuildingInitialState == null)
                        {
                            ctx.getFacesContext().getAttributes().remove(
                                    "javax.faces.IS_BUILDING_INITIAL_STATE");
                        }
                        else
                        {
                            ctx.getFacesContext().getAttributes().put(
                                    "javax.faces.IS_BUILDING_INITIAL_STATE", isBuildingInitialState);
                        }
                        fcc.setMarkInitialState(oldMarkInitialState);
                    }
                    actx.popTemplateContext();
                }
            }
            finally
            {
                ctx.setVariableMapper(orig);
            }
        }
        finally
        {
            if (!src.isLiteral())
            {
                fcc.endComponentUniqueIdSection();
            }
        }
        if (!src.isLiteral() && fcc.isUsingPSSOnThisView() && fcc.isRefreshTransientBuildOnPSS() &&
            !fcc.isRefreshingTransientBuild())
        {
            //Mark the parent component to be saved and restored fully.
            ComponentSupport.markComponentToRestoreFully(ctx.getFacesContext(), parent);
        }
    }
View Full Code Here

            {
                _params[i].apply(ctx, parent);
            }
        }

        FaceletCompositionContext fcc = FaceletCompositionContext.getCurrentInstance(ctx);
        String path;
        boolean markInitialState = false;
        if (!_template.isLiteral())
        {
            String uniqueId = fcc.startComponentUniqueIdSection();
            //path = getTemplateValue(actx, fcc, parent, uniqueId);
            String restoredPath = (String) ComponentSupport.restoreInitialTagState(ctx, fcc, parent, uniqueId);
            if (restoredPath != null)
            {
                // If is not restore view phase, the path value should be
                // evaluated and if is not equals, trigger markInitialState stuff.
                if (!PhaseId.RESTORE_VIEW.equals(ctx.getFacesContext().getCurrentPhaseId()))
                {
                    path = this._template.getValue(ctx);
                    if (path == null || path.length() == 0)
                    {
                        return;
                    }
                    if (!path.equals(restoredPath))
                    {
                        markInitialState = true;
                    }
                }
                else
                {
                    path = restoredPath;
                }
            }
            else
            {
                //No state restored, calculate path
                path = this._template.getValue(ctx);
            }
            ComponentSupport.saveInitialTagState(ctx, fcc, parent, uniqueId, path);
        }
        else
        {
            path = _template.getValue(ctx);
        }
        try
        {
            boolean oldMarkInitialState = false;
            Boolean isBuildingInitialState = null;
            if (markInitialState)
            {
                //set markInitialState flag
                oldMarkInitialState = fcc.isMarkInitialState();
                fcc.setMarkInitialState(true);
                isBuildingInitialState = (Boolean) ctx.getFacesContext().getAttributes().put(
                        "javax.faces.IS_BUILDING_INITIAL_STATE", Boolean.TRUE);
            }
            try
            {
                ctx.includeFacelet(parent, path);
            }
            finally
            {
                if (markInitialState)
                {
                    //unset markInitialState flag
                    if (isBuildingInitialState == null)
                    {
                        ctx.getFacesContext().getAttributes().remove(
                                "javax.faces.IS_BUILDING_INITIAL_STATE");
                    }
                    else
                    {
                        ctx.getFacesContext().getAttributes().put(
                                "javax.faces.IS_BUILDING_INITIAL_STATE", isBuildingInitialState);
                    }
                    fcc.setMarkInitialState(oldMarkInitialState);
                }
            }
        }
        finally
        {
            //ctx.setVariableMapper(orig);
            actx.popClient(this);
        }
        if (!_template.isLiteral())
        {
            fcc.endComponentUniqueIdSection();
        }
        if (!_template.isLiteral() && fcc.isUsingPSSOnThisView() && fcc.isRefreshTransientBuildOnPSS() &&
            !fcc.isRefreshingTransientBuild())
        {
            //Mark the parent component to be saved and restored fully.
            ComponentSupport.markComponentToRestoreFully(ctx.getFacesContext(), parent);
        }
    }
View Full Code Here

    }

    public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
            ELException
    {
        FaceletCompositionContext fcc = FaceletCompositionContext.getCurrentInstance(ctx);
        boolean processed = false;
        //assign an unique id for this section
        String uniqueId = fcc.startComponentUniqueIdSection();
        Integer savedOption = null;
       
        Integer restoredSavedOption = getSavedOption(ctx, fcc, parent, uniqueId);
       
        if (restoredSavedOption != null)
        {
            if (!PhaseId.RESTORE_VIEW.equals(ctx.getFacesContext().getCurrentPhaseId()))
            {
                for (int i = 0; i < this.when.length; i++)
                {
                    //Ensure each option has its unique section
                    fcc.startComponentUniqueIdSection();
                    if (!processed)
                    {
                        if (this.when[i].isTestTrue(ctx))
                        {
                            boolean markInitialState = !restoredSavedOption.equals(i);
                            boolean oldMarkInitialState = false;
                            Boolean isBuildingInitialState = null;
                            try
                            {
                                if (markInitialState)
                                {
                                    //set markInitialState flag
                                    oldMarkInitialState = fcc.isMarkInitialState();
                                    fcc.setMarkInitialState(true);
                                    isBuildingInitialState = (Boolean) ctx.getFacesContext().getAttributes().put(
                                            "javax.faces.IS_BUILDING_INITIAL_STATE", Boolean.TRUE);
                                }
                                this.when[i].apply(ctx, parent);
                            }
                            finally
                            {
                                if (markInitialState)
                                {
                                    //unset markInitialState flag
                                    if (isBuildingInitialState == null)
                                    {
                                        ctx.getFacesContext().getAttributes().remove(
                                                "javax.faces.IS_BUILDING_INITIAL_STATE");
                                    }
                                    else
                                    {
                                        ctx.getFacesContext().getAttributes().put(
                                                "javax.faces.IS_BUILDING_INITIAL_STATE", isBuildingInitialState);
                                    }
                                    fcc.setMarkInitialState(oldMarkInitialState);
                                }
                            }
                            processed = true;
                            savedOption = i;
                            //return;
                        }
                    }
                    fcc.endComponentUniqueIdSection();
                }

            }
            else
            {
                for (int i = 0; i < this.when.length; i++)
                {
                    //Ensure each option has its unique section
                    fcc.startComponentUniqueIdSection();
                    if (!processed)
                    {
                        if (restoredSavedOption.equals(i))
                        {
                            this.when[i].apply(ctx, parent);
                            processed = true;
                            savedOption = i;
                            //return;
                        }
                    }
                    fcc.endComponentUniqueIdSection();
                }
            }
        }
        else
        {
            for (int i = 0; i < this.when.length; i++)
            {
                //Ensure each option has its unique section
                fcc.startComponentUniqueIdSection();
                if (!processed)
                {
                    if (this.when[i].isTestTrue(ctx))
                    {
                        this.when[i].apply(ctx, parent);
                        processed = true;
                        savedOption = i;
                        //return;
                    }
                }
                fcc.endComponentUniqueIdSection();
            }
        }
        if (this.otherwise != null)
        {
            fcc.startComponentUniqueIdSection();
            if (!processed)
            {
                this.otherwise.apply(ctx, parent);
                savedOption = -1;
            }
            fcc.endComponentUniqueIdSection();
        }
       
        fcc.endComponentUniqueIdSection();

        ComponentSupport.saveInitialTagState(ctx, fcc, parent, uniqueId, savedOption);
        if (fcc.isUsingPSSOnThisView() && fcc.isRefreshTransientBuildOnPSS() && !fcc.isRefreshingTransientBuild())
        {
            //Mark the parent component to be saved and restored fully.
            ComponentSupport.markComponentToRestoreFully(ctx.getFacesContext(), parent);
        }
    }
View Full Code Here

        this.var = this.getAttribute("var");
    }

    public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, ELException
    {
        FaceletCompositionContext fcc = FaceletCompositionContext.getCurrentInstance(ctx);
        String uniqueId = fcc.startComponentUniqueIdSection();
        Boolean restoredValue = (Boolean) ComponentSupport.restoreInitialTagState(ctx, fcc, parent, uniqueId);
        boolean b = false;
        boolean markInitialState = false;
        if (restoredValue != null)
        {
            if (!PhaseId.RESTORE_VIEW.equals(ctx.getFacesContext().getCurrentPhaseId()))
            {
                b = this.test.getBoolean(ctx);
                if (!restoredValue.equals(b))
                {
                    markInitialState = true;
                }
            }
            else
            {
                b = restoredValue;
            }
        }
        else
        {
            // No state restored, calculate
            b = this.test.getBoolean(ctx);
        }
        //boolean b = getTestValue(ctx, fcc, parent, uniqueId);
        if (this.var != null)
        {
            ctx.setAttribute(var.getValue(ctx), new Boolean(b));
        }
        if (b)
        {
            boolean oldMarkInitialState = false;
            Boolean isBuildingInitialState = null;
            try
            {
                if (markInitialState)
                {
                    //set markInitialState flag
                    oldMarkInitialState = fcc.isMarkInitialState();
                    fcc.setMarkInitialState(true);
                    isBuildingInitialState = (Boolean) ctx.getFacesContext().getAttributes().put(
                            "javax.faces.IS_BUILDING_INITIAL_STATE", Boolean.TRUE);
                }
                this.nextHandler.apply(ctx, parent);
            }
            finally
            {
                if (markInitialState)
                {
                    //unset markInitialState flag
                    if (isBuildingInitialState == null)
                    {
                        ctx.getFacesContext().getAttributes().remove(
                                "javax.faces.IS_BUILDING_INITIAL_STATE");
                    }
                    else
                    {
                        ctx.getFacesContext().getAttributes().put(
                                "javax.faces.IS_BUILDING_INITIAL_STATE", isBuildingInitialState);
                    }
                    fcc.setMarkInitialState(oldMarkInitialState);
                }
            }
        }
        fcc.endComponentUniqueIdSection();
        //AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
        ComponentSupport.saveInitialTagState(ctx, fcc, parent, uniqueId, b);
        if (fcc.isUsingPSSOnThisView() && fcc.isRefreshTransientBuildOnPSS() && !fcc.isRefreshingTransientBuild())
        {
            //Mark the parent component to be saved and restored fully.
            ComponentSupport.markComponentToRestoreFully(ctx.getFacesContext(), parent);
        }
    }
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;
        myFaceletContext = FaceletCompositionContext.getCurrentInstance(facesContext);
        if (myFaceletContext == null)
        {
            myFaceletContext = new FaceletCompositionContextImpl(_factory, facesContext);
            myFaceletContext.init(facesContext);
            faceletCompositionContextInitialized = true;
        }
        DefaultFaceletContext ctx = new DefaultFaceletContext(facesContext, this, myFaceletContext);
       
        //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();
           
            if (faceletCompositionContextInitialized)
            {
                myFaceletContext.release(facesContext);
            }
        }
    }
View Full Code Here

    @Override
    public void apply(FaceletContext ctx, UIComponent parent) throws IOException
    {
        // we need methods from AbstractFaceletContext
        FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx);

        if (_wrapMode)
        {
            // the tag has children --> provide validator information for all children
           
            // FIXME the spec says we should save the validation groups in an attribute
            // on the parent UIComponent, but this will be a problem in the following scenario:
            // <h:form>
            //     <f:validateBean>
            //         <h:inputText />
            //     </f:validateBean>
            //     <h:inputText />
            // </h:form>
            // because the validator would also be applied to the second h:inputText,
            // which it should not, on my opinion. In addition, mojarra also does not
            // attach the validator to the second h:inputText in this scenario (blackbox test).
            // So I use the same way as f:ajax for this problem. -=Jakob Korherr=-
           
            String validatorId = _delegate.getValidatorConfig().getValidatorId();
           
            boolean disabled = _delegate.isDisabled(ctx);
            if (disabled)
            {
                // the validator is disabled --> add its id to the exclusion stack
                boolean validatorIdAvailable = validatorId != null && !"".equals(validatorId);
                try
                {
                    if (validatorIdAvailable)
                    {
                        mctx.pushExcludedValidatorIdToStack(validatorId);
                    }
                    _delegate.getValidatorConfig().getNextHandler().apply(ctx, parent);
                }
                finally
                {
                    if (validatorIdAvailable)
                    {
                        mctx.popExcludedValidatorIdToStack();
                    }
                }
            }
            else
            {
                // the validator is enabled
                // --> add the validation groups and the validatorId to the stack
                String groups = getValidationGroups(ctx);
                // spec: don't save the validation groups string if it is null or empty string
                boolean groupsAvailable = groups != null
                        && !groups.matches(BeanValidator.EMPTY_VALIDATION_GROUPS_PATTERN);
                try
                {
                    if (groupsAvailable)
                    {
                        mctx.pushValidationGroupsToStack(groups);
                    }
                    try
                    {
                        mctx.pushEnclosingValidatorIdToStack(validatorId);
                        _delegate.getValidatorConfig().getNextHandler().apply(ctx, parent);
                    }
                    finally
                    {
                        mctx.popEnclosingValidatorIdToStack();
                    }
                }
                finally
                {
                    if (groupsAvailable)
                    {
                        mctx.popValidationGroupsToStack();
                    }
                }
            }
        }
        else
        {
            // Apply only if we are creating a new component
            if (!ComponentHandler.isNew(parent))
            {
                return;
            }

            // the tag is a leave --> attach validator to parent
            if (parent instanceof EditableValueHolder)
            {
                applyAttachedObject(ctx.getFacesContext(), parent);
            }
            else if (UIComponent.isCompositeComponent(parent))
            {
                if (getFor() == null)
                {
                    throw new TagException(_delegate.getTag(), "is nested inside a composite component"
                            + " but does not have a for attribute.");
                }
                mctx.addAttachedObjectHandler(parent, _delegate);
            }
            else
            {
                throw new TagException(_delegate.getTag(), "Parent not composite component or an instance of EditableValueHolder: " + parent);
            }
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

            // our id
            String id = ctx.generateUniqueId(this.id);

            // grab our component
            UIComponent c = null;
            FaceletCompositionContext mctx= FaceletCompositionContext.getCurrentInstance(ctx);
            boolean componentFoundInserted = false;
           
            if (mctx.isRefreshingTransientBuild())
            {
                c = ComponentSupport.findChildByTagId(parent, id);
                /*
                if (c == null && mctx.isRefreshTransientBuildOnPSS() &&
                        mctx.isRefreshingTransientBuild() && UIComponent.isCompositeComponent(parent))
                {
                    String facetName = this.getFacetName(ctx, parent);
                    if (facetName == null)
                    {
                        String targetClientId = (String) parent.getAttributes().get(InsertChildrenHandler.INSERT_CHILDREN_TARGET_ID);
                        if (targetClientId != null)
                        {
                            UIComponent targetComponent = parent.findComponent(targetClientId.substring(parent.getClientId().length()+1));
                            if (targetComponent != null)
                            {
                                c = ComponentSupport.findChildByTagId(targetComponent, id);
                            }
                        }
                        if (c != null)
                        {
                            c.getAttributes().put(InsertChildrenHandler.USES_INSERT_CHILDREN, Boolean.TRUE);
                            componentFoundInserted = true;
                        }
                    }
                    else
                    {
                        String targetClientId = (String) parent.getAttributes().get(InsertFacetHandler.INSERT_FACET_TARGET_ID+facetName);
                        if (targetClientId != null)
                        {
                            UIComponent targetComponent = parent.findComponent(targetClientId.substring(parent.getClientId().length()+1));
                            if (targetComponent != null)
                            {
                                c = ComponentSupport.findChildByTagId(targetComponent, id);
                                if (c != null)
                                {
                                    c.getAttributes().put(InsertFacetHandler.USES_INSERT_FACET, Boolean.TRUE);
                                    componentFoundInserted = true;
                                }
                            }
                        }
                    }
                }
                */
            }
            boolean componentFound = false;
            if (c != null)
            {
                componentFound = true;
                // mark all children for cleaning
                mctx.markForDeletion(c);
            }
            else
            {
                Instruction[] applied;
                if (this.literal)
                {
                    applied = this.instructions;
                }
                else
                {
                    int size = this.instructions.length;
                    applied = new Instruction[size];
                    // Create a new list with all of the necessary applied
                    // instructions
                    Instruction ins;
                    for (int i = 0; i < size; i++)
                    {
                        ins = this.instructions[i];
                        applied[i] = ins.apply(ctx.getExpressionFactory(), ctx);
                    }
                }

                c = new UIInstructions(txt, applied);
                // mark it owned by a facelet instance
                //c.setId(ComponentSupport.getViewRoot(ctx, parent).createUniqueId());

                UniqueIdVendor uniqueIdVendor = FaceletCompositionContext.getCurrentInstance(ctx).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(). Also, note that UIViewRoot.createUniqueId() javadoc
                    // says we could send as seed the facelet generated id.
                    String uid = uniqueIdVendor.createUniqueId(ctx.getFacesContext(), id);
                    c.setId(uid);
                }               
                c.getAttributes().put(ComponentSupport.MARK_CREATED, id);
            }
           
            boolean oldProcessingEvents = ctx.getFacesContext().isProcessingEvents();
            // finish cleaning up orphaned children
            if (componentFound)
            {
                mctx.finalizeForDeletion(c);
                if (!componentFoundInserted)
                {
                    if (mctx.isRefreshingTransientBuild())
                    {
                        ctx.getFacesContext().setProcessingEvents(false);
                    }
                    parent.getChildren().remove(c);
                    if (mctx.isRefreshingTransientBuild())
                    {
                        ctx.getFacesContext().setProcessingEvents(oldProcessingEvents);
                    }
                }
            }
            /*
            if ( mctx.isRefreshingTransientBuild()
                    && UIComponent.isCompositeComponent(parent))
            {
                // Save the child structure behind this component, so it can be
                // used later by InsertChildrenHandler and InsertFacetHandler
                // to update components correctly.
                String facetName = this.getFacetName(ctx, parent);
                if (facetName != null)
                {
                    if (parent.getAttributes().containsKey(InsertFacetHandler.INSERT_FACET_TARGET_ID+facetName))
                    {
                        List<String> ordering = (List<String>) parent.getAttributes().get(
                                InsertFacetHandler.INSERT_FACET_ORDERING+facetName);
                        if (ordering == null)
                        {
                            ordering = new ArrayList<String>();
                            parent.getAttributes().put(InsertFacetHandler.INSERT_FACET_ORDERING+facetName, ordering);
                        }
                        ordering.remove(id);
                        ordering.add(id);
                    }
                }
                else
                {
                    if (parent.getAttributes().containsKey(InsertChildrenHandler.INSERT_CHILDREN_TARGET_ID))
                    {
                        List<String> ordering = (List<String>) parent.getAttributes().get(
                                InsertChildrenHandler.INSERT_CHILDREN_ORDERING);
                        if (ordering == null)
                        {
                            ordering = new ArrayList<String>();
                            parent.getAttributes().put(InsertChildrenHandler.INSERT_CHILDREN_ORDERING, ordering);
                        }
                        ordering.remove(id);
                        ordering.add(id);
                    }
                }
            }
            */
            if (!componentFoundInserted)
            {
                if (componentFound && mctx.isRefreshingTransientBuild())
                {
                    ctx.getFacesContext().setProcessingEvents(false);
                }
                this.addComponent(ctx, parent, c);
                if (componentFound && mctx.isRefreshingTransientBuild())
                {
                    ctx.getFacesContext().setProcessingEvents(oldProcessingEvents);
                }
            }
        }
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.