ADF

How to pass parameter to method using expression language (EL) in ADF?

Apparently there is not possible to pass a parameter to java method using expression language. But there is a workaround! It is possible to use Map as a return type for method. Here is sample how we play around this requirement by using Map:

Suppose that we need to print text with line break symbols replaced with HTML <br> tags in ADF faces page (this is usually needed if want to display multiline text in readonly mode, entered via inputText field). Here are steps to follow:

  • Create managed bean utilsBean with method getBrFormattedString() in it:

public Map<String, String> getBrFormattedString() {
    return new HashMap<String, String>() {
        @Override
        public String get(Object key) {
            String str = (String)key;
            str = str.replaceAll(“(\r|\n|\r\n)+”, “<br>”);
            return str;
        }
    };
}

  • Create af:outputFormatted component

 <af:outputFormatted value=”#{utilsBean.brFormattedString[‘some sample multiline text’]}”
                                        id=”of1″/>

As you can see, in this example Map is constructed dynamically and finally it acts as a regular method. We can put there any functionality we need. We could use any kind of object instead of String as well.