Tuesday, May 6, 2014

Populate checkbox in adf application using the data binding

Populate  checkbox in adf application using the data binding

I was finding using checkbox in adf application using the data binding a bit tricky.
For eg : suppose a field from database name IsApp has value populated as 0/1. When using the binding to populate it value by using the following code:

<af:selectBooleanCheckbox value="#{bindings.IsApp.inputValue == 1}"
                                            label="Is Application" >
</af:selectBooleanCheckbox>

It was successful but i found that it would bring up a checkbox as readonly on the page. while inspecting the element, i found that the source code behind the element as:
<div id="j_id_id5:j_id_id14:0:j_id_id16__xc_c" class="x2e"><img src="/ComplexInsert-ViewController-context-root/adf/images/checkrn.gif" width="12" height="12" border="0" title="Read only Checkbox Not Checked" alt="Read only Checkbox Not Checked"></div>

So, i advise to do following:
1. Create a transient attribute in VO:



Make sure to use the type as boolean and select the updateable property as Always

2. Create a rowImpl class corresponding to the VO if not already created

3. Configure the getter setter of the transient attribute as mentioned below:

    /**
     * Gets the attribute value for the calculated attribute IsAppBoolean.
     * @return the IsAppBoolean
     */
    public Boolean getIsAppBoolean() {
        if (this.getIapp() != null) {
            if (this.getIapp().toString().equals("1")) {
                return true;
            } else {
                return false;
            }
        }
        return false;
    }

    /**
     * Sets <code>value</code> as the attribute value for the calculated attribute IsAppBoolean.
     * @param value value to set the  IsAppBoolean
     */
    public void setIsAppBoolean(Boolean value) {
        if(value){
            setIsapp(new BigDecimal(1));
        }else{
            setIsapp(new BigDecimal(0));
        }
    }
Note: when getter is called , its value is decided based on the value of IsApp and setter overrides the value os IsApp.


4. Using the Transient Attribute on jspx:
     while using the drag n drop method the isAppBoolean attribute is defaulted as type outputext in case of readonly table and input text in case of updatable form, Either you can right click on the component and use convert option to convert it into checkbox or you may use this:

        a. Readonly Table  :
                                      <af:column sortProperty="ISAPPBOOLEAN" sortable="false"
                                         width="75" headerText="IsAPP" id="c6">
                                                   <af:selectBooleanCheckbox selected="#{row.ISAPPBOOLEAN}"
                                                     id="sbc1"/>
                                             </af:column>

         b. Updatable form :
                                        <af:selectBooleanCheckbox value="#{bindings.ISAPPBOOLEAN.inputValue}"
                                            label="IsApp"
                                            id="sbc2">
         

No comments:

Post a Comment