Example usage for javax.el ExpressionFactory createMethodExpression

List of usage examples for javax.el ExpressionFactory createMethodExpression

Introduction

In this page you can find the example usage for javax.el ExpressionFactory createMethodExpression.

Prototype

public abstract MethodExpression createMethodExpression(ELContext context, String expression,
        Class<?> expectedReturnType, Class<?>[] expectedParamTypes);

Source Link

Document

Create a new method expression instance.

Usage

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

public MethodExpression makeMethodExpression(final String expression, final Class<?> expectedReturnType,
        final Class<?>... expectedParamTypes) {

    MethodExpression methodExpression = null;
    try {//from   www.j  av  a2s.co m
        FacesContext fc = getContext();
        ExpressionFactory factory = getExpressionFactory();
        methodExpression = factory.createMethodExpression(fc.getELContext(), expression, expectedReturnType,
                expectedParamTypes);

        return methodExpression;
    } catch (Exception e) {
        throw new FacesException("Method expression '" + expression + "' no se puede crear.", e);
    }
}

From source file:com.googlecode.jsfFlex.taglib.AbstractFlexUIInputTagBase.java

protected void setProperties(UIComponent component) {
    super.setProperties(component);

    FacesContext context = FacesContext.getCurrentInstance();
    ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();

    setBooleanProperty(context, component, IMMEDIATE_ATTR, _immediate);
    setBooleanProperty(context, component, REQUIRED_ATTR, _required);

    if (_validator != null) {
        if (!(component instanceof EditableValueHolder)) {
            throw new IllegalArgumentException(
                    "Component " + component.getClientId(context) + " is no EditableValueHolder");
        }//from ww w.ja va  2 s.com

        MethodExpression me = expressionFactory.createMethodExpression(context.getELContext(), _validator,
                Object.class, VALIDATOR_ARGS);
        if (me != null) {
            ((EditableValueHolder) component).addValidator(new MethodExpressionValidator(me));
        } else {
            _log.error("Component " + component.getClientId(context) + " has invalid validation expression "
                    + _validator);
        }
    }

    if (_valueChangeListener != null) {
        if (!(component instanceof EditableValueHolder)) {
            throw new IllegalArgumentException(
                    "Component " + component.getClientId(context) + " is no EditableValueHolder");
        }

        MethodExpression me = expressionFactory.createMethodExpression(context.getELContext(),
                _valueChangeListener, Object.class, VALUE_LISTENER_ARGS);
        if (me != null) {
            ((EditableValueHolder) component)
                    .addValueChangeListener(new MethodExpressionValueChangeListener(me));
        } else {
            _log.error("Component " + component.getClientId(context)
                    + " has invalid valueChangedListener expression " + _valueChangeListener);
        }
    }

}

From source file:com.egt.core.aplicacion.web.GestorPaginaActualizacionConArbol.java

protected MethodExpression getExpresionAccionEscogerNodo() {
    if (expresionAccionZum == null) {
        ExpressionFactory factory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
        ELContext context = FacesContext.getCurrentInstance().getELContext();
        String expression = "#{" + this.getPaginaAbstracta().getClass().getSimpleName() + ".accionEscogerNodo}";
        expresionAccionZum = factory.createMethodExpression(context, expression, String.class, new Class[] {});
        this.track("getExpresionAccionEscogerNodo", expression);
    }/*from   ww w  .java 2 s. com*/
    return expresionAccionZum;
}

From source file:ips1ap101.lib.core.web.app.GestorPaginaActualizacionConArbol.java

protected MethodExpression getExpresionAccionEscogerNodo() {
    if (expresionAccionZum == null) {
        ExpressionFactory factory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
        ELContext context = FacesContext.getCurrentInstance().getELContext();
        String expression = "#{" + getPaginaBasica().getManagedBeanName() + ".accionEscogerNodo}";
        expresionAccionZum = factory.createMethodExpression(context, expression, String.class, new Class[] {});
        track("getExpresionAccionEscogerNodo", expression);
    }//from ww w .j a  v a 2 s .  c  o  m
    return expresionAccionZum;
}

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

/**
 * Retorna una EL expression correspondiente a un metodo.
 * /* w w  w  .  j a v a2 s . c  om*/
 * @param valueExpression
 *            cadena que representa la expresion.
 * @param expectedReturnType
 *            clase del tipo que se espera que retorna la expresion
 * @param expectedParamTypes
 *            clase de los parametros esperados que reciba el metodo
 * 
 * @return {@link MethodExpression} correspondiente
 */
public MethodExpression createMethodExpression(final String valueExpression, final Class<?> expectedReturnType,
        final Class<?>... expectedParamTypes) {

    MethodExpression methodExpression = null;
    try {
        FacesContext fc = getContext();
        ExpressionFactory factory = fc.getApplication().getExpressionFactory();
        methodExpression = factory.createMethodExpression(fc.getELContext(), valueExpression,
                expectedReturnType, expectedParamTypes);
    } catch (Exception e) {
        throw new FacesException("Method expression '" + valueExpression + "' could not be created.", e);
    }

    return methodExpression;
}

From source file:eu.planets_project.tb.gui.backing.ExperimentBean.java

/**
 * Creates the JSF Elements to render a given fileRef as CommandLink within the given UIComponent
 * @param panel/*from  w  w w  .  j  ava  2s  .c om*/
 * @param fileRef
 * @param key
 */
public void helperCreateRemoveFileElement(UIComponent panel, String fileRef, String key) {
    log.info("Looking for fileRef: " + fileRef + " w/ key: " + key);
    try {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        DataHandler dh = new DataHandlerImpl();
        //file ref
        HtmlOutputText outputText = (HtmlOutputText) facesContext.getApplication()
                .createComponent(HtmlOutputText.COMPONENT_TYPE);
        DigitalObjectRefBean dobr = dh.get(fileRef);
        outputText.setValue(" " + dobr.getName());
        outputText.setId("fileName" + key);
        //file name
        HtmlOutputLink link_src = (HtmlOutputLink) facesContext.getApplication()
                .createComponent(HtmlOutputLink.COMPONENT_TYPE);
        link_src.setId("fileRef" + key);
        URI URIFileRef = dobr.getDownloadUri();
        link_src.setValue(URIFileRef);
        link_src.setTarget("_new");

        //CommandLink+Icon allowing to delete this entry
        HtmlCommandLink link_remove = (HtmlCommandLink) facesContext.getApplication()
                .createComponent(HtmlCommandLink.COMPONENT_TYPE);
        //set the ActionMethod to the method: "commandRemoveAddedFileRef(ActionEvent e)"
        Class<?>[] parms = new Class<?>[] { ActionEvent.class };
        ExpressionFactory ef = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
        MethodExpression mb = ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(),
                "#{NewExp_Controller.commandRemoveAddedFileRef}", null, parms);
        link_remove.setActionExpression(mb);
        link_remove.setId("removeLink" + key);
        link_remove.setTitle("Remove this file."); // FIXME Localise this!
        //send along an helper attribute to identify which component triggered the event
        link_remove.getAttributes().put("IDint", key);
        HtmlGraphicImage image = (HtmlGraphicImage) facesContext.getApplication()
                .createComponent(HtmlGraphicImage.COMPONENT_TYPE);
        image.setUrl("../graphics/user_trash.png");
        image.setAlt("delete-image");
        image.setId("graphicRemove" + key);
        link_remove.getChildren().add(image);

        //add all three components
        panel.getChildren().add(link_remove);
        link_src.getChildren().add(outputText);
        panel.getChildren().add(link_src);

    } catch (Exception e) {
        log.error("error building components for file removal " + e.toString());
    }
}

From source file:org.ajax4jsf.bean.TemplateBean.java

/**
 * Invokes reset method of appropriate backing bean
 * //from  ww w .  ja v  a 2s  .  c  om
 * @param actionEvent
 */
public void reset(ActionEvent actionEvent) {
    FacesContext context = FacesContext.getCurrentInstance();
    if (context != null) {
        if (methodName != null && methodName.trim().length() > 0 && !"null".equals(methodName)) {
            ExpressionFactory factory = context.getApplication().getExpressionFactory();
            if (factory != null) {
                MethodExpression methodExpression = factory.createMethodExpression(context.getELContext(),
                        methodName, Void.class, new Class[] {});
                methodExpression.invoke(context.getELContext(), new Object[] {});
            }
        }
    }

}

From source file:org.nuxeo.ecm.platform.ui.web.binding.MetaMethodExpression.java

@Override
public Object invoke(ELContext context, Object[] params) {
    Object res = null;// w w w.jav a  2 s  .c o m
    if (originalMethodExpression != null) {
        res = originalMethodExpression.invoke(context, params);
        if (res instanceof String) {
            String expression = (String) res;
            if (ComponentTagUtils.isValueReference(expression)) {
                FacesContext faces = FacesContext.getCurrentInstance();
                Application app = faces.getApplication();
                ExpressionFactory factory = app.getExpressionFactory();
                MethodExpression newMeth = factory.createMethodExpression(context, expression, Object.class,
                        new Class[0]);
                try {
                    res = newMeth.invoke(context, null);
                } catch (Throwable t) {
                    if (t instanceof InvocationTargetException) {
                        // respect the javadoc contract of the overridden
                        // method
                        throw new ELException(t.getCause());
                    } else {
                        throw new ELException(t);
                    }
                }
            } else {
                res = expression;
            }
        }
    }
    return res;
}

From source file:org.nuxeo.ecm.platform.ui.web.rest.RestfulPhaseListener.java

/**
 * Hack trigger of a Seam component that will trigger reset of most Seam components caches, only if dev mode is
 * enabled/*from ww  w. j  av a2s  .c o  m*/
 * <p>
 * This is handled here to be done very early, before response is constructed.
 *
 * @since 5.6
 * @see Framework#isDevModeSet()
 */
protected void resetHotReloadContext(FacesContext facesContext) {
    if (Framework.isDevModeSet()) {
        try {
            ExpressionFactory ef = facesContext.getApplication().getExpressionFactory();
            ELContext context = facesContext.getELContext();
            String actionBinding = SEAM_HOTRELOAD_TRIGGER_ACTION;
            MethodExpression action = ef.createMethodExpression(context, actionBinding, String.class,
                    new Class[] { DocumentView.class });
            action.invoke(context, new Object[0]);
        } catch (ELException | NullPointerException e) {
            String msg = "Error while trying to flush seam context after a reload, executing method expression '"
                    + SEAM_HOTRELOAD_TRIGGER_ACTION + "'";
            log.error(msg, e);
        }
    }
}

From source file:org.nuxeo.ecm.platform.ui.web.rest.services.URLPolicyServiceImpl.java

@Override
public String navigate(FacesContext facesContext) {
    HttpServletRequest httpRequest = (HttpServletRequest) facesContext.getExternalContext().getRequest();

    URLPatternDescriptor pattern = getURLPatternDescriptor(httpRequest);
    if (pattern == null) {
        return null;
    }/*ww  w  .j a  v  a 2s. c o  m*/

    DocumentView docView = getDocumentViewFromRequest(pattern.getName(), httpRequest);
    ExpressionFactory ef = facesContext.getApplication().getExpressionFactory();
    ELContext context = facesContext.getELContext();
    String actionBinding = pattern.getActionBinding();

    if (actionBinding != null && !"".equals(actionBinding)
            && httpRequest.getAttribute(URLPolicyService.DISABLE_ACTION_BINDING_KEY) == null) {
        MethodExpression action = ef.createMethodExpression(context, actionBinding, String.class,
                new Class[] { DocumentView.class });
        return (String) action.invoke(context, new Object[] { docView });
    }
    return null;
}