Search This Blog

Sunday, September 30, 2012

Build and Manage View Criteria dynamically in ADF

View Criteria :

Using Structured Where Clauses: View criteria are structured criteria that you can use to assemble a WHERE clause. Instead of changing WHERE clauses using string manipulation, you may find it more efficient to use view criteria to assemble complex WHERE clauses in conjunctive normal form.
To use structured WHERE clauses:

1. Instantiate the a ViewCriteria class by calling createViewCriteria() on the view object instance. For example, to create view criteria for the view object instance myOrdVO , you could use the following code:

ViewCriteria vc = myOrdVO.createViewCriteria();

2. For each view criteria row you will need, create a view criteria row by calling createViewCriteriaRow() on the ViewCriteria,

Example: ViewCriteriaRow cRow = vc.createViewCriteriaRow();


3. Set the requirements for each view criteria row by calling setAttribute() on the ViewCriteriaRow. Pass setAttribute() the name of the view object attribute and the SQL requirement to be applied to the attribute:

cRow.setAttribute("OrderTotal", "> 500");

cRow.setAttribute("CreditLimit", "> 2500");

cRow.setAttribute("PromotionId", "IS NOT NULL");


4. Add the rows to the view criteria by passing them to addElement() on the ViewCriteria:
vc.addElement(cRow);


5. Apply the view criteria to the view object instance by passing the ViewCriteria to applyViewCriteria():
myOrdVO.applyViewCriteria(vc);

At any time, you can do any of the following:

 Change the requirements in any row using setAttribute()

 Add further rows to the criteria using addElement()

 Remove rows from the criteria using removeElement()

 Construct and apply entirely different view criteria

 Unapply view critera by passing null to applyViewCriteria()

Wednesday, September 19, 2012

ADF Taskflow programatic refresh

Refreshing a taskflow sometimes becomes very essential in scenarios where we have multiple pages/fragments in a task flow and the business process requires multiple taskflows and each taskflows are interconnected.

For example :

Taskflow 1 has Pagefragment1, Pageframent2, Pagefragment3 and are executed in the same sequence based on your busines scenario.

Taskflow 2 has Pagefragment3, Pageframent4, Pagefragment5

Now on completion of Taskflow 1 (i.e Pagefragment 3), we call taskflow 2 and for any reason based on business logic we have to  go back to taskflow1. Surprisingly, taskflow1 starts at Pageframent 3 and NOT at Pageframent1, even though we set the default task for Taskflow1 as Pageframent1.

In such a scenario, we need to refresh the task flow that we instead to call by getting handler to the taskflow binding and refresh the taskflow. Refresh of taskflow re-renders/re-executes the taskflow starting from the default selection in the task flow. Below is the code snippet to do the same.

DCTaskFlowBinding tf = (DCTaskFlowBinding) JSFUtils.resolveExpression("#{binding.mytaskflow}");

//Refresh taskflow

tf.getRegionModel().refreshh(FacesContext.getCurrentinstance());

Generic Revenue Recognition Rules

Revenue generally is earned and realized or realizable when all of the following criteria are met:

Persuasive evidence of an arrangement exists. The requirement that persuasive evidence of an arrangement exists is intended to ensure that the understanding between the parties about the specific nature and terms of a transaction has been finalized. Determining the proper accounting treatment for a transaction depends on evidence of the final understanding between the parties, because a change in terms could lead to a different conclusion regarding the revenue recognition model to apply.

Delivery has occurred or services have been rendered. Unless delivery has occurred or services have been rendered, the seller has not substantially completed its obligations under the terms of the arrangement, and revenue should not be recognized. Delivery is generally deemed to have occurred when the customer takes title and assumes the risks and rewards of ownership.

The seller’s price to the buyer is fixed or determinable. Whether the price is fixed or determinable depends on many factors, including payment terms, discounts, and rebates, which can vary from arrangement to arrangement. In determining whether the price is fixed or determinable, entities should evaluate all elements of an arrangement to ensure that amounts recognized as revenue are not subject to refund or adjustment.

Collectibility is reasonably assured. If the collection of fees in an arrangement is not reasonably assured, the general principle of being realized or realizable is not met, and revenue recognition is precluded until collection is reasonably assured.

Monday, September 10, 2012

Export To Excel in ADF

ADF 11g has provided the feature of exporting to excel using export listener as follows

<af:exportCollectionActionListener exportedId="tableId" type="excelHTML" title="My Excel Document" filename="testFile.xls"/>

This feature has couple of limitation

1. Export can be based on a single table. If multiple tables are given we get the following error.
Exported collection with the ID of: t1 t2 was not found. with t1, t2 being table Ids.

2. The current feature doesn't allow to export data based on page iterators. As there are many scenarios we base our export to excel on different data(iterators) in the real world.   A traditional approach of exporting data has addressed the above two problems. Below is the code...

public String exporttoexcel_action() throws IOException {
         String filename = "testFile.xls";
         FacesContext fc = FacesContext.getCurrentInstance();
         BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
         // get response object.
         HttpServletResponse response = (HttpServletResponse)fc.getExternalContext().getResponse();
         // Set the file name
         response.setHeader("Content-disposition", "attachment; filename=" + filename);
         // Set MIME type to excel
         response.setContentType("application/vnd.ms-excel");
         PrintWriter out = response.getWriter();

         DCIteratorBinding theateriter = (DCIteratorBinding)bc.get("MyVO1Iterator");         
         printtoexcel(theateriter,out);

         out.println();

         DCIteratorBinding areaiter = (DCIteratorBinding)bc.get("MyVO2Iterator");
         printtoexcel(theateriter,out);
         out.close();

         fc.responseComplete();
         return null;
}



public void printtoexcel(DCIteratorBinding iter, PrintWriter out) {
         RowSetIterator rsi = iter.getRowSetIterator();
         String[] attNames = rsi.getRowAtRangeIndex(0).getAttributeNames();
         for (int i = 0; i < attNames.length-1; i++) {
         if (i > 0)
                out.print("\t"); // tab after each value
         out.print(attNames[i]);
}

Alternate Appraoches :

1. Using Apache open source POI APIs.
2. Other way to overcome this limitation is to override the export collection action listener class. (Never tried).

Friday, September 7, 2012

Programatically hide and show popup in ADF 11g

Programatically hide and show popup in ADF 11g

/**
* Show popup.
*/

import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;

public static void showPopup(UIComponent pId) {

        String popupId= (String )pId.getClientId(getFacesContext());
        FacesContext context = null;
        ExtendedRenderKitService extRenderKitSrvc = null;
        StringBuilder script = new StringBuilder();
        context = FacesContext.getCurrentInstance();
        extRenderKitSrvc = Service.getRenderKitService(context, ExtendedRenderKitService.class);
        script.append("var popup = AdfPage.PAGE.findComponent('").append(popupId).append("'); ").append("popup.show();");
        extRenderKitSrvc.addScript(context, script.toString());
}

/**
* Hide popup.
*/

public static void hidePopup(UIComponent pId) {
        String popupId= (String )pId.getClientId(getFacesContext());
        FacesContext context = FacesContext.getCurrentInstance();
        ExtendedRenderKitService erkService = Service.getService(context.getRenderKit(),            ExtendedRenderKitService.class);
       erkService.addScript(context,"AdfPage.PAGE.findComponent('" + popupId + "').hide();");
}

Sunday, September 2, 2012

Reloading an ADF page in 11g

Programmatically reloading an ADF page.

FacesContext fc = FacesContext.getCurrentInstance();
String viewId = fc.getViewRoot().getViewId();
String resourceUrl = fc.getApplication().getViewHandler().getActionURL(fc, viewId);

try {
      ExternalContext ec= fc.getExternalContext();
      ec.redirect(resourceUrl);
} catch (Exception e) {
      e.printStackTrace();
}