Example usage for javax.el ValueExpression getExpressionString

List of usage examples for javax.el ValueExpression getExpressionString

Introduction

In this page you can find the example usage for javax.el ValueExpression getExpressionString.

Prototype

public abstract String getExpressionString();

Source Link

Usage

From source file:de.beyondjava.angularFaces.core.ELTools.java

public static String getCoreValueExpression(UIComponent component) {
    ValueExpression valueExpression = component.getValueExpression("value");
    if (null != valueExpression) {
        String v = valueExpression.getExpressionString();
        if (null != v) {
            String model = v.replace("#{", "").replace("}", "");
            return model;
        }//from  w  w w .ja va  2s. c  o m
    }
    return null;
}

From source file:de.beyondjava.angularFaces.core.ELTools.java

/**
 * Yields the type of the variable displayed by a component.
 *
 * @param p_component/*from  w w w  .  j  a  va  2 s . co  m*/
 *            the UIComponent
 * @return
 */
public static Class<?> getType(UIComponent p_component) {
    ValueExpression valueExpression = p_component.getValueExpression("value");
    if (valueExpression != null) {
        return getType(valueExpression.getExpressionString());
    }
    return null;
}

From source file:de.beyondjava.angularFaces.core.ELTools.java

/**
 * Which annotations are given to an object displayed by a JSF component?
 *
 * @param p_component// ww w  .j av  a 2  s.  com
 * @return null if there are no annotations, or if they cannot be accessed
 */
public static Annotation[] readAnnotations(UIComponent p_component) {
    ValueExpression valueExpression = p_component.getValueExpression("value");
    if (valueExpression != null) {
        return readAnnotations(valueExpression.getExpressionString());
    }
    return null;
}

From source file:de.openknowledge.extensions.jsf.model.ModelMethod.java

@Override
public void updateModel(FacesContext context) {
    ValueExpression expression = getValueExpression("value");
    SimpleMethodExpressionParser parser = new SimpleMethodExpressionParser(expression.getExpressionString());
    SimpleMethodExpression methodExpression = parser.parse();
    ExpressionFactory expressionFactory = notNull(context, "context may not be null").getApplication()
            .getExpressionFactory();/*from w w  w .  ja  v a  2s . c o m*/
    ValueExpression baseExpression = expressionFactory.createValueExpression(context.getELContext(),
            "#{" + methodExpression.getBase() + '}', Object.class);
    Object baseValue = baseExpression.getValue(context.getELContext());
    Class<? extends Object> baseType = baseValue.getClass();
    UIInput[] parameterComponents = findComponents(methodExpression);
    Class<?>[] parameterTypes = findParameterTypes(context, methodExpression, expressionFactory,
            parameterComponents);
    Method method = findMethod(baseType, methodExpression.getMethodName(), parameterTypes);
    Object[] parameters = findParameters(context, methodExpression, expressionFactory, parameterComponents,
            parameterTypes);
    try {
        method.invoke(baseValue, parameters);
    } catch (InvocationTargetException e) {
        throw new ELException(e.getTargetException());
    } catch (Exception e) {
        throw new ELException(e);
    }
}

From source file:py.una.pol.karaku.util.ControllerHelper.java

/**
 * @param columns/*from  ww w  .j a va  2  s  . co m*/
 * @param ui
 */
private Column buildColumn(UIComponent ui) {

    ValueExpression expressionHeader = ((HtmlOutputText) ((UIColumn) ui).getHeader())
            .getValueExpression(EL_VALUE_PROPERTY);

    String header = ELParser.getHeaderColumn(expressionHeader.getExpressionString());

    for (UIComponent children : ui.getChildren()) {
        if (children instanceof HtmlOutputText) {
            HtmlOutputText text = (HtmlOutputText) children;
            ValueExpression expression = text.getValueExpression(EL_VALUE_PROPERTY);

            String field = ELParser.getFieldByExpression(expression.getExpressionString());
            return new Column(header, field);
        }
    }
    return null;
}

From source file:com.lassitercg.faces.components.sheet.Sheet.java

/**
 * Gets the rendered col index of the column corresponding to the current
 * sortBy. This is used to keep track of the current sort column in the
 * page./*from  w  w w. ja v a 2 s .co  m*/
 * <p>
 * @return
 */
public int getSortColRenderIndex() {
    ValueExpression veSortBy = getValueExpression(PropertyKeys.sortBy.name());
    if (veSortBy == null)
        return -1;

    final String sortByExp = veSortBy.getExpressionString();
    int colIdx = 0;
    for (Column column : getColumns()) {
        if (!column.isRendered())
            continue;

        ValueExpression veCol = column.getValueExpression(PropertyKeys.sortBy.name());
        if (veCol != null) {
            if (veCol.getExpressionString().equals(sortByExp))
                return colIdx;
        }
        colIdx++;
    }
    return -1;
}

From source file:org.crank.javax.faces.component.MenuRenderer.java

public Object convertSelectManyValue(FacesContext context, UISelectMany uiSelectMany, String[] newValues)
        throws ConverterException {

    // if we have no local value, try to get the valueExpression.
    ValueExpression valueExpression = uiSelectMany.getValueExpression("value");

    Object result = newValues; // default case, set local value
    Class<?> modelType = null;
    boolean throwException = false;

    // If we have a ValueExpression
    if (null != valueExpression) {
        modelType = valueExpression.getType(context.getELContext());
        // Does the valueExpression resolve properly to something with
        // a type?
        if (modelType != null) {
            result = convertSelectManyValuesForModel(context, uiSelectMany, modelType, newValues);
        }/*ww w. j  a va2  s .  c om*/
        // If it could not be converted, as a fall back try the type of
        // the valueExpression's current value covering some edge cases such
        // as where the current value came from a Map.
        if (result == null) {
            Object value = valueExpression.getValue(context.getELContext());
            if (value != null) {
                result = convertSelectManyValuesForModel(context, uiSelectMany, value.getClass(), newValues);
            }
        }
        if (result == null) {
            throwException = true;
        }
    } else {
        // No ValueExpression, just use Object array.
        result = convertSelectManyValues(context, uiSelectMany, Object[].class, newValues);
    }
    if (throwException) {
        StringBuffer values = new StringBuffer();
        if (null != newValues) {
            for (int i = 0; i < newValues.length; i++) {
                if (i == 0) {
                    values.append(newValues[i]);
                } else {
                    values.append(' ').append(newValues[i]);
                }
            }
        }
        Object[] params = { values.toString(), valueExpression.getExpressionString() };
        throw new ConverterException(
                MessageUtils.getExceptionMessage(MessageUtils.CONVERSION_ERROR_MESSAGE_ID, params));
    }

    // At this point, result is ready to be set as the value
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("SelectMany Component  " + uiSelectMany.getId() + " convertedValues " + result);
    }
    return result;

}

From source file:com.flexive.faces.renderer.FxSelectRenderer.java

/**
 * Convert SelectManys value to the correct value classes
 *
 * @param context      faces context/* w ww. ja v a2 s.  c  o  m*/
 * @param uiSelectMany the select many component
 * @param newValues    the new values to convert
 * @return converted values
 * @throws ConverterException on errors
 */
public Object convertSelectManyValue(FacesContext context, UISelectMany uiSelectMany, String[] newValues)
        throws ConverterException {
    // if we have no local value, try to get the valueExpression.
    ValueExpression valueExpression = uiSelectMany.getValueExpression("value");

    Object result = newValues; // default case, set local value
    boolean throwException = false;

    // If we have a ValueExpression
    if (null != valueExpression) {
        Class modelType = valueExpression.getType(context.getELContext());
        // Does the valueExpression resolve properly to something with
        // a type?
        if (modelType != null)
            result = convertSelectManyValuesForModel(context, uiSelectMany, modelType, newValues);
        // If it could not be converted, as a fall back try the type of
        // the valueExpression's current value covering some edge cases such
        // as where the current value came from a Map.
        if (result == null) {
            Object value = valueExpression.getValue(context.getELContext());
            if (value != null)
                result = convertSelectManyValuesForModel(context, uiSelectMany, value.getClass(), newValues);
        }
        if (result == null)
            throwException = true;
    } else {
        // No ValueExpression, just use Object array.
        result = convertSelectManyValues(context, uiSelectMany, Object[].class, newValues);
    }
    if (throwException) {
        StringBuffer values = new StringBuffer();
        if (null != newValues) {
            for (int i = 0; i < newValues.length; i++) {
                if (i == 0)
                    values.append(newValues[i]);
                else
                    values.append(' ').append(newValues[i]);
            }
        }
        throw new ConverterException("Error converting expression [" + valueExpression.getExpressionString()
                + "] of " + String.valueOf(values));
    }
    return result;
}

From source file:org.apache.empire.jsf2.utils.TagEncodingHelper.java

protected boolean hasValueExpression() {
    // Find expression
    if (hasValueExpr != null)
        return hasValueExpr.booleanValue();
    // Find expression
    ValueExpression ve = findValueExpression("value", false);
    if (ve != null) { // check
        if (log.isDebugEnabled()) {
            FacesContext ctx = FacesContext.getCurrentInstance();
            boolean readOnly = ve.isReadOnly(ctx.getELContext());
            if (readOnly)
                log.debug(tag.getClass().getSimpleName() + " for " + getColumnName() + " expression "
                        + ve.getExpressionString() + " is readOnly!");
            else/*from   w  w w.  j  av  a 2 s  . c  o  m*/
                log.debug(tag.getClass().getSimpleName() + " for " + getColumnName() + " expression "
                        + ve.getExpressionString() + " is updateable!");
        }
    }
    /*
    else if (log.isDebugEnabled())
    log.debug(tag.getClass().getSimpleName()+" for "+getColumnName()+" has no value expression!");
    */
    // merken
    hasValueExpr = Boolean.valueOf(ve != null);
    return hasValueExpr.booleanValue();
}

From source file:org.apache.empire.jsf2.utils.TagEncodingHelper.java

@SuppressWarnings("unchecked")
protected ValueExpression findValueExpression(String attribute, boolean allowLiteral) {
    // Check for expression
    ValueExpression ve = tag.getValueExpression(attribute);
    if (ve == null)
        return null;
    // Find expression
    UIComponent parent = tag;//from ww  w. j a  va2  s .  c om
    String expr = ve.getExpressionString();
    while (expr.startsWith(CC_ATTR_EXPR)) {
        // Unwrap
        if (ve instanceof FacesWrapper<?>)
            ve = ((FacesWrapper<ValueExpression>) ve).getWrapped();
        // find parent
        UIComponent valueParent = FacesUtils.getFacesApplication().getFacesImplementation()
                .getValueParentComponent(ve);
        if (valueParent != null) { // use the value parent
            parent = valueParent;
        } else { // find parent
            parent = UIComponent.getCompositeComponentParent(parent);
        }
        if (parent == null)
            return null;
        // check expression
        int end = expr.indexOf('}');
        String attrib = expr.substring(CC_ATTR_EXPR.length(), end);
        if (attrib.indexOf('.') > 0)
            return ve; // do not investigate any further
        // find attribute
        ValueExpression next = parent.getValueExpression(attrib);
        if (next == null) { // allow literal
            if (allowLiteral && (parent.getAttributes().get(attrib) != null))
                return ve;
            // not found
            return null;
        }
        // get new expression String
        ve = next;
        expr = ve.getExpressionString();
    }
    // found
    return ve;
}