Sunday, July 8, 2012

ADF PPR Checkbox(af:selectBooleanCheckbox) action hide/show Command Link (af:commandLink)


Requirement

On ADF Form after Clicking Accept Terms and Condition Checkbox(af:selectBooleanCheckbox) make another component eg. Command Link (af:commandLink)  visible or enable using Partial Page Rendering.



After Accepting T&C show Command Link Available Options




Solution 
On ADF Page create Terms and Condition Checkbox
1)Enter Label and/or other details
2)In Property Inspector à Behavior à Auto Submit to True
3)In Property Inspector à Behavior à Value Change Listener to create method  TCcheckUncheck



4)In Property Inspector àAdvanced à Bindings click edit to create New tcCheckBox


 
<af:selectBooleanCheckbox text="Accept T&amp;C"
                                        label="Accept" id="sbc1"
                                        autoSubmit="true"
                                        valueChangeListener="#{IATLoginMB.TCcheckUncheck}"
                                        binding="#{IATLoginMB.tcCheckBox}"/>

Create Command Link with appropriate URL or Action
1)Enter Label and/or other details
2) In Property Inspector àAdvanced à Bindings click edit to create New myLink1


3) ) In Property Inspector àAdvanced àVisible to False
              <af:commandLink text="Available Options" action="taskflowLogin1"
                              id="cl1"
                              binding="#{IATLoginMB.myLink1}" visible="false"/>

Below Code in Managed Bean

    private RichSelectBooleanCheckbox tcCheckBox;
    private RichCommandLink myLink1;

 public void TCcheckUncheck(ValueChangeEvent valueChangeEvent) {

        if(this.getTcCheckBox().isSelected() == true ) {
            System.out.println("Checked ");
            myLink1.setVisible(true);
        }
       else if(this.getTcCheckBox().isSelected() == false ){
            System.out.println("UnChecked ");
            myLink1.setVisible(false);
             }

        AdfFacesContext.getCurrentInstance().addPartialTarget(myLink1);

    }

   public void setTcCheckBox(RichSelectBooleanCheckbox tcCheckBox) {
        this.tcCheckBox = tcCheckBox;
    }

   public RichSelectBooleanCheckbox getTcCheckBox() {
        return tcCheckBox;
    }

    public void setMyLink1(RichCommandLink myLink1) {
        this.myLink1 = myLink1;
    }

    public RichCommandLink getMyLink1() {
        return myLink1;
    }