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

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

Wednesday, August 22, 2012

Different ways of getting Handle to AM from Backing Bean

Method 1 : (Note : ValueBinding is deprecated in 11g)
// 1. Create a value binding
// 2. Access the binding container
// 3. Find the data control using #data binding.
// 4. Access the data control's application module data provider

ValueBinding vb=fctx.getApplication().createValueBinding();
BindingContext bc = (BindingContext)vb.getValue(fctx);
DCDataControl dc =  bc.findDataControl("#{data}");
ApplicationModule am =(ApplicationModule)dc.getDataProvider();

Method 2 : (Typically used in a managed bean)
Configuration.createRootApplicationModule(MyAMDefn,AMConfig);
Configuration.releaseRootApplicationModule(,..);

Method 3 : (Typically used in a backing bean based on page iterators)
// 1. Access the binding container
// 2. Find a named iterator binding
// 3. Get the data control from the iterator binding
// 4. Access the data control's application module data provider

DCBindingContainer bc = (DCBindingContainer)getBindings();
DCIteratorBinding iter = bc.findIteratorBinding("MyVOIterator");
DCDataControl dc  = iter.getDataControl();
ApplicationModule am = (ApplicationModule)dc.getDataProvider();

Method 4 : (Typically used in a backing bean based on action binding)
// 1. Access the binding container
// 2. Find a named action binding
// 3. Get the data control from the iterator binding (or method binding)
// 4. Access the data control's application module data provider

DCBindingContainer bc = (DCBindingContainer)getBindings();
JUCtrlActionBinding action = (JUCtrlActionBinding)bc.findCtrlBinding("MyActionMethod");
DCDataControl dc = action.getDataControl();
ApplicationModule am = (ApplicationModule)dc.getDataProvider();

Method 5 :
// 1. Access the binding context
// 2. Find data control by name
// 3. Access the data control's application module data provider
FacesContext fctx = FacesContext.getCurrentInstance();
BindingContext bindingContext = BindingContext.getCurrent();
DCDataControl dc = bindingContext.findDataControl("MyModuleDataControl");
MyAMImpl am = (MyAMImpl)dc.getDataProvider();

Method 6 :
//Using Value Expression.
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = fc.getELContext();
ValueExpression valueExp =elFactory.createValueExpression(elContext, "#{data.MyDataControl.dataProvider}",Object.class);
MyAMImpl am = (AmImpl)valueExp.getValue(elContext);

Saturday, August 18, 2012

Alternate approach for multiple row select on an ADF table

Earlier post covered a similar topic of how to capture multiple row selection made in an ADF table.

The problem with the earlier approach is that user have to select a row and in order to select the second row and subsequently from there on, they have to hold the ctrl key and click on the row to select additinal rows.

Here in this post, I am going to detail on an alternate approach which would eventually provide access to the selected row but with more user adaptablility.

Select the VO (say "MyVO") that you plan to create a ADF table, add an additional column as "selectMany" as an transient variable. Make sure to check the attribute updatable always.

When we drag the VO to create an ADF table make sure to change the new transient variable type from outputtext to selectBoolenCheckBox.
(OR)
Update the Edit Attribute : select Many control hints -> Control Type to Boolean.

Make sure the value on the checkbox looks something like this value="#{row.bindings.selectMany.inputValue}"

FacesContext facesContext = FacesContext.getCurrentInstance();
DCBindingContainer bindings = (DCBindingContainer)getBindings();
DCIteratorBinding iter = bindings.findIteratorBinding("MyVO");
RowSetIterator rsi = iter.getViewObject().createRowSetIterator(null);

Row current;
while (rsi.hasNext()) {
         current = rsi.next();
         if (true == current.getAttribute("selectMany")) {
                 // this is the row that is selected in the UI.
         }
}  

Friday, August 17, 2012

Fetch all the rows selected from a UI Table in ADF

Following is an example to get all the rows selected from a UI table in ADF.

How do we enable multiple selections on a table ?

When you drag and drop a VO on to a page, user is presented with different options to represent the data from the VO. Choose the option of ADF table and select the option of "multiple rows" under "Row Selection" (Other options available are None, Single row)

If there is no backing bean or Managed bean enabled while creating the page then create binding for the table, how ?
-------------------------------------------------------------------------
Click on the table in the structure panel, Go to property inspector - > Advance -> Binding - > Choose Edit -> Create new managed bean & create new porperty as "table1".

Above action creates a getter  and setter method for the "table1" as below in the bean.

    private RichTable table1;
   
    public void setTable1(RichTable table) {
        this.table = table;
    }

    public RichTable getTable1() {
        return table;
    }

-------------------------------------------------------------------------

Friday, August 10, 2012

Refresh ADF page programmatically.

Several times, we might have the need to refresh the page programatically. Every page is internally given an ID and can be refreshed by this ID as follows in the backing bean.

Refresh a page programmatically.

String refreshPage = fctx.getViewRoot().getViewId();
ViewHandler vh = fctx.getApplication().getViewHandler();
UIViewRoot UVi = vh.createView(fctx,refreshPage);
UVi.setViewId(refreshPage);
fctx.setViewRoot(UVi);

Thursday, August 9, 2012


ADF Glossary


action binding
A binding for command components, such as buttons or links, to built-in or custom methods on the data control, or to built-in collection-level operations (such as, Create, Delete, Next, or Previous). An action binding object encapsulates the details of how to invoke a method and what parameters (if any) the method is expecting.



activity
A piece of work that is performed when an ADF Controller task flow runs, for example, a method call or view.



ADF binding filter
A servlet filter that ADF web applications use to preprocess any HTTP requests that may require access to the binding context.



ADF Business Components
A framework that simplifies the development, delivery, and customization of business applications for the Java 2 Platform. You use ADF Business Components to define associations between entity objects, view objects, and application modules to reflect the foreign keys present in the underlying tables.



ADF Controller layer
A mechanism that provides an enhanced navigation and state management model on top of JSF. This mechanism declaratively defines navigation using control flow rules.



ADF Faces Rich Client (RC)
A set of standard JSF components that include built-in Ajax functionality.



ADF Model layer
A layer that implements JSR-227 service abstraction called the data control.



application module
A transactional component that UI clients use to work with application data. It defines an updatable data model and top-level procedures and functions (called service methods) related to a logical unit of work. This unit of work is related to an end-user task.



binding context
A container object that holds a list of available data controls and data binding objects. The DataBindings.cpx files define the binding context for the application.See also data control.



bounded task flow
A specialized form of ADF Controller task flow that has a single entry point and zero or more exit points. It contains its own set of private, control flow rules, activities, and managed beans. A bounded task flow allows reuse, parameters, transaction management, and reentry. When dropped on a page, it becomes a region.



control flow
An ADF Controller activity that enables navigation between other activities in an ADF task flow. The control flow links one activity to another in a task flow.



data control
XML configuration files that describe a service. At design time, visual tools like JDeveloper can leverage that metadata to UI component to be declaratively bound to an operation or data collection.



Data Controls panel
A panel in JDeveloper that lists all the data controls that have been created for the application's business services and exposes all the collections (row sets of data objects), methods, and built-in operations that are available for binding to UI components.



entity object
An object that represents a row in a database table and that simplifies modifying its data by handling all data manipulation language operations for you. Entity objects are ADF Business Components that provide the mapping to underlying data structures.



invoke action
An action that binds to a method that invokes the operations or methods defined in an action or a method action binding during any phase of the page lifecycle. See also action binding.



iterator binding
A binding to an iterator that iterates over view object collections. There is one iterator binding for each collection used on the page. All of the value bindings on the page must refer to an iterator binding in order for the component values to be populated with data at runtime.
Contrast with variable iterator and method iterator.



list of values (LOV)
Input components that allow a user to enter values by picking from a list that is generated by a query



MDS
An application server and Oracle relational database that keep metadata in these areas: a file-based repository data, dictionary tables (accessed by built-in functions) and a metadata registry. One of the primary uses of MDS is to store customizations and persisted personalization for Oracle applications



method iterator
A binding to an iterator that iterates over the collections returned by custom methods in the data control. An iterator binding that is always related to a method action binding object. The method action binding encapsulates the details about how to invoke the method and what parameters the method is expecting. The method action binding is itself bound to the method iterator, which provides the data.



Oracle ADF
An end-to-end application framework that builds on Java Platform, Enterprise Edition standards and open-source technologies to simplify and accelerate implementing service-oriented applications.




page definition file
A file that defines the binding objects that populate the data in UI components at runtime. For every page that has ADF bindings, there must be a corresponding page definition file that defines the binding objects used by that page.


region
An ADF Controller UI component whose content is based on a task flow definition. When first rendered, the region's content is that of the first view activity in a task flow.



task flow
A set of ADF Controller activities, control flow rules and managed beans that interact to allow a user to complete a task.


unbounded task flow

A set of activities, ADF control flow rules, and managed beans that interact to allow a user to complete a task. An unbounded task flow has a single point of entry.



value binding
A binding used by ADF view UI components that display data. Value bindings range from the most basic variety that work with a simple text field to more sophisticated list and tree bindings that support the additional needs of list, table, and tree UI controls.



value iterator
An ADF Model iterator pointing to a collection that contains only one data object whose attributes are the binding container variable. Contrast with method iterator and value iterator iterator.



variable iterator
A binding to an iterator that exposes all the variables in the binding container to the other bindings. While there is an iterator binding for each collection, there is only one variable iterator binding for all variables used on the page. Contrast with method iterator and value iterator iterator.



view accessor
An ADF Business Components object that points from an entity object attribute (or view object) to a destination view object or shared view instance in the same application workspace. The view accessor returns a row set that by default contains all the rows from the destination view object.



view object
An ADF Business Components object that represents a SQL query and simplifies working with its results. The SQL language is used to join, project, filter, sort, and aggregate data into the shape required by the end-user task being represented in the user interface.

OAF - Change standard logo, background color

Customizing Your Web Pages
The following steps explain how to customize certain aspects of your Oracle Self-Service Web Applications pages.

To add your company logo:
You can replace the default Oracle logo with your own corporate logo. Your logo will then appear on every page.

1. Create a GIF file containing your corporate logo and name it FNDLOGOS.gif.
2. Place the file in the directory as defined in the Web Listener.
If you have a multilingual install, you must also copy this file into the other language location.

To change the background color:
You can replace the background on every page with your own choice of background color and texture.

1. Create a JPEG file containing your background and name it ICXBCKGR.jpg.
2. Place the file in the directory as defined in the Web Listener.
If you have a multilingual install, you must also copy this file into the other language location.