Wednesday, February 3, 2016

is not Rendered if binding property is set when used inside a foreach

The reason being <af:forEach> cannot share a binding EL value with the Children.
It means a component instance may only exist once in a component tree.

Therefore, if it is desired to have the component bound
to a managed bean, the binding must evaluate to a different bean property for every iteration of the loop.

For example:

<af:forEach var="item" items="#{bean.items}">
<!-- Note that the output text component is bound to the item, not the bean -->
<af:outputText binding="#{item.outputText}" />
</af:ForEach>

The forEach tag should be used with intent and knowledge. The forEach tag is not used in JSF for iteration, but instead for generating multiple components. If your goal is to iterate over a collection of objects and render HTML for each item, <af:iterator> should be using instead.-

More info- Oracle Fusion Middleware Tag Reference for Oracle ADF Faces


Thursday, January 21, 2016

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);
    }


Wednesday, October 21, 2015

How to create a HTML like table using ADF Faces components

Supposing  your requirement demands to show a table just like an HTML table, the best would be use the panelGridLayout
 something like:

marginStart="0px" is variable which will give no gaps between the cells

<af:toolbar id="dc_t1"
                  inlineStyle="border-color:ActiveCaption; border-style:solid; border-width:1.0px;">
        <af:panelGridLayout id="pov_pgl1">
          <af:gridRow marginTop="0px" height="auto" id="gr1">
            <af:gridCell marginStart="0px" width="auto" id="gc3" halign="center"
                         valign="middle"
                         inlineStyle="border: 1px ActiveCaption solid;">
              <af:panelGroupLayout id="pov_pgl2" layout="vertical"
                                   inlineStyle="padding:5.0px;">
                <af:panelGroupLayout id="dc_pgl4" layout="horizontal" >
                  <af:outputText value="Row1" id="ot1"
                                 inlineStyle="font-size:smaller;"/>
                </af:panelGroupLayout>
                <af:panelGroupLayout id="dc_pgl10"
                                     layout="horizontal">
                  <af:outputText id="dc_ot1" />
                </af:panelGroupLayout>
                <af:panelGroupLayout id="dc_pgl5" layout="horizontal">
                  <af:outputText value="Row2" id="ot3"/>
                </af:panelGroupLayout>
              </af:panelGroupLayout>
            </af:gridCell>
            <af:gridCell marginStart="0px" width="auto" id="gc2"
                         inlineStyle="border: 1px ActiveCaption solid;"
                         halign="center" valign="middle">
              <af:panelGroupLayout id="pov_pgl3" layout="vertical"
                                   inlineStyle="padding:5.0px;">
                <af:panelGroupLayout id="dc_pgl6" layout="horizontal" rendered="true">
                  <af:commandLink text="Row1" id="dc_cl1"
                                  actionListener="#{backingBeanScope.POVBarComponentBean.openMemSelector}"
                                  inlineStyle="font-size:smaller;"/>
                </af:panelGroupLayout>
                <af:panelGroupLayout id="dc_pgl9" layout="horizontal">
                  <af:outputText id="dc_ot2" />
                </af:panelGroupLayout>
                <af:panelGroupLayout id="dc_pgl7" layout="horizontal">
                  <af:commandLink id="ot4" text="Row2"
                                  actionListener="#{backingBeanScope.POVBarComponentBean.openMemSelector}"/>
                </af:panelGroupLayout>
              </af:panelGroupLayout>
            </af:gridCell>
            <af:gridCell marginStart="0px" marginEnd="5px" width="auto" id="gc5"
                         inlineStyle="border: 1px ActiveCaption solid;"/>
          </af:gridRow>
        </af:panelGridLayout>
      </af:toolbar>