Follow by Email

Monday, 25 August 2014

Using HashMap in EL expression to set component properties in Oracle ADF

Basic requirement while using EL on pages in ADF, we use bean variables, binding attributes, iterators in expression to check conditions , to set properties for components as Enable-Disable, Visible, inline style etc.
in the same way we can use collections (Array, HashMap) in expression, i know it is pretty simple but have seen many thread in OTN asking how to use HashMap in expression

So here i am taking a very simple example

I have 5 input text on page and i have to enable-disable some fields based on it's id value, there is two buttons on page

as you can see on click of first button , input field 1,3 and 5 should be disabled and on click of second button af:inputText 2 and 4 should be disabled
so for this purpose i have used a HashMap in managed bean

    private HashMap fieldVal = new HashMap();

    public void setFieldVal(HashMap fieldVal) {
        this.fieldVal = fieldVal;

    public HashMap getFieldVal() {
        return fieldVal;

values in HashMap are populated using id value of inputTexts on page as key, this id will be passed as parameter in HashMap in expression
see how expression used in disabled property of inputText-

in same way expression for all inputText is set

<af:panelFormLayout id="pfl1" partialTriggers="b1 b2">
                    <af:inputText label="Label 1" id="it1" disabled="#{EnableDisableBean.fieldVal['it1']}"/>
                    <af:inputText label="Label 2" id="it2"
                    <af:inputText label="Label 3" id="it3"
                    <af:inputText label="Label 4" id="it4"
                    <af:inputText label="Label 5" id="it5" autoSubmit="true"

now see code on buttons, simply setting values against key

    /**Method to disable inputText (1,3,5) on basis of id value
     * @param actionEvent
    public void disable135Action(ActionEvent actionEvent) {
        fieldVal.put("it1", true);
        fieldVal.put("it2", false);
        fieldVal.put("it3", true);
        fieldVal.put("it4", false);
        fieldVal.put("it5", true);


    /**Method to disable inputText (2,4) on basis of id value
     * @param actionEvent
    public void disable24Action(ActionEvent actionEvent) {
        fieldVal.put("it1", false);
        fieldVal.put("it2", true);
        fieldVal.put("it3", false);
        fieldVal.put("it4", true);
        fieldVal.put("it5", false);

Run Application and see what is on page
On Click of First Button

On Click of Second Button

Happy learning :)

No comments :

Post a Comment