Search This Blog

Friday, October 26, 2012

Detect the browser type and version in ADF

How-to detect the browser type and version


The Trinidad RequestContext object provides access to the user browser type and browser version. using Expression Language as

#{requestContext.agent.agentName}

#{requestContext.agent.agentVersion}

Trinidad RequestContext class is exposed through the AdfFacesContext class, which means that we can also use

#{adfFacesContext.agent.agentName}

#{adfFacesContext.agent.agentVersion}

Thursday, October 18, 2012

OAF setup on server before running Oracle Self-Service Web Applications

Configure environment variables and servlet zone list, these are prerequisite before deploying the OAF code on to the server.  (Courtesy : Oracle Documentation)

1. Locate the file jserv.properties.
All environment variables are set in this file. It is important to get $CLASSPATH and $LD_LIBRARY_PATH correct here. You can look at APPLSYS.env and adovars.env under $APPL_TOP for these two variable settings.

2. In jserv.properties, modify the following parameters:
wrapper.bin
The wrapper.bin property must contain the full path to the executable for the Java Virtual Machine. It sets which Java Virtual Machine interpreter to use here. For example:
wrapper.bin=/local/java/jdk1.1.6/bin/java

wrapper.classpath
This property contains the CLASSPATH environment value passed to the JVM. The wrapper.classpath property must contain both the JSDK and the JServ jar file. It should probably also contain the JVM's classes.zip file and directives of servlet zones.
The syntax is:
wrapper.classpath=[path]
For example:
wrapper.classpath=/usr/local/ApacheJServ/jservlets
wrapper.classpath=/local/java/jdk1.1.6/lib/classes.zip
wrapper.classpath=/usr/local/ApacheJserv/src/java/ApacheJServ.jar

wrapper.env
This property is an environment name whose value is passed to the JVM.
The syntax is:
wrapper.env=[name]=[value]

You should set the $LD_LIBRARY_PATH variable here to the directory which contains the JDBC library file. For example:
wrapper.env=LD_LIBRARY_PATH=/oracle/db/8.1.6.1/lib

NLS environment variables should also be set here for the JDBC to operate. For example:
wrapper.env=NLS_LANG=AMERICAN_AMERICA
wrapper.env=ORA_NLS33=/opt/tools/ocommon/nls/admin/data
wrapper.env=NLS_DATE_FORMAT=DD-MON-RR

zones
This property lists the servlet zones that JServ manages. The syntax is:
zones=,
For example:
zones=jservlets

You must specify the configuration file location for each servlet zone that is specified. For example:
jservlets.properties=/usr/local/ApacheJServ/jservlets/

Monday, October 15, 2012

Find the ADF component from the page source.

When the JSF page becomes bulkier, the HTML view source of JSF pages is not very easily readable.
Setting the below flag in trinidad-config.xml ( under view controller -> Web Content -> WEB-INF) will add comments showing which ADF component caused which HTML to be rendered.


<debug-output>true </debug-output>


Found it very handy and useful.

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).