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>

Monday, September 7, 2015

How to set the default value of LOV?

There are 2 ways to default the value of LOV value:
1) From the model layer as explained in:
     http://husaindalal.blogspot.in/2010/05/how-to-default-lov-with-its-first-value.html
2) From the UI layer i.e. using the managed bean as explained in:
https://adfblog.wordpress.com/2014/02/21/how-to-display-default-valuesfirst-item-selected-in-selectonechoice/
    
   

Sunday, August 23, 2015

What are the java classes generated from EO and what are their uses?

1. Entity Object Class: Most frequently used for customizing business logic. for e.g.: to prevent an update on specific attributes setAttributeInternal() method is used

2. Entity Collectin Class: Customize default entity caching implementation. for.e.g: custom logic for cleaning up cache rows

3. Entity Definition Class: Customize default entity definition implementation. for e.g: modify properties of entity object or attributes at runtime then override resolveDefObject

What are the different ways to create EO


  1. Using Tables
  2. Using Views, but view should be updatable. Views can inherently updatable or you can create INSTEAD OF trigger on view to make it updatable.
  3. Overriding doDML method
  4. Synonyms: Its an alias for any table or materialized view
  5. Materialized view: Its a database object which contains the results of a query
Note: If primary key is not inferred then framework will create an attribute RowId with primary flag checked

How to make one of the attributes of EO saved in uppercase

In the EntityImpl getter class, return the string with upper case:
For e.g:- Name attribute should be changed to uppercase after commit:
    /**
     * Gets the attribute value for Name, using the alias name Name.
     * @return the value of Name
     */
    public String getName() {
        System.out.println("EO getName method");
        String name =(String)getAttributeInternal(NAME);
        if(name!=null){
            return name.toUpperCase();
        }
        else{
            return (String)getAttributeInternal(NAME);  
        }      
    }


Monday, August 17, 2015

When should i extend the Exception Class?

Following are some of the reasons why you
want to do this are to:


  • Customize the exception error message
  • Use error codes to locate the error messages in the resource bundle
  • Use a single resource bundles per locale for the error messages and the error message parameters
Ok...but how to do this?

Create a new class and extend oracle.jbo.JboException

Thursday, August 13, 2015

What should i do if my layouts in the Jdev get messed?

For e.g: structure window/log/property palette is docked at an unwanted position by mistake while dragging!

From the tool bar select Windows > Reset windows to Factory Setting :)

Tuesday, August 11, 2015

Why Confused?

I work on Oracle ADF, as its a vast framework used for developing enterprise applications. There are a lot of concepts and scenarios where we need to think which might fit best to the scenario. There are many ADF experts available in Oracle ADF/ Jdev Forum. But this blog is a small effort to differentiate and help understand and eliminate such day-to-day confusions for ADF beginners :)

Whether to use jsp or jspx while creating a page?

While create a page in ADF, there are 2 options whether to use jsf or jspx:










On selection of the Facelets option untitled.jsf file will created and on selection of JSP XML untitled.jspx file will be created. Here lies the confusion...which one to choose??

While searching for this answer came across Frank Nimphius's answer:

"Usually Facelets is considered to be of better performance because it is tighter integrated with the JSf lifcycle and doesn't need to be compiled before running it. Anyway, to lift the FUD:

1. JSPX documents and Facelets are both supported with JDeveloper 11g R2 and we do       
    support them equally in functionality (very little differences exist on both sides)

2. JSPX documents are the only choice in JDeveloper 11g R1

3. The future speaks Facelets (according to the JSF specification) and if you starting a new       
    development project with JDeveloper 11g R2 then we recommend you use Facelets because 
    of this

4. If you are on JDeveloper 11gR1, don't panic, you are good to go and we make sure your 
    applications upgrade nicely to 11g R2 and 12c (later)

5. We plan on providing a JSPX to Facelets migration in JDeveloper. Until then, JSPX are a 
    first class citizen as Facelets is too

6. When you are on JDeveloper 11gR1, don't wait for 12c if you need to start a development 
    project."

No more confusion :)