public boolean isRTL() { if (rtl == null) { String param = context.getExternalContext().getInitParameter(Constants.ContextParams.DIRECTION); if (param == null) { rtl = false; } else { ELContext elContext = context.getELContext(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ValueExpression expression = expressionFactory.createValueExpression(elContext, param, String.class); String expressionValue = (String) expression.getValue(elContext); rtl = (expressionValue == null) ? false : expressionValue.equalsIgnoreCase("rtl"); } } return rtl; } }
protected Object coerceToModelType(FacesContext ctx, Object value, Class itemValueType) { Object newValue; try { ExpressionFactory ef = ctx.getApplication().getExpressionFactory(); newValue = ef.coerceToType(value, itemValueType); } catch (ELException | IllegalArgumentException ele) { newValue = value; } return newValue; }
if (event instanceof MenuActionEvent) { FacesContext facesContext = getFacesContext(); ELContext eLContext = facesContext.getELContext(); MenuActionEvent menuActionEvent = (MenuActionEvent) event; MenuItem menuItem = menuActionEvent.getMenuItem(); MethodExpression noArgExpr = facesContext.getApplication().getExpressionFactory(). createMethodExpression(eLContext, actionExpressionString, String.class, new Class[0]); Object invokeResult = null; MethodExpression argExpr = facesContext.getApplication().getExpressionFactory(). createMethodExpression(eLContext, actionExpressionString, String.class, new Class[]{ActionEvent.class}); MethodExpression argExpr = facesContext.getApplication().getExpressionFactory(). createMethodExpression(eLContext, actionExpressionString, String.class, new Class[]{MenuActionEvent.class});
/** * Construct a default ELContext for a stand-alone environment. * @param factory The ExpressionFactory */ public StandardELContext(ExpressionFactory factory) { this.streamELResolver = factory.getStreamELResolver(); initFunctionMap = factory.getInitFunctionMap(); }
public static Object makeExpressionPayload ( String expr ) throws IllegalArgumentException, IllegalAccessException, Exception { FacesContextImpl fc = new FacesContextImpl((ServletContext) null, (ServletRequest) null, (ServletResponse) null); ELContext elContext = new FacesELContext(new CompositeELResolver(), fc); Reflections.getField(FacesContextImplBase.class, "_elContext").set(fc, elContext); ExpressionFactory expressionFactory = ExpressionFactory.newInstance(); ValueExpression ve1 = expressionFactory.createValueExpression(elContext, expr, Object.class); ValueExpressionMethodExpression e = new ValueExpressionMethodExpression(ve1); ValueExpression ve2 = expressionFactory.createValueExpression(elContext, "${true}", Object.class); ValueExpressionMethodExpression e2 = new ValueExpressionMethodExpression(ve2); return Gadgets.makeMap(e2, e); }
@Override public String getSummary() { FacesContext facesContext = FacesContext.getCurrentInstance(); ValueExpression value = facesContext.getApplication().getExpressionFactory().createValueExpression( facesContext.getELContext(), super.getSummary(), String.class); return (String)value.getValue(facesContext.getELContext()); }
SummaryRow summaryRow = table.getSummaryRow(); HeaderRow headerRow = table.getHeaderRow(); ELContext eLContext = context.getELContext(); ValueExpression groupByVE = null; ValueExpression tableSortByVE = table.getValueExpression(DataTable.PropertyKeys.sortBy.toString()); groupByVE = (table.getSortBy() == null || table.isMultiSort()) ? null : context.getApplication().getExpressionFactory().createValueExpression( eLContext, "#{" + table.getVar() + "." + table.getSortBy() + "}", Object.class);
public static Object convertToType(Object value, Class desiredClass) { if (value == null) return null; try { ExpressionFactory expFactory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory(); return expFactory.coerceToType(value, desiredClass); } catch (Exception e) { String message = "Cannot coerce " + value.getClass().getName() + " to " + desiredClass.getName(); log.log(Level.SEVERE, message, e); throw new FacesException(message, e); } }
protected void setAttributeProperites(final UIComponent component, final String attributeName, final String attribute) { if (attribute != null) { if (Expressions.isEL(attribute)) { FacesContext context = FacesContext.getCurrentInstance(); Application app = context.getApplication(); ExpressionFactory expressionFactory = app.getExpressionFactory(); ValueExpression ve = expressionFactory.createValueExpression(attribute, Object.class); component.setValueExpression(attributeName, ve); } else { component.getAttributes().put(attributeName, attribute); } } } }
ExpressionFactory f = ctx.getApplication() .getExpressionFactory(); expectedReturnType = Util.getTypeFromString(strValue.trim()); } catch (ClassNotFoundException cnfe) { throw new FacesException(methodSignature + " : Unable to load type '" + strValue ELContext elContext = (ELContext) ctx.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY); if (null == elContext) { elContext = ctx.getELContext(); .createMethodExpression(elContext , ve.getExpressionString(), expectedReturnType, expectedParameters); target.getAttributes().put(metadata.getName(), new ContextualCompositeMethodExpression( ve,
getApplication(). getExpressionFactory(). coerceToType(this._disableDefault.getExpressionString(), Boolean.class); throw new FacesException(e); component.setValueExpression("disableDefault", this._disableDefault); getApplication(). getExpressionFactory(). coerceToType(this._for.getExpressionString(), java.lang.String.class); getApplication(). getExpressionFactory(). coerceToType(this._name.getExpressionString(), java.lang.String.class); coerceToType(this._params.getExpressionString(), java.lang.String.class); coerceToType(this._targetId.getExpressionString(), java.lang.String.class); coerceToType(this._type.getExpressionString(), java.lang.String.class);
@Override public void encodeBegin(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); PrimeApplicationContext applicationContext = PrimeApplicationContext.getCurrentInstance(context); ProjectStage projectStage = context.getApplication().getProjectStage(); boolean csvEnabled = applicationContext.getConfig().isClientSideValidationEnabled(); writer.writeAttribute("id", component.getClientId(context), "id"); UIComponent first = component.getFacet("first"); if (first != null) { first.encodeAll(context); ELContext elContext = context.getELContext(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ValueExpression ve = expressionFactory.createValueExpression(elContext, themeParamValue, String.class); theme = (String) ve.getValue(elContext);
public void processAction(ActionEvent evt) throws AbortProcessingException { FacesContext faces = FacesContext.getCurrentInstance(); ELContext el = faces.getELContext(); Object valueObj = this.value.getValue(el); if (valueObj != null) { ExpressionFactory factory = faces.getApplication().getExpressionFactory(); valueObj = factory.coerceToType(valueObj, target.getType(el)); } this.target.setValue(el, valueObj); }
public String resolveDynamicField(ValueExpression expression) { if (expression == null) { return null; } FacesContext context = getFacesContext(); ELContext elContext = context.getELContext(); String expressionString = expression.getExpressionString(); // old syntax compatibility // #{car[column.property]} // new syntax is: // #{column.property} or even a method call if (expressionString.startsWith("#{" + getVar() + "[")) { expressionString = expressionString.substring(expressionString.indexOf("[") + 1, expressionString.indexOf("]")); expressionString = "#{" + expressionString + "}"; ValueExpression dynaVE = context.getApplication() .getExpressionFactory().createValueExpression(elContext, expressionString, String.class); return (String) dynaVE.getValue(elContext); } return (String) expression.getValue(elContext); }
@Override public void onComponentPopulated(FaceletContext ctx, UIComponent c, UIComponent parent) { super.onComponentPopulated(ctx, c, parent); UIComponent defaultTreeNode = c.getFacet(DEFAULT_TREE_NODE_FACET_NAME); if (defaultTreeNode == null) { String var = ((AbstractTree) c).getVar(); if (Strings.isNullOrEmpty(var)) { return; } FacesContext facesContext = ctx.getFacesContext(); Application application = facesContext.getApplication(); AbstractTreeNode treeNode = (AbstractTreeNode) application.createComponent(AbstractTreeNode.COMPONENT_TYPE); treeNode.setId(DEFAULT_TREE_NODE_ID); c.getFacets().put(DEFAULT_TREE_NODE_FACET_NAME, treeNode); UIComponent text = application.createComponent(HtmlOutputText.COMPONENT_TYPE); text.setValueExpression( "value", application.getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{" + var + "}", String.class)); treeNode.getChildren().add(text); } } }
/** * {@inheritDoc} */ @Override public String resolve(String expression) { ValueExpression expr = expressionFactory.createValueExpression(elContext, expression, String.class); return String.valueOf(expr.getValue(elContext)); } }
private void applyValidatorMethodExpressionEL(FacesContext context, ELContext elContext, UIComponent topLevelComponent, String attributeName, String attributeExpressionString, ValueExpression attributeNameValueExpression, boolean ccAttrMeRedirection) { // target is EditableValueHolder MethodExpression methodExpression = reWrapMethodExpression(context.getApplication().getExpressionFactory(). createMethodExpression(elContext, attributeExpressionString, Void.TYPE, VALIDATOR_SIGNATURE), attributeNameValueExpression); //Store the method expression to the topLevelComponent to allow reference it through EL if (!ccAttrMeRedirection) { //Replace it with a method expression topLevelComponent.getAttributes().put(attributeName, methodExpression); } // Otherwise keep the current ValueExpression, // because it will be used chain other value expressions }
break; } else { expressionString = expression.getExpressionString(); result = StringUtils.isEmpty(expressionString); parent.getAttributes().put(name.getValue(), result); } else if ("isSet".equals(mode.getValue())) { boolean result = true; break; } else { expressionString = expression.getExpressionString(); result = StringUtils.isNotEmpty(expressionString); final MethodExpression action = new TagMethodExpression(value, expressionFactory.createMethodExpression( faceletContext, expressionString, String.class, ComponentUtils.ACTION_ARGS)); ((ActionSource2) parent).setActionExpression(action); final ExpressionFactory expressionFactory = faceletContext.getExpressionFactory(); final MethodExpression actionListener = new TagMethodExpression(value, expressionFactory.createMethodExpression( faceletContext, expressionString, null, ComponentUtils.ACTION_LISTENER_ARGS)); ((ActionSource) parent).addActionListener(new MethodExpressionActionListener(actionListener)); throw new FacesException("Type " + mode + " not supported");
public Expression createExpression(String expression) { ValueExpression valueExpression = expressionFactory.createValueExpression(parsingElContext, expression.trim(), Object.class); return new JuelExpression(valueExpression, expression); }
private void processCustomArgListener(FacesContext context, ELContext elContext, AjaxBehaviorEvent event) throws AbortProcessingException { if (listenerWithCustomArg == null) { MethodExpression argListener = context.getApplication().getExpressionFactory(). createMethodExpression(elContext, listener.getExpressionString(), Void.class, new Class[]{event.getClass()}); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Try to invoke customListener: " + argListener.getExpressionString()); } argListener.invoke(elContext, new Object[]{event}); } else { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Try to invoke customListener: " + listenerWithCustomArg.getExpressionString()); } listenerWithCustomArg.invoke(elContext, new Object[]{event}); } } }