Wednesday 27 March 2013

Difference between AutoSubmit and PartialSubmit

autoSubmit: Related to an input component (such as inputText and selectOneChoice) or a table select component (such tableSelectOne). The component automatically submits the form it is enclosed in.
partialSubmit:
Releated to a command component. The page partially submits when the button or link is clicked
To refresh the tree child node. Executing the top level view object instance alone is not enough. This is because when you expand a parent node, if the
framework identifies any existing query collection for the row filter supplied by the parent row, the existing query collection cache will be reused for displaying
child nodes. To refresh specific child nodes, you will have to find the appropriate child row set and refresh it by calling the executeQuery() method.

For example. We have displaying country in tree node. In Child node we are displaying the states. For we will taking out the country id and fetch the row on basis of countryID and get the rowset
and call executeQuery() method and it will refresh the child node as well.

Below is the code.


public void refreshChildStates(Number CountryId) {
//Gets the VO used for parent node
ViewObjectImpl vo = getCountry();
//Read the row using Key CountryId
Row[] countryRow= vo.findByKey(new Key(new Object[] { CountryId}), 1);
RowSet childRows =
(RowSet)stateRow[0].getAttribute("States")';
childRows.executeQuery();
}

Monday 18 March 2013

Bookmarking Taskflows in ADF / Accessing ADF Taskflows by URLs

The problem:
I need to bookmark or deep link a page in an ADF application, either to save a link to the page or share the page by email or other means. Unlike a normal web-app, JSF does not play well with bookmarks, but ADF comes bundled with (somewhat limited)support for doing this. This sort of a requirement is common when we need to include an application link in a generated email report to enable to user to see additional interactive information or to secure the information itself by sending not the report but just a link to it, so that he user will authenticate before accessing the information.

Solution:
ADF has bookmark support for pages in the unbounded task flow, so we take a look at how the bookmark attribute works and how to use it. The built in support has limitations in that only pages in the unbounded taskflow can be bookmarked, and at times we would want pages within a bounded taskflow to be bookmark-able, so we take a look at a method for bookmarking/deep-linking a page within a bounded taskflow.

Bookmarking in the unbounded taskflow
The following example of the out-of-the-box support for bookmarking is based on the standard Oracle documentation here.
You start out with a standard app, in this case a page that lists the departments in the HR schema and a second page that displays the details of the staff in a given department. We need to make this second page bookmark-able, i.e. we need the ability to directly give a URL with parameters and pull the staff information of the department that we use as the parameter in the URL. The taskflow is simple and is shown below.


You can download the full example for the complete code, but the essentials of the example are these :
  • The first page lists the depatments table, and the second page gets the staff details for a specific department. 
  • The second page is using a sql query (ViewObject) that has the departmentName as a bind parameter.
  • You have the first page(welcome) with the department list(from DEPARTMENTS table in HR schema) displayed on a table, and each row has an <af:commandButton> that has its action attribute set to a navigation rule that directs the flow to the staff details page.
  • The <af:commandButton> also takes care of passing the parameter to the details page.(code below).
                                                                 
    
Now, for the purpose of the example, the command button has an action listener that is bound to a custom method on the AM that takes the department name as a method parameter and executes the Staff Details VO(this dept name being a bind param for the VO). An <af:setActionListener> sets the dept name corresponding to the button in to a backing bean property. Then in the pageDef for the Department page, an operation binding for the AM method(via DataControl) created and is configured to pickup the backing bean property as a parameter to the AM method. So when the button is clicked:

The <af:setActionListener> copies the respective department name to a backing bean property
Then the actionListener for the button fires executing the method binding,
The method binding takes the department name from the backing bean property(set in step 1), and uses it as a parameter to the AM method.
This AM method in turn executes the StaffdetailsVO binding the given department name to it.
Now the staff details VO contains the staff information for the given department.
Then, since the action attribute of the command button was set to a navigation rule to the staff page, the Staff Details page loads displaying the staff VO that has been executed already.

This is the basic working of the example app. Now for bookmarking, we need the ability to extract the URL parameter from the URL and execute the StaffDetailsVO when loading the Staff Details page. ADF provides exactly this.In the unbounded taskflow, open the property inspector for the view activity representing the staff detail page(Click on the StaffDetail ViewActivity) and you can see there is a properties section for bookmarking.
Here you will see the URL parameter name and value. They basically mean that the framework will take whatever value is in the URL for the given name, and it will populate that value to the destination. The optional method property lets you invoke a custom method after the values have been processed and before the page is loaded to do custom processing, like execute a VO with the param we get from the URL !.     In this case, name is set to “dept” and value is set to #{pageFlowScope.deptDetails.departmentName}, which is the departmentName property in the backing bean. So essesntially what the framework does is look at the URL for the parameter named “dept”, take the value for tht parameter and populate the value to the backing bean property . Now we also have a custom method defined as #{pageFlowScope.deptDetails.loadDepartmentDetails} which is a method defined in the backing bean as:
Since the above method is invoked after processing the parameters, the departmentName property of the backing bean has been set to the value specified by the URL param “dept”. So the call to getDepartment will return the department name that was passed though the URL. The rest is like clockwork, we get the same method binding and execute it. Its worthwhile to note here that the method binding here is created on the Staffdetails page’s pageDef and defaults to the backing bean property departmentName for the department name parameter it needs to execute the Staffdetails VO. So setting the operationBinding parameter manually in this method is not required and is shown for demonstration.
Bookmarking in bounded task-flows:

Bounded task-flows are a little bit more tricky and before we dive in to the implementation, consider this: When we say URL accessible, we are essentially saying a publicly available resource reachable by a URL, whereas a bounded taskflow is like a component, which needs a container. So we need a way to make the hidden innards of a bounded taskflow accessible in the form of a URL, with optional parameters. One way to do this to setup/construct the state for a page in the bounded taskflow based on the parameters in the URL that we’ll use. Since pages in bounded taskflows cannot be reached directly(actually they can, but the URL is not human readable and is very snarly) the approach here is to create a "container" page in the unbounded taskflow, and embed our bounded taskflow inside the container as a region. Then we will make that "container" page bookmark-able as described above. This way the clients will always see the "container" page's URL which would be nice and simple too. The bookmark-able page takes the URL parameters and passes them to to the taskflow as taskflow params and the task flow will be constructed so that it can recreate state based on the input parameters. Bounded taskflows do have a property called URL invoke. This enables the taskflow to be invoked with a URL, and is a good option when you want to expose the whole taskflow to be URL accessible, not just a page within the taskflow. We will not look at this option as we are trying to gain access to a specific page/part of a taskflow without going though the taskflow’s normal flow.

As the example, we’re going to do the exact same app as before, but time as a bounded taskflow with parameters. In the example, we will see the whole flow implemented, from search and details, and this is not necessary in most cases where you want to make a single page of your application bookmark-able/linkable. This is more of a pattern that I have found that will save time, and keeps code consistent. Develop the whole taskflow as bounded and provide the extra “hooks” to parts of your bounded taskflow from the unbounded one. This way, you can reap all the benefits of a bounded taskflow (like reusability, security), and the taskflow consumer can expose parts of the taskflow as URL accessible.

First we design the bounded taskflow. Since this taskflow takes parameters, the taskflow parameters and properties can be set in the property inspector by clicking on the blank area in the taskflow diagram.
The taskflow starts with a router which decides which page to see. although this is not required, it demonstrates an approach for structuring task flows that are built for URL accessibility(see the “about the example” box note). The important part is the taskflow parameters, as you can see from the property inspector image above. We’ll see how these parameters are passed to the task flow later on. The router looks at one parameter(viewMode) to decide which page page it wants to show. In the example, it is always the StaffDetails page. Once it determines that the details page is to be loaded, it then invokes a MethodCallActivity, passing the second input parameter, which is the deptName, to the method.
This MethodCallActivity has a page definition/ binding container so that it can invoke the AM method to execute the Deatils VO by passing in the dept Name. To open this pageDef file, right click the MethodCallActivity and choose "Go to Page Definition". Once the VO has been executed, the method call outcome loads the StaffDetails page which simple displays the executed VO as before. To make the page URL accessible, we put a “hook” page in the unbounded taskflow that is Bookmarkable and captures the URL parameters.
This page contains the bounded taskflow as a region and passes the URL parameters to the taskflow though the page’s pageDef/binding container.

Saturday 9 March 2013

What are the ADF Business Components Core Objects?

ADF Business Components implements the business service through the following set of cooperating components.


Entity object:
An entity object represents a row in a database table and simplifies modifying its data by handling all DML operations for you. It can encapsulate business logic for the row to ensure that your business rules are consistently enforced. You associate an entity object with others to reflect relationships in the underlying database schema to create a layer of business domain objects to reuse in multiple applications.

View object:
A view object represents a SQL query. You use the full power of the familiar SQL language to join, filter, sort, and aggregate data into exactly the shape required by the end-user task. This includes the ability to link a view object with others to create master-detail hierarchies of any complexity. When end users modify data in the user interface, your view objects collaborate with entity objects to consistently validate and save the changes.

Application module:
An application module is the 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 related to an end-user task.

Tuesday 5 March 2013

How to Customizing Error Handling?

You can report errors using a custom error handler that extends the default DCErrorHandlerImpl class. You are not required to write any code to register your custom exception handler class. Instead, you select the root node of the DataBindings.cpx file in the Structure window, and then use the Property Inspector to set the ErrorHandlerClass property to the fully qualified name of the error handler you want it to use.

Your custom error handler can contain the following overridable methods:
reportException(): Called to report any exception that occurs. It can be overridden to analyze reported exceptions.
getDisplayMessage(): Returns the message that will be reported to JSF for each error that occurs. Returning null is the way your custom error handler signals that a given exception should not be reported to the client.
getDetailedDisplayMessage(): Returns the detail portion of the message as a String object or HTML that will be reported to JSF for each error that occurs. Returning null is the way your custom error handler signals that a given exception should not be reported to the client.
skipException(): Returns a boolean depending on whether you want to display each item from the nested exception in the final error list displayed to the user. This method override lets you implement logic to check for specifics exception types and, based on the business scenario, determine whether to display it in the list.

custom error handler that extends the DCErrorHandlerImpl class and shows the override for the skipException() method that is needed to skip exceptions that should not appear in the list displayed to the user.
Example: 
Custom Error Handlerpackage view.controller.fwkext;
 import java.sql.SQLIntegrityConstraintViolationException; 
 import java.util.ArrayList; import java.util.List;
 import oracle.adf.model.binding.DCBindingContainer; 
 import oracle.adf.model.binding.DCErrorHandlerImpl; 
 import oracle.jbo.CSMessageBundle; import oracle.jbo.DMLConstraintException; import oracle.jbo.JboException;
 public class CustomErrorHandler extends DCErrorHandlerImpl { List<ExceptionMapper> exceptionMapperList = new ArrayList<ExceptionMapper>();
 public CustomErrorHandler() { this(true);
 }
 public CustomErrorHandler(boolean setToThrow) 
{
 super(setToThrow); exceptionMapperList.add(new DisableJboExceptionCodesMapper());
 }
 public void reportException(DCBindingContainer bc, Exception ex)
 {
 for (ExceptionMapper mapper : exceptionMapperList)
 { 
if (mapper.canMapException(ex))
 {
 ex = mapper.mapException(ex); 
 }
 }
 super.reportException(bc, ex); 
 }
 /** * If an exception is a RowValException or a TxnValException and they * have nested exceptions, then do not display it. This example shows * an implementation that skips the SQLIntegrityConstraintViolationException * from displaying in the error final list displayed to the user. */ 
@Override protected boolean skipException(Exception ex) {
 if (ex instanceof DMLConstraintException) 
{
 return false;
 }
 else if (ex instanceof SQLIntegrityConstraintViolationException) 
 return true; 
 } 
 return super.skipException(ex);
 }
 }

What Happens at Runtime,if the Validation is Successful/Failure?

When a user submits data, as long as the submitted value is a non-null value or a string value of at least one character, then all validators on a component are called one at a time. Because the f:validator tag on the component is bound to the validator property on the binding, any validation routines set on the model are accessed and executed.

The process then continues to the next component. If all validations are successful, the Update Model Values phase starts and a local value is used to update the model. If any validation fails, the current page is redisplayed along with an error message.

How to Create ADF Model Validation?

To create an ADF Model validation rule:

  • Open the page definition that contains the binding for which you want to create a rule.
  • In the Structure window, select the attribute, list, or table binding.
  • In the Property Inspector, select More and then Edit Validation Rule.
  • In the Edit Validation Rules dialog, expand the binding node, select the attribute name, and click New.
  • In the Add Validation Rule dialog, select a validation rule and configure the rule as needed.
  • Select the Failure Handling tab and configure the message to display when the rule is broken.

HOW TO DO VALIDATION IN ADF MODEL LAYER

In the model layer, ADF Model validation rules can be set for a binding's attribute on a particular page. When a user edits or enters data in a field and submits the form, the bound data is validated against any set rules and conditions. If validation fails, the application displays an error message.

Defining Validation Rules in the ADF Model Layer:

  • You can configure ADF Model validation for a binding's attributes on the page definition file. Validation rules in the model layer are executed for a binding's attribute on a particular page when the containing form is submitted.
  • You can optionally set the skipValidation property to true to bypass the ADF Model validation. You can set skipValidation to skipDataControls to validate the bound objects without validating the transaction. For example, set skipValidation to skipDataControls if you have a table action that opens a popup window to accept data entries and you want to allow the view layer to validate those entries before the commit on the table. The skipValidation property can be found in the Property Inspector after you have selected the root node of the page definition file in the Structure window.

Validation Can be Done by following:
Validator Rule Name Description
Compare Compares the attribute's value with a literal value
List Validates whether or not the value is in a list of values
Range Validates whether or not the value is within a range of values
Length Validates the value's character or byte size against a size and operand (such as greater than or equal to)
Regular Expression Validates the data using Java regular expression syntax
Required Validates whether or not a value exists for the attribute


Friday 1 March 2013

ADF TaskFlow Related Questions

Define TaskFlow?
ADF task flows provide a modular approach for defining control flow in a Fusion web application. Instead of representing an application as a single large JSF page flow, you can break it up into a collection of reusable task flows. Each task flow contains a portion of the application's navigational graph. 
The nodes in the task flows are activities. An activity node represents a simple logical operation such as displaying a page, executing application logic, or calling another task flow. 
The transitions between the activities are called control flow cases.
Ex:
In The Above Example two view activities called Create and Confirm. These view activities are similar to page nodes within a JSF page flow

How Many Types of TaskFlow ?Define Them?

The are two types of ADF task flow:

Unbounded task flow: A set of activities, control flow rules, and managed beans that interact to allow a user to complete a task. The unbounded task flow consists of all activities and control flows in an application that are not included within a bounded task flow.

Bounded task flow: A specialized form of task flow that, in contrast to the unbounded task flow, has a single entry point (an entry point is a view activity that can be directly requested by a browser) 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, reentry, and can render within an ADF region in a JSF page.


What is the difference in jspx and jsff?
Ans: jspx and jsff file are same in most of manner. Only difference is that you can run jspx directly on browser while jsff file container which will run on browser.


What is taskflow ? how many type of taskflow adf support?
Ans: Taskflow is the Component of Oracle ADF which is used to define simple task. After successfully defining task-flow can consume any number of time.
ADF support two kind of taskflow:
Bounded TaskFlow : Bonded taskflow require the page on which they will consume.
UnBounded TaskFlow : Unbounded taskflows can directly run on browser


How to develop reusable taskflow in ADF?
Ans: Please fins the step below
Define taskflow
Define deployment profile as ADF Library jar
Deploy adf jar file
Open new project where you want to consume the task flow.
Add newly created jar of taskflow project 
go to component palate You will fine you jar name select it.
It will show list of taskflow you developed
Drag drop your taskflow as region on jsff/jspx page and run ur application

Can bounded taskflow run on browser?
Ans: NO

What are different scope of adf taskflow?
Ans: Isolate/Shared
Shared scope will share data among the multiple instance of taskflows while Isolated doesn’t.

How can you force ADF taskflow to use new transaction everytime taskflow is called?
Ans: Go taskflow overview and you will file below item 

Select always begin new transaction fron dropdown

How to use same transaction in ADF taskflow?
Ans 

How can you pass parameter to adf taskflow?
Ans: Go to overview select parameters link it will show screen like 

Here you can add multiple parameter which you want to pass takflow while loading it.

Explain the purpose of using Controls flow in adf?
Ans: Controls flow defined in taskflow can be called anytime from any page of that taskflow.if you have same flow for multiple pages just define the control flow once in taskflow. You can invoke it anytime from any action event.

What is the behavior of router in ADF taskflow?
Ans : Based on some condition router can decide which route need to be follow. If none of condition match in that case router will follow default route defined by used.

How can navigation define in taskflow?
Ans : Navigation can be defined in taskflow using control flows and invoked by jsff/jspx page using action event like button link etc.


Can ADF task flow hold more than 1 view activity?
Ans: Yes. ADF taskflow can have multiple view activity but 1 activity has to be defined as default activity. 


What is the Parent Action in ADF Taskflow?
Ans:Parent action is activity using that you can invoke the Control flow define in parent taskflow from child taskflow. More details about how to develop it can be found on Parent Activity.


What is method activity in Adf Taskflow?
Ans: Using this activity you can invoke and method defined in manage-bean.

How to initialize ADF Taskflow?
Ans: Open the taskflow in Overview Mode select general like there is initiallizer property. 
you can provide the any method reference which will get invoked whenever taskflow instance created.





Explain about Oracle ADF Architecture?
Applications  build using the Fusion web technology stack achieve a clean separation of business logic, page navigation, and user interface by adhering to a model-view-controller architecture.


  • The model layer represents the data values related to the current page.
  • The view layer contains the UI pages used to view or modify that data.
  • The controller layer processes user input and determines page navigation.
  • The business service layer handles data access and encapsulates business logic.