sort of column of table in ADF -Techartifact

Requirement- To sort an particular column by default on page load.

We can achive by changing the iterator property. Suppose we are having an table and we want to sort the table on page load by taskrole.
Click on bindings –

Now select the right iterator and click on edit

click on sort criteria tab and select the right column and choose sort order-

Happy coding with Techartifact

ADF – Groovy for Total Sum of a Column in a Table

ADF – Groovy for Total Sum of a Column in a Table

We will be looking in this article as how we can add Total of a column in a table. Very often we require to have total of a column in a table. For example , we might need total sum of Salary column in the table.
We will be leveraging power of Groovy in accomplishing this task.
So lets see how we can do this.
Use Case :- Add a Total Salary Attribute below Salary column in Employees Table.
Model Project
Considering that we have EmployeesView VO object which is based on Employees EO, go to attributes of VO and click add new attribute. Select “Add new Attribute”. It will by default be transient. Give this attribute  name as TotalSal.
Now go to View Accessors tab and click on green + sign to create new View Accessor.
Select EmployeesView from the first window and shuttle it so that you can see like below.
Do ok and it should be like below screenshot.
Now go to attributes tab and select the new transient attribute (TotalSal).
Give its Default value as Expression and give Groovy expression as EmployeesView1.sum(“Salary”) .
View Project
Create a new page. Drag and Drop EmployeesVO from data control and create a new read only table “without” TotalSal Attribute.
Now go to Salary Column in Structure and do a right click and select footer from facet as shown below.
Now from EmployeesView1 in DataControl, drag and drop TotalSal column in this new footer facet.
Now go to bindings and create a new binding for this variable.
 And change the value of footer output text with this binding.
Save all and run this page.
Hope this was useful.
Happy Learning !!
Rohan Walia

Invoke a method from Managed Bean when JSPX Page Loads in ADF.

Requirment -invoke a method from Managed Bean when JSPX Page Loads in ADF.

Suppose you have some method in managed bean, which you want to call on page load.For that
Your managed bean should implement implements PagePhaseListener i.e

public class vinayManagedBean implements PagePhaseListener{ }

You should import “oracle.adf.controller.v2.lifecycle.PagePhaseListener;”
Now you will be calling method in beforePhase event of ADF page life cycle.In side the beforePhase ,pageLoad method will be called.You can write your custom method there.

public void beforePhase(PagePhaseEvent pagePhaseEvent) {
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_MODEL_ID) {
onPageLoad();
}
}

public void afterPhase(PagePhaseEvent pagePhaseEvent) {
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_RENDER_ID) {
// onPagePreRender();
}
}

public void onPageLoad() {
if (!AdfFacesContext.getCurrentInstance().isPostback()) {
// add your onPageLoad event here

// to set the View Criteria on the Iterator
doSomeOperation();  ///your custom method.
}
}

After all then right click on .jspx page and go to page definitions file .In your JSPX page definition make sure you add the ControllerClass that points to the managed bean that handles the onPageLoad event.

<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel" version="11.1.2.60.17" id="InspectionTaskHomePageDef"
                Package="oper.view.pageDefs" ControllerClass="vinayManagedBean">
  <parameters/>

By doint this whenever you page loads, the onPageLoad() method gets invoked which inturn invokes the v() method. You can even call multiple methods in onPageLoad() method.

Note:- It will not work in jsff.