• ADF
    February 13, 2013

Evaluating EL expressions the Java way in ADF Mobile

Guest Author

Expression language (EL) is used all over the place in JSF and ADF Faces, since it enables the presentation layer (JSPX / JSF pages) to communicate with the application logic (managed beans). ADF Mobile uses exactly the same pattern with its AMX technology, which delivers a JSF-like development experience to build an HTML5-based user interface. The key point here is JSF-like, since internal implementation details may vary between the two.

It is sometimes useful to evaluate EL expressions in the managed bean itself rather than delegate the task to the page. Typically, in ADF web applications, this is done like this:

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.context.FacesContext;

public static Object resolveExpression(String expression) {
    FacesContext facesContext = getFacesContext();
    Application app = facesContext.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = facesContext.getELContext();
    ValueExpression valueExp = 
        elFactory.createValueExpression(elContext, expression,
    return valueExp.getValue(elContext);

This code snippet will not work as is in ADF Mobile, since there are no FacesContext or Application objects.

Sure, you could retrieve the expression factory by doing this:

import oracle.adfmf.framework.api.AdfmfJavaUtilities;
import oracle.adfmf.framework.model.AdfELContext;

AdfELContext ctx = AdfmfJavaUtilities.getAdfELContext();

ExpressionFactory factory = ctx.getExpressionFactory();

But ADF Mobile provides helper methods that will retrieve the context and expression factory behind the scenes for you.  For example, if you want to evaluate in Java an EL expression that retrieves a message (key ERROR_MSG) from a ressource bundle (declared as viewcontrollerBundle):

import oracle.adfmf.framework.api.Model
import oracle.adfmf.framework.contract.adf.NameValuePair;

Model mod = new Model();

NameValuePair[] result = null;

result = mod.getValue(new String[] { "#{viewcontrollerBundle.ERROR_MSG}" });
String value = (String)(result[0].getValue());

The code above will work out of the box if the AMX pages referencing the bean declare the bundle. If that's not the case, you must simply add this line of code before calling getValue on the Model object:

mod.loadBundle(<resource_bundle_basename>, <var_attribute>);

How would you use this technique in a real-world scenario? Suppose, for example, that you need to bind a single amx:outputText to several different values in a resource bundle, the specific text string to be displayed being determined at runtime. In ADF web applications, you could use nested EL to achieve your goal:


This doesn't work in ADF Mobile currently. Thus, you can sidestep the issue by creating a method binding on a bean and reference it in the page. 

Join the discussion

Comments ( 2 )
  • guest Monday, March 25, 2013


    How can I provide EL inside an EL expression ?

    something like this ... ? #{bean.someList[#{bean.someInt}].name}

    When I give an expression like the above, the page itself is not loading?

    Thanks !

  • Blueberry Coder Monday, March 25, 2013

    Unfortunately, this is not possible in the current version. You will have to write Java code in order to get an equivalent result, using the techniques described in the blog post.

    I will check with the product team if they have planned to support nested expressions in future releases.

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.