public <T> T eval(String attr, T unspecifiedValue) { if (literals.containsKey(attr)) { Object val = literals.get(attr); if (val == null) { return unspecifiedValue; } else { return (T) val; } } ValueExpression ve = bindings.get(attr); if (ve != null) { FacesContext facesContext = FacesContext.getCurrentInstance(); ELContext elContext = facesContext.getELContext(); return (T) ve.getValue(elContext); } return unspecifiedValue; }
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; } }
public Integer getSize() { if (size != null) { return size; } ValueExpression ve = getValueExpression("size"); if (ve != null) { return (Integer) ve.getValue(getFacesContext().getELContext()); } return null; }
public int compare(Object obj1, Object obj2) { try { FacesContext context = FacesContext.getCurrentInstance(); Object value1 = sortBy.getValue(context.getELContext()); context.getExternalContext().getRequestMap().put(var, obj2); Object value2 = sortBy.getValue(context.getELContext()); result = (Integer) sortFunction.invoke(context.getELContext(), new Object[]{value1, value2}); throw new FacesException(e);
public void setLiteralValue(String name, ValueExpression expression) { assert (expression.isLiteralText()); ELContext context = getFacesContext().getELContext(); try { setLiteralAttribute(name, expression.getValue(context)); } catch (ELException elem) { throw new FacesException(elem); } }
protected Converter findImplicitConverter(FacesContext context, UIComponent component) { ValueExpression ve = component.getValueExpression("value"); if (ve != null) { Class<?> valueType = ve.getType(context.getELContext()); if (valueType != null) { if (valueType.isArray()) { valueType = valueType.getComponentType(); } return context.getApplication().createConverter(valueType); } } return null; }
public static final String getValue(FacesContext context, UICalendar calendar, Object value, String pattern) { //first ask the converter if (calendar.getConverter() != null) { return calendar.getConverter().getAsString(context, calendar, value); } else if (value instanceof String) { return (String) value; } //Use built-in converter else if (value instanceof Date) { SimpleDateFormat format = new SimpleDateFormat(pattern, calendar.calculateLocale(context)); format.setTimeZone(calculateTimeZone(calendar.getTimeZone())); return format.format((Date) value); } else { //Delegate to global defined converter (e.g. joda or java8) ValueExpression ve = calendar.getValueExpression("value"); if (ve != null) { Class type = ve.getType(context.getELContext()); if (type != null && type != Object.class && type != Date.class) { Converter converter = context.getApplication().createConverter(type); if (converter != null) { return converter.getAsString(context, calendar, value); } } } throw new FacesException("Value could be either String or java.util.Date"); } }
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]); 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});
@Override public void processAjaxBehavior(AjaxBehaviorEvent event) throws AbortProcessingException { FacesContext context = FacesContext.getCurrentInstance(); final ELContext elContext = context.getELContext(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Try to invoke listener: " + listener.getExpressionString()); } try { listener.invoke(elContext, new Object[]{}); } catch (MethodNotFoundException | IllegalArgumentException | ArrayIndexOutOfBoundsException mnfe) { processArgListener(context, elContext, event); } }
void decodeMultipleSelection(FacesContext context, DataTable table, String selection) { ValueExpression selectionByVE = table.getValueExpression(DataTable.PropertyKeys.selection.toString()); Class<?> clazz = selectionByVE == null ? null : selectionByVE.getType(context.getELContext()); boolean isArray = clazz == null ? false : clazz.isArray(); throw new FacesException("Multiple selection reference must be an Array or a List for datatable " + table.getClientId());
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 processAction(ActionEvent actionEvent) throws AbortProcessingException { if (value == null) { throw new AbortProcessingException("Value has not been set"); } ELContext elContext = FacesContext.getCurrentInstance().getELContext(); Object val = value.getValue(elContext); if (addTo != null) { Collection collection = (Collection) addTo.getValue(elContext); Object uniqueValue = (unique != null) ? unique.getValue(elContext) : null; boolean checkUniqueness = (uniqueValue == null) ? true : Boolean.parseBoolean(uniqueValue.toString()); if (checkUniqueness) { if (!collection.contains(val)) { collection.add(val); } } else { collection.add(val); } } else if (removeFrom != null) { Collection collection = (Collection) removeFrom.getValue(elContext); collection.remove(val); } else { throw new IllegalArgumentException("Specify either addTo or removeFrom as collection reference"); } }
public int compare(Object obj1, Object obj2) { try { FacesContext context = FacesContext.getCurrentInstance(); Object value1 = sortBy.getValue(context.getELContext()); context.getExternalContext().getRequestMap().put(var, ((TreeNode) obj2).getData()); Object value2 = sortBy.getValue(context.getELContext()); result = (Integer) sortFunction.invoke(context.getELContext(), new Object[]{value1, value2}); throw new FacesException(e);
public Integer getEnd() { if (end != null) { return end; } ValueExpression ve = getValueExpression("end"); if (ve != null) { return (Integer) ve.getValue(getFacesContext().getELContext()); } return null; }
public void setLiteralValue(String name, ValueExpression expression) { assert (expression.isLiteralText()); ELContext context = getFacesContext().getELContext(); try { setLiteralAttribute(name, expression.getValue(context)); } catch (ELException elem) { throw new FacesException(elem); } }
Resource resource = context.getApplication().getResourceHandler().createResource( "dynamiccontent.properties", "primefaces", streamedContent.getContentType()); String resourcePath = resource.getRequestPath(); context.getELContext(), component.getValueExpression("value"));
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]); 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});
public void initPreselection() { ValueExpression ve = getValueExpression(UITree.PropertyKeys.selection.toString()); if (ve != null) { if (preselection != null) { String selectionMode = getSelectionMode(); if (selectionMode != null) { if (selectionMode.equals("single")) { if (!preselection.isEmpty()) { ve.setValue(FacesContext.getCurrentInstance().getELContext(), preselection.get(0)); } } else { ve.setValue(FacesContext.getCurrentInstance().getELContext(), preselection.toArray(new TreeNode[0])); } preselection = null; } } else { ve.setValue(FacesContext.getCurrentInstance().getELContext(), null); } } }
ValueExpression valueExpression = inputNumber.getValueExpression("value"); if (valueExpression != null) { Class<?> type = valueExpression.getType(context.getELContext()); if (type != null && type.isPrimitive() && !LangUtils.isValueBlank(inputNumber.getMinValue())) { throw new FacesException("Invalid number", ex);
ELContext eLContext = context.getELContext(); ValueExpression ve = context.getApplication().getExpressionFactory().createValueExpression( context.getELContext(), dynamicContentEL, StreamedContent.class); streamedContent = (StreamedContent) ve.getValue(eLContext);