Wednesday, November 18, 2015

What is the difference between Taskflow return and Parent Action Activity?

If Taskflow return in a bounded taskflow is used then the control returns back to the parent containing the same return name

If Parent action activitiy is used then control returns back to parent and also triggers an action in parent

Taskflow return ref: https://tompeez.wordpress.com/2013/06/18/jdeveloper-navigation-after-return-from-bounded-task-flow/

Parent action activity ref: https://tompeez.wordpress.com/2014/09/25/jdev-12-1-3-using-parent-action-to-navigate-tabs-of-a-afpaneltabbed-from-inside-a-region/

Render and Visible property? When to use?

I want to hide a component in the UI based on certain condition? Should i use Render or Visible?

If Render is used : 

  • The component will not be a part of the component tree. Meaning?
    • The component will not be shown on the client side (HTML) and will NOT go through the ADF life cycle as well as validation phases.
  • You need not change it based on bindings values via PPR 

How to toggle?

We need to do a PPR on the components PARENT to ensure it is included in tree structure and rendered on the UI.

If Visible is used:


  • The component will be a part of the component tree. Meaning?
    • The component will be seen on the client side (HTML) and will go through the ADF life cycle as well as validation phases.
  • This means its still available on the client side causing security issues. How?
    • Its easy for hackers to see them in the browser DOM for manipulation and if they're submittable components send them on the next request. 

For these reasons Render property is preferred and also it performs better as the component is not part of the validation life cycle

How to toggle?
PPR can be done to make the component conditionally visible.

Ref:
http://www.techzahowz.com/fmw/adf/adf-tip-when-to-use-rendered-vs-visible-for-hiding-components/
https://adfblog.files.wordpress.com/2014/01/oracle-application-development-framework-best-practices.pdf

Thursday, November 12, 2015

How to disable or enable a button on click of a Command Link

This is one of the most used cases: On click of a link you need to enable/disable a button:


Something like shown above, following is the requirement:
1. On click of the link Click here the Go button should be enabled
2. Initially when the page is rendered the the Go button should be disabled

Lets see how to achieve this:

Create a bean having a boolean property which will be used to set the disabled property of the button Go. I have created a bean called TestBean with buttonDisable property

import javax.faces.event.ActionEvent;

import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
import oracle.adf.view.rich.context.AdfFacesContext;

public class TestBean {    
    private boolean buttonDisable=true;

    public void linkClicked(ActionEvent actionEvent) {
        // Add event code here...
        buttonDisable=false;
        RichCommandButton button =(RichCommandButton)actionEvent.getComponent().findComponent("cb1");
        AdfFacesContext.getCurrentInstance().addPartialTarget(button);
    }

    public void setButtonDisable(boolean buttonDisable) {
        this.buttonDisable = buttonDisable;
    }

    public boolean isButtonDisable() {
        return buttonDisable;
    }
}

Setting this to true is going to make the Go button disabled when the page is loaded.
Then on wards if the link is clicked the linkClicked method is called which is going to set this boolean to false.

Happy Coding :)


Thursday, November 5, 2015

How to sort values in a java Class based on a property

Implement the Comparator class, say you have created a class called YourClass as follows

YourClass{
int age;
String name;
}
Supposing your requirement is to sort this Object based on the age then create a comparator as follows


public class YourComparator implements Comparator {

    YourClass yourList;

    public YourComparator (YourClass yourList) {
        super();
        this.yourList= yourList;
    }

    public int compare(Object o1, Object o2) {
        return compare((YourClass )o1, (YourClass )o2);
    }

    public int compare(YourClass o1, YourClass o2) {
        int age1= o1.getAge();
        int age2= o2.getAge();
        return (age1- age2);
    }
}

Then use this class to sort YourClass as follows, here i have a list input from the taskflow and then i am sorting this list and assigning back to the pageFlowScope.

    public void AgeSort() {
        List<YourClass > list = (List<YourClass >)resolveExpression("#{pageFlowScope.YourDetails}");
        YourClass  y1 = new YourClass ();
        YourComparator comp= new YourComparator (y1);
        Collections.sort(list, comp);  
        AdfFacesContext.getCurrentInstance().getPageFlowScope().put("YourDetails", list);
    }