Wednesday, 17 April 2013

Rendering HTML code on page

Below are the ways to render HTML code on JSF page:

Using <af:outputText><af:outputText value="#{pageFlowScope.testbean.value}" id="ot1" escape="false"/>

Using <af:richTextEditor><af:richTextEditor label="Label 1" id="rte1" readOnly="true" value="#{pageFlowScope.testbean.value}"/>
where bean code is using "org.apache.commons.lang.StringEscapeUtils.unescapeHtml" API to render html code properly.

import org.apache.commons.lang.StringEscapeUtils; 

public class testbean { 
 public testbean() { } 
 private String value = "&lt;
object width="100" height="100" data="http://www.google.co.in/images/srpr/logo3w.png"&gt;&lt;/object&gt;"; 
 public void setValue(String value) { 
 this.value = value; 
 } 
 public String getValue() { 
 value = StringEscapeUtils.unescapeHtml(value); return value; 
 } 
}

Tuesday, 9 April 2013

Reusable ADF Region with Dialog Framework

This post is about reusable ADF region and its usage from ADF Dialog Framework. If we have ADF Task Flow with fragments and want to use Dialog Framework, we need to create intermediate ADF Task Flow with pages and include our reusable region there - this will allow to load ADF Dialog from the fragment (dialog is always running in ADF page). I will describe in this post how to pass data from/to ADF region included into ADF Dialog to the calling fragment.

There is main ADF Task Flow in the sample - empls-flow (download sample applicationReusableDialogRegionApp.zip):

This task flow is configured to call intermediate ADF Task Flow with wrapper page. We are passing and getting parameters to/from the dialog:
Dialog is opened from the button in the main employees fragment:
Button is configured to open dialog:
There is dialog listener defined for this button, it receives return value. Alternatively we can get return value from the dialog return parameter directly:
Intermediate ADF task flow (which actually implements ADF dialog), contains a page and return activity. This page is only a wrapper, it includes reusable ADF region:
Intermediate ADF task flow with wrapper page defines input and output parameters:
Wrapper page contains Close button, this button sets return value, it retrieves return value from the bindings. Because Data Control is shared between reusable ADF region and intermediate ADF task flow with wrapper page, we can access bindings from ADF region and return it from the wrapper page. You can see that this page includes our reusable ADF region:
Here is binding definition for the attribute in the page definition for wrapper page:
And the last bit - ADF reusable region, JSF fragment view:
Bindings for ADF reusable region, you can see where CountryId attribute value is set. We are getting the same value in dialog wrapper page through shared Data Control:
I should mention one important thing - intermediate ADF dialog task flow is configured to run in isolated scope. This is important and allows to reset reusable ADF region in the dialog always to its initial state on opening:
Countries region is loaded and DepartmentId value is passed into:
Selected value is returned back:
The same reusable region is opened from another fragment - region state is reset, user can select value and return it:

Thursday, 4 April 2013

Oracle ADF useful training video, PPT, PDF links

Videos:
Following are the prerequisites for these trainings:-
Oracle JDeveloper 11G Studio
Oracle Database Express Edition 10G/11G  

Training-1: Introduction to ADF 
http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/Introduction_To_ADF/Introduction_To_ADF.html

Training-2: Introduction to ADF Business Components
http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/adfinsiderBC/adfinsiderBC.html

Training-3: Introduction to ADF Faces Components
http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/adfinsiderADFFaces/adfinsiderADFFaces.html

Training-4: ADF Page Template and Declarative Component
http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/adfjsfreuse/templates.html

Training-5: ADF Faces Skin
http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/adf-insider-skinning/adf-insider-skinning.html

Training-6: ADF Data Binding (Part-1)
http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/insiderBinding1/BindingsPart1.html

Training-7: ADF Data Binding (Part-2)
http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/adfinsider-binding-internals-2/adfinsider-binding-internals-2.html

Training-8: ADF Task Flow - Overview (Part-1)
http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/taskflow-overview-p1/taskflow-overview-p1.html

Training-9: ADF Task Flow - Overview (Part-1)
http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/taskflow-overview-p2/taskflow-overview-p2.html

Training-10: ADF Application Security
http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/adfinsidersecurity/adfinsidersecurity.html  

Other Useful Links:

Oracle ADF Insider  - Oracle ADF Architecture Fundamentals - Angles in ADF Architecture..
http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/AngelsInTheArchitecture/AngelsInTheArchitecture.html

Tuesday, 2 April 2013

How to use subversion with jdeveloper for Oracle ADF development


It is a very rare sight that a project team with more than 2 developers doesn’t have any source control in place while working on an Oracle ADF development project.If you don’t have source control for Oracle ADF development, then your project needs a better project manager and architect :).

I had created a small project to demonstrate source control with Oracle ADF jdeveloper’s native support for subversion(SVN).We will use the code.adfapps.com for our subversion project hosting.

Below are the high level steps..

1) Create a manual connection to subversion repository from Jdeveloper

2) Click on the Application menu and say version application.

3) Select the repository connection and choose whether to version control to trunk,tags or branch(Put it in Trunk for the first time)

4) That’s it.. We are done with source control..No, there are lot of challenges still.We will cover them one by one in the 5 part series.

For now, let us look at the above steps in detail.


Step 1 : Create connection to svn repository
Step 2: Create a project with svn support in code.adfapps.com like below
Step 3: Provide the details as below for a demo svn project in code.adfapps.com
Step 4: Version the application now.

Step 5: Verify the subversion log in jdeveloper
Now we have successfully source controlled our Oracle ADF application.From now on we will use this code base to demonstrate the various features of subversion in ADF jdeveloper.

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.