Package org.apache.myfaces.view.facelets

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


     *            parameter type
     * @return a MethodExpression instance
     */
    public MethodExpression getMethodExpression(FaceletContext ctx, Class type, Class[] paramTypes)
    {
        AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
       
        //volatile reads are atomic, so take the tuple to later comparison.
        Object[] localCachedExpression = cachedExpression;
       
        if (actx.isAllowCacheELExpressions() && localCachedExpression != null && (localCachedExpression.length % 3 == 0))
        {
            //If the expected type and paramTypes are the same return the cached one
            for (int i = 0; i < (localCachedExpression.length/3); i++)
            {
                if ( ((type == null && localCachedExpression[(i*3)] == null ) ||
                     (type != null && type.equals(localCachedExpression[(i*3)])) ) &&
                     (Arrays.equals(paramTypes, (Class[]) localCachedExpression[(i*3)+1])) )
                {
                    return (MethodExpression) localCachedExpression[(i*3)+2];
                }
            }
        }
       
        actx.beforeConstructELExpression();
        try
        {
            MethodExpression methodExpression = null;
           
            // From this point we can suppose this attribute contains a ELExpression
            // Now we have to check if the expression points to a composite component attribute map
            // and if so deal with it as an indirection.
            // NOTE that we have to check if the expression refers to cc.attrs for a MethodExpression
            // (#{cc.attrs.myMethod}) or only for MethodExpression parameters (#{bean.method(cc.attrs.value)}).
            if ((this.capabilities & EL_CC_ATTR_ME) != 0)
            {
                // The MethodExpression is on parent composite component attribute map.
                // create a pointer that are referred to the real one that is created in other side
                // (see VDL.retargetMethodExpressions for details)
               
                // check for params in the the MethodExpression
                if (ExternalSpecifications.isUnifiedELAvailable() && this.value.contains("("))
                {
                    // if we don't throw this exception here, another ELException will be
                    // thrown later, because #{cc.attrs.method(param)} will not work as a
                    // ValueExpression pointing to a MethodExpression
                    throw new ELException("Cannot add parameters to a MethodExpression "
                            + "pointing to cc.attrs");
                }
               
                ValueExpression valueExpr = this.getValueExpression(ctx, Object.class);
                methodExpression = new ValueExpressionMethodExpression(valueExpr);
            }
            else
            {
                ExpressionFactory f = ctx.getExpressionFactory();
                methodExpression = f.createMethodExpression(ctx, this.value, type, paramTypes);
                   
                // if the MethodExpression contains a reference to the current composite
                // component, the Location also has to be stored in the MethodExpression
                // to be able to resolve the right composite component (the one that was
                // created from the file the Location is pointing to) later.
                // (see MYFACES-2561 for details)
                if ((this.capabilities & EL_CC) != 0)
                {
                    methodExpression = new LocationMethodExpression(getLocation(), methodExpression);
                }
            }
           
            if (actx.getFaceletCompositionContext().isWrapTagExceptionsAsContextAware())
            {
                methodExpression = new ContextAwareTagMethodExpression(this, methodExpression);
            }
            else
            {
                methodExpression = new TagMethodExpression(this, methodExpression);
            }
               
            if (actx.isAllowCacheELExpressions() && !actx.isAnyFaceletsVariableResolved())
            {
                if (localCachedExpression != null && (localCachedExpression.length % 3 == 0))
                {
                    // If you use a racy single check, assign
                    // the volatile variable at the end.
                    Object[] array = new Object[localCachedExpression.length+3];
                    array[0] = type;
                    array[1] = paramTypes;
                    array[2] = methodExpression;
                    for (int i = 0; i < localCachedExpression.length; i++)
                    {
                        array[i+3] = localCachedExpression[i];
                    }
                    cachedExpression = array;
                }
                else
                {
                    cachedExpression = new Object[]{type, paramTypes, methodExpression};
                }
            }

            return methodExpression;
        }
        catch (Exception e)
        {
            throw new TagAttributeException(this, e);
        }
        finally
        {
            actx.afterConstructELExpression();
        }
    }
View Full Code Here


     *            expected return type
     * @return ValueExpression instance
     */
    public ValueExpression getValueExpression(FaceletContext ctx, Class type)
    {
        AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
       
        //volatile reads are atomic, so take the tuple to later comparison.
        Object[] localCachedExpression = cachedExpression;
        if (actx.isAllowCacheELExpressions() && localCachedExpression != null && localCachedExpression.length == 2)
        {
            //If the expected type is the same return the cached one
            if (localCachedExpression[0] == null && type == null)
            {
                return (ValueExpression) localCachedExpression[1];
            }
            else if (localCachedExpression[0] != null && localCachedExpression[0].equals(type))
            {
                return (ValueExpression) localCachedExpression[1];
            }
        }

        actx.beforeConstructELExpression();
        try
        {
            ExpressionFactory f = ctx.getExpressionFactory();
            ValueExpression valueExpression = f.createValueExpression(ctx, this.value, type);
           
            if (ExternalSpecifications.isUnifiedELAvailable())
            {
                if (actx.getFaceletCompositionContext().isWrapTagExceptionsAsContextAware())
                {
                    valueExpression = new ContextAwareTagValueExpressionUEL(this, valueExpression);
                }
                else
                {
                    valueExpression = new TagValueExpressionUEL(this, valueExpression);
                }
            }
            else
            {
                if (actx.getFaceletCompositionContext().isWrapTagExceptionsAsContextAware())
                {
                    valueExpression = new ContextAwareTagValueExpression(this, valueExpression);
                }
                else
                {
                    valueExpression = new TagValueExpression(this, valueExpression);
                }
            }

            // if the ValueExpression contains a reference to the current composite
            // component, the Location also has to be stored in the ValueExpression
            // to be able to resolve the right composite component (the one that was
            // created from the file the Location is pointing to) later.
            // (see MYFACES-2561 for details)
            if ((this.capabilities & EL_CC) != 0)
            {
                if (ExternalSpecifications.isUnifiedELAvailable())
                {
                    valueExpression = new LocationValueExpressionUEL(getLocation(), valueExpression);
                }
                else
                {
                    valueExpression = new LocationValueExpression(getLocation(), valueExpression);
                }
            }
            else if ((this.capabilities & EL_RESOURCE) != 0)
            {
                if (ExternalSpecifications.isUnifiedELAvailable())
                {
                    valueExpression = new ResourceLocationValueExpressionUEL(getLocation(), valueExpression);
                }
                else
                {
                    valueExpression = new ResourceLocationValueExpression(getLocation(), valueExpression);
                }
            }
           
           
            if (actx.isAllowCacheELExpressions() && !actx.isAnyFaceletsVariableResolved())
            {
                cachedExpression = new Object[]{type, valueExpression};
            }
            return valueExpression;
        }
        catch (Exception e)
        {
            throw new TagAttributeException(this, e);
        }
        finally
        {
            actx.afterConstructELExpression();
        }
    }
View Full Code Here

                ValueExpression expr = ctx.getExpressionFactory().createValueExpression(
                        elCtx, expStr.toString(), Object.class);
                expr.setValue(elCtx, veObj.getValue(elCtx));
            } else {
                //ctx.getVariableMapper().setVariable(varStr, veObj);
                AbstractFaceletContext actx = ((AbstractFaceletContext) ctx);
                actx.getPageContext().getAttributes().put(varStr, veObj);
                if (actx.getPageContext().isAllowCacheELExpressions())
                {
                    if (ELExpressionCacheMode.strict.equals(actx.getELExpressionCacheMode()))
                    {
                        actx.getPageContext().setAllowCacheELExpressions(false);
                    }
                }
            }
        }
        else
View Full Code Here

        }
        else
        {
            String facetName = _name.getValue(ctx);
           
            AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
           
            UIComponent parentCompositeComponent = FaceletCompositionContext.getCurrentInstance(ctx).getCompositeComponentFromStack();
           
            actx.includeCompositeComponentDefinition(parent, facetName);
           
            //parentCompositeComponent.getAttributes().put(INSERT_FACET_USED+facetName, Boolean.TRUE);
        }
       
    }
View Full Code Here

            }
            else
            {
                this._names.add(testName);
                boolean found = false;
                AbstractFaceletContext actx = new DefaultFaceletContext(
                        (DefaultFaceletContext) ctx, this._owner, false);
                ctx.getFacesContext().getAttributes().put(FaceletContext.FACELET_CONTEXT_KEY, actx);
                try
                {
                    actx.pushPageContext(this._pageContext);
                    found = this._target
                            .apply(actx,
                                    parent, name);
                }
                finally
                {
                    actx.popPageContext();
                }
                ctx.getFacesContext().getAttributes().put(FaceletContext.FACELET_CONTEXT_KEY, ctx);
                this._names.remove(testName);
                return found;
            }
View Full Code Here

            return false;
        }

        public ELText apply(ExpressionFactory factory, ELContext ctx)
        {
            AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
           
            if (actx.isAllowCacheELExpressions() && cached != null)
            {
                return cached;
            }
           
            actx.beforeConstructELExpression();
            try
            {
                ValueExpression valueExpression = factory.createValueExpression(ctx, this.ve.getExpressionString(), String.class);
             
                if ((this.capabilities & EL_CC) != 0)
                {
                    UIComponent cc = actx.getFaceletCompositionContext().getCompositeComponentFromStack();
                    if (cc != null)
                    {
                        Location location = (Location) cc.getAttributes().get(CompositeComponentELUtils.LOCATION_KEY);
                        if (location != null)
                        {
                            if (ExternalSpecifications.isUnifiedELAvailable())
                            {
                                valueExpression = new LocationValueExpressionUEL(location, valueExpression);
                            }
                            else
                            {
                                valueExpression = new LocationValueExpression(location, valueExpression);
                            }
                        }
                    }
                }
                else if ((this.capabilities & EL_RESOURCE) != 0)
                {
                    UIComponent cc = actx.getFaceletCompositionContext().getCompositeComponentFromStack();
                    if (cc != null)
                    {
                        Location location = (Location) cc.getAttributes().get(CompositeComponentELUtils.LOCATION_KEY);
                        if (location != null)
                        {
                            if (ExternalSpecifications.isUnifiedELAvailable())
                            {
                                valueExpression = new ResourceLocationValueExpressionUEL(location, valueExpression);
                            }
                            else
                            {
                                valueExpression = new ResourceLocationValueExpression(location, valueExpression);
                            }
                        }
                    }
                }
               
                ELTextVariable eltv = new ELTextVariable(valueExpression);
               
                if (actx.isAllowCacheELExpressions() && !actx.isAnyFaceletsVariableResolved())
                {
                     cached = eltv;
                }
                return eltv;
            }
            finally
            {
                actx.afterConstructELExpression();
            }
        }
View Full Code Here

        //Apply only if we are creating a new component
        if (!ComponentHandler.isNew(parent))
        {
            if (_wrapMode)
            {
                AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
                // In this case it will be only applied to components inserted by
                // c:if or related tags, in other cases, ComponentTagHandlerDelegate should
                // not reapply ajax tag.
                actx.pushAjaxHandlerToStack(this);
                nextHandler.apply(ctx, parent);
                actx.popAjaxHandlerToStack();
            }
            return;
        }
        if (_wrapMode)
        {
            AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
            // Push and pop this ajax handler to the stack, to delegate the
            // call to applyAttachedObject to ComponentTagHandlerDelegate
            // TODO: The spec is not clear about how to deal with
            // composite component instances. The default one proposed here is
            // use a different stack on DefaultFaceletContext.applyCompositeComponent,
            // so components inside composite:implementation tag will not be
            // affected by f:ajax outsider handlers.
            actx.pushAjaxHandlerToStack(this);
            nextHandler.apply(ctx, parent);
            actx.popAjaxHandlerToStack();
        }
        else
        {
            if (parent instanceof ClientBehaviorHolder)
            {
View Full Code Here

     * @see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext, javax.faces.component.UIComponent)
     */
    public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
            ELException
    {
        AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
        String path = this.src.getValue(ctx);
        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;
            // 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);
               
            }
            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
            {
                actx.popTemplateContext();
            }
        }
        finally
        {
            ctx.setVariableMapper(orig);
View Full Code Here

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

        AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
        actx.pushClient(this);

        if (_params != null)
        {
            //VariableMapper vm = new VariableMapperWrapper(orig);
            //ctx.setVariableMapper(vm);
            for (int i = 0; i < _params.length; i++)
            {
                _params[i].apply(ctx, parent);
            }
        }

        try
        {
            ctx.includeFacelet(parent, _template.getValue(ctx));
        }
        finally
        {
            //ctx.setVariableMapper(orig);
            actx.popClient(this);
        }
    }
View Full Code Here

   
    public void apply(FaceletContext ctx, UIComponent parent, String nameStr, ValueExpression valueVE) throws IOException, FacesException, FaceletException,
            ELException
    {
        //((AbstractFaceletContext) ctx).getTemplateContext().getAttributes().put(nameStr, valueVE);
        AbstractFaceletContext actx = ((AbstractFaceletContext) ctx);
        actx.getTemplateContext().setParameter(nameStr, valueVE);
       
        if (actx.getTemplateContext().isAllowCacheELExpressions())
        {
            if (ELExpressionCacheMode.strict.equals(actx.getELExpressionCacheMode()) ||
                ELExpressionCacheMode.allowCset.equals(actx.getELExpressionCacheMode()))
            {
                actx.getTemplateContext().setAllowCacheELExpressions(false);
            }
        }
    }
View Full Code Here

TOP

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

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.