Since I work often with the EL expression language in ADF/JSF applications, I have a favorite helper class that I like to use called EL (I've included the source at the end of this post). This EL class is designed to let me write terse, one-line EL-manipulation code in JSF backing beans like:
MyAppModule m = (MyAppModule)EL.get("#{data.MyAppModuleDataControl.dataProvider}"); m.someInterestingCustomMethod(x,y,z);
or
String postCode = EL.getAsString("#{bindings.PostCode.inputValue}");
or
EL.set("#{bindings.PostCode.inputValue}","#{param.SomeParamName}");
The mystery that has been haunting me for months has been that whenever I try to use my class named "EL" in a JSF backing bean, JDeveloper 10.1.3 refuses to offer me its handy, automatic Java import "insight" to save me from having to remember or type the full package name of the EL class in my Java imports section. I tried to narrow down the problem and I noticed that if I named my helper class another name like MyELHelper, the import insight worked as expected. So, I filed a bug reporting that for some strange reason our import insight was broken for a class named EL. Today a developer on our core IDE team updated my bug with the explanation of the behavior. The mystery had nothing to do with exactly the name EL, but instead with the fact that its name is only two characters long. By default, the JDeveloper import insight mechanism waits until the developer has typed at least three characters of the class name before suggesting import assistance. This is to avoid a large number of irrelevant suggestions. For example, if you typed a letter "a" and JDeveloper were to immediately propose a list of possible classes that begin with the letter "a" which you might be intending to import, you would have a long list of classes are are not what you want. By waiting for at least three letters to be typed, it makes JDeveloper's search through all possible classes more selective and performant.
However, if you want to enable the import insight for classes of any length (including classes with 1-letter or 2-letter names), you can:
- Shutdown JDeveloper 10.1.3 for a moment if it's currently running
- Edit the file jdev/system/oracle.jdeveloper.<version>/preferences.xml
- Set the ignoreShortClasses preference property value to false as shown in the XML snippet below.
: <Item> <Key>JavaImportOptions</Key> <Value class="oracle.jdevimpl.java.imports.JavaImportOptions"> : <ignoreShortClasses>false</ignoreShortClasses> :
</Value> </Item>
When you next restart JDeveloper, the import insight will work for your two-letter classnames like EL.
The source of the EL helper class, in case you might be interested, looks like this:
package example.view.util; import javax.faces.context.FacesContext; import javax.faces.el.ValueBinding; public class EL { public static boolean test(String booleanExpr) { return Boolean.TRUE.equals(get(booleanExpr)); } public static String getAsStringWithDefault(String expr, String defaultExpr) { return (String)getWithDefault(expr, defaultExpr); } public static String getAsString(String expr) { return (String)get(expr); } public static Object get(String expr) { FacesContext fc = FacesContext.getCurrentInstance(); ValueBinding vb = fc.getApplication().createValueBinding(expr); return vb.getValue(fc); } public static Object getWithDefault(String expr, String defaultExpr) { Object exprVal = get(expr); return exprVal != null ? exprVal : get(defaultExpr); } public static void set(String expr, String value) { Object valToSet = value; if (isELExpr(value)) { valToSet = get(value); } set(expr, valToSet); } public static void set(String expr, Object value) { FacesContext fc = FacesContext.getCurrentInstance(); ValueBinding vb = fc.getApplication().createValueBinding(expr); vb.setValue(fc, value); } private static boolean isELExpr(Object o) { if (o instanceof String) { String str = (String)o; str.trim(); return str.startsWith("#{") && str.endsWith("}"); } return false; } }
2:51:18 PM
|