Search in sources :

Example 1 with FaceletStateValueExpression

use of org.apache.myfaces.view.facelets.el.FaceletStateValueExpression in project myfaces by apache.

the class ForEachHandler method setVar.

private void setVar(FaceletContext ctx, UIComponent parent, String uniqueId, String base, String v, ValueExpression ve, ValueExpression srcVE) {
    AbstractFaceletContext actx = ((AbstractFaceletContext) ctx);
    PageContext pctx = actx.getPageContext();
    if (srcVE != null) {
        FaceletState faceletState = ComponentSupport.getFaceletState(ctx, parent, true);
        faceletState.putBinding(uniqueId, base, ve);
        // Put the indirect EL into context
        ValueExpression fve = new FaceletStateValueExpression(uniqueId, base);
        pctx.getAttributes().put(v, fve);
    } else {
        pctx.getAttributes().put(v, ve);
    }
}
Also used : FaceletStateValueExpression(org.apache.myfaces.view.facelets.el.FaceletStateValueExpression) ValueExpression(jakarta.el.ValueExpression) FaceletStateValueExpression(org.apache.myfaces.view.facelets.el.FaceletStateValueExpression) PageContext(org.apache.myfaces.view.facelets.PageContext) FaceletState(org.apache.myfaces.view.facelets.tag.faces.FaceletState) AbstractFaceletContext(org.apache.myfaces.view.facelets.AbstractFaceletContext)

Example 2 with FaceletStateValueExpression

use of org.apache.myfaces.view.facelets.el.FaceletStateValueExpression in project myfaces by apache.

the class UserTagHandler method apply.

/**
 * Iterate over all TagAttributes and set them on the FaceletContext's VariableMapper, then include the target
 * Facelet. Finally, replace the old VariableMapper.
 *
 * @see TagAttribute#getValueExpression(FaceletContext, Class)
 * @see jakarta.el.VariableMapper
 * @see jakarta.faces.view.facelets.FaceletHandler#apply(jakarta.faces.view.facelets.FaceletContext,
 *        jakarta.faces.component.UIComponent)
 */
@Override
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, ELException {
    AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
    // eval include
    try {
        String[] names = null;
        ValueExpression[] values = null;
        if (this._vars.length > 0) {
            names = new String[_vars.length];
            values = new ValueExpression[_vars.length];
            for (int i = 0; i < _vars.length; i++) {
                names[i] = _vars[i].getLocalName();
                values[i] = _vars[i].getValueExpression(ctx, Object.class);
            }
        }
        actx.pushTemplateContext(new TemplateContextImpl());
        actx.pushClient(this);
        FaceletCompositionContext fcc = FaceletCompositionContext.getCurrentInstance(ctx);
        String uniqueId = fcc.startComponentUniqueIdSection();
        try {
            if (this._vars.length > 0) {
                if (ELExpressionCacheMode.alwaysRecompile.equals(actx.getELExpressionCacheMode())) {
                    FaceletState faceletState = ComponentSupport.getFaceletState(ctx, parent, true);
                    for (int i = 0; i < this._vars.length; i++) {
                        faceletState.putBinding(uniqueId, names[i], values[i]);
                        ValueExpression ve = new FaceletStateValueExpression(uniqueId, names[i]);
                        actx.getTemplateContext().setParameter(names[i], ve);
                    }
                } else {
                    for (int i = 0; i < this._vars.length; i++) {
                        ((AbstractFaceletContext) ctx).getTemplateContext().setParameter(names[i], values[i]);
                    }
                }
            }
            // The only mode that can support EL caching in this condition is alwaysRedirect.
            if (!ELExpressionCacheMode.alwaysRecompile.equals(actx.getELExpressionCacheMode())) {
                actx.getTemplateContext().setAllowCacheELExpressions(false);
            }
            ctx.includeFacelet(parent, this._location);
        } finally {
            fcc.endComponentUniqueIdSection();
        }
    } catch (FileNotFoundException e) {
        throw new TagException(this.tag, e.getMessage());
    } finally {
        // make sure we undo our changes
        actx.popClient(this);
        actx.popTemplateContext();
    }
}
Also used : FaceletCompositionContext(org.apache.myfaces.view.facelets.FaceletCompositionContext) FileNotFoundException(java.io.FileNotFoundException) AbstractFaceletContext(org.apache.myfaces.view.facelets.AbstractFaceletContext) FaceletStateValueExpression(org.apache.myfaces.view.facelets.el.FaceletStateValueExpression) TagException(jakarta.faces.view.facelets.TagException) ValueExpression(jakarta.el.ValueExpression) FaceletStateValueExpression(org.apache.myfaces.view.facelets.el.FaceletStateValueExpression) TemplateContextImpl(org.apache.myfaces.view.facelets.impl.TemplateContextImpl) FaceletState(org.apache.myfaces.view.facelets.tag.faces.FaceletState)

Example 3 with FaceletStateValueExpression

use of org.apache.myfaces.view.facelets.el.FaceletStateValueExpression in project myfaces by apache.

the class ParamHandler method apply.

public void apply(FaceletContext ctx, UIComponent parent, String nameStr, ValueExpression valueVE, String uniqueId) throws IOException, FacesException, FaceletException, ELException {
    AbstractFaceletContext actx = ((AbstractFaceletContext) ctx);
    if (ELExpressionCacheMode.alwaysRecompile.equals(actx.getELExpressionCacheMode())) {
        FaceletState faceletState = ComponentSupport.getFaceletState(ctx, parent, true);
        faceletState.putBinding(uniqueId, nameStr, valueVE);
        ValueExpression ve = new FaceletStateValueExpression(uniqueId, nameStr);
        actx.getTemplateContext().setParameter(nameStr, ve);
    } else {
        actx.getTemplateContext().setParameter(nameStr, valueVE);
    }
    if (actx.getTemplateContext().isAllowCacheELExpressions()) {
        if (ELExpressionCacheMode.strict.equals(actx.getELExpressionCacheMode()) || ELExpressionCacheMode.allowCset.equals(actx.getELExpressionCacheMode())) {
            actx.getTemplateContext().setAllowCacheELExpressions(false);
        }
    }
}
Also used : FaceletStateValueExpression(org.apache.myfaces.view.facelets.el.FaceletStateValueExpression) FaceletStateValueExpression(org.apache.myfaces.view.facelets.el.FaceletStateValueExpression) ValueExpression(jakarta.el.ValueExpression) FaceletState(org.apache.myfaces.view.facelets.tag.faces.FaceletState) AbstractFaceletContext(org.apache.myfaces.view.facelets.AbstractFaceletContext)

Aggregations

ValueExpression (jakarta.el.ValueExpression)3 AbstractFaceletContext (org.apache.myfaces.view.facelets.AbstractFaceletContext)3 FaceletStateValueExpression (org.apache.myfaces.view.facelets.el.FaceletStateValueExpression)3 FaceletState (org.apache.myfaces.view.facelets.tag.faces.FaceletState)3 TagException (jakarta.faces.view.facelets.TagException)1 FileNotFoundException (java.io.FileNotFoundException)1 FaceletCompositionContext (org.apache.myfaces.view.facelets.FaceletCompositionContext)1 PageContext (org.apache.myfaces.view.facelets.PageContext)1 TemplateContextImpl (org.apache.myfaces.view.facelets.impl.TemplateContextImpl)1