Example usage for javax.el ValueExpression setValue

List of usage examples for javax.el ValueExpression setValue

Introduction

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

Prototype

public abstract void setValue(ELContext context, Object value);

Source Link

Usage

From source file:org.apache.myfaces.component.html.ext.AbstractHtmlDataTable.java

public void setForceIdIndexFormula(String forceIdIndexFormula) {
    getStateHelper().put(PropertyKeys.forceIdIndexFormula, forceIdIndexFormula);
    ValueExpression vb = getValueExpression("forceIdIndexFormula");
    if (vb != null) {
        vb.setValue(getFacesContext().getELContext(), forceIdIndexFormula);
        getStateHelper().put(PropertyKeys.forceIdIndexFormula, null);
    }//w ww  .  j a v a  2s  .  co m
}

From source file:org.apache.myfaces.component.html.ext.AbstractHtmlDataTable.java

public void restoreState(FacesContext context, Object state) {
    if (state == null) {
        return;// w ww .j  a va  2 s. c o m
    }

    Object[] values = (Object[]) state;
    super.restoreState(context, values[0]);
    if (isPreserveDataModel()) {
        _preservedDataModel = (_SerializableDataModel) restoreAttachedState(context, values[1]);
    } else {
        _preservedDataModel = null;
    }

    if (isPreserveSort()) {
        String sortColumn = (String) values[2];
        Boolean sortAscending = (Boolean) values[3];
        if (sortColumn != null && sortAscending != null) {
            ValueExpression vb = getValueExpression("sortColumn");
            if (vb != null && !vb.isReadOnly(context.getELContext())) {
                vb.setValue(context.getELContext(), sortColumn);
            }

            vb = getValueExpression("sortAscending");
            if (vb != null && !vb.isReadOnly(context.getELContext())) {
                vb.setValue(context.getELContext(), sortAscending);
            }
        }
    }

    //_expandedNodes = (Map) values[4];
}

From source file:org.apache.myfaces.component.html.ext.AbstractHtmlDataTable.java

private void updateModelFromPreservedDataModel(FacesContext context) {
    ValueExpression vb = getValueExpression("value");
    if (vb != null && !vb.isReadOnly(context.getELContext())) {
        DataModel qdm = getDataModel();/*w ww . ja v  a  2  s.c o  m*/
        if (qdm instanceof _SerializableDataModel) {
            _SerializableDataModel dm = (_SerializableDataModel) qdm;
            Class type = (getValueType() == null) ? vb.getType(context.getELContext())
                    : ClassUtils.simpleClassForName(getValueType());
            Class dmType = dm.getClass();
            if (DataModel.class.isAssignableFrom(type)) {
                vb.setValue(context.getELContext(), dm);
            } else if (List.class.isAssignableFrom(type)
                    || _SerializableListDataModel.class.isAssignableFrom(dmType)) {
                vb.setValue(context.getELContext(), dm.getWrappedData());
            } else if (OBJECT_ARRAY_CLASS.isAssignableFrom(type)) {
                List lst = (List) dm.getWrappedData();
                vb.setValue(context.getELContext(), lst.toArray(new Object[lst.size()]));
            } else if (ResultSet.class.isAssignableFrom(type)) {
                throw new UnsupportedOperationException(
                        this.getClass().getName() + " UnsupportedOperationException");
            } else {
                //Assume scalar data model
                List lst = (List) dm.getWrappedData();
                if (lst != null && lst.size() > 0) {
                    vb.setValue(context.getELContext(), lst.get(0));
                } else {
                    vb.setValue(context.getELContext(), null);
                }
            }
        }
    }
    _preservedDataModel = null;
}

From source file:org.apache.myfaces.application.ApplicationImpl.java

@Override
public final UIComponent createComponent(final ValueExpression componentExpression,
        final FacesContext facesContext, final String componentType)
        throws FacesException, NullPointerException {

    /*/*from  www . j a  va 2  s . co m*/
     * Before the component instance is returned, it must be inspected for the presence of a ListenerFor (or
     * ListenersFor) or ResourceDependency (or ResourceDependencies) annotation. If any of these annotations are
     * present, the action listed in ListenerFor or ResourceDependency must be taken on the component, 
     * before it is
     * returned from this method. This variant of createComponent must not inspect the Renderer for the 
     * component to
     * be returned for any of the afore mentioned annotations. Such inspection is the province of
     */

    checkNull(componentExpression, "componentExpression");
    checkNull(facesContext, "facesContext");
    checkNull(componentType, "componentType");

    ELContext elContext = facesContext.getELContext();

    try {
        Object retVal = componentExpression.getValue(elContext);

        UIComponent createdComponent;

        if (retVal instanceof UIComponent) {
            createdComponent = (UIComponent) retVal;
            _handleAnnotations(facesContext, createdComponent, createdComponent);
        } else {
            createdComponent = createComponent(facesContext, componentType);
            componentExpression.setValue(elContext, createdComponent);
        }

        return createdComponent;
    } catch (FacesException e) {
        throw e;
    } catch (Exception e) {
        throw new FacesException(e);
    }
}