JSF/ADF and the browsers’ back button

When you’re developing a JSF or ADF Faces application and your giving your customer a first testing-experience, you’ll notice the browser’s back button is a very interesting functionality used by a lot of end-users.

JSF saves the state of every page loaded in a browser, which means everytime a user clicks the browser back button, JSF loads the saved state of the target page.

You will also notice that the application is behaving very weard and unpredictable and you as a developer will need to solve the problem.

Possible solutions:

  1. Integrate the needed java script functionality to display the application in a full screen window (back button isn’t displayed anymore)
  2. Define no-caching on your web application using the phaselistener (jsf api’s)
  3. The user needs to refresh the page he ‘backed to’ => maybe this isn’t an option when I’m talking about developers and customers ;o)
  4. Use ‘enableTokenValidation=false’ within an ADF Application
  5. Define the needed state- and session-parameters in your jsf’s configuration file, read following post

I still think, when talking to collegues, browsing the internet/communities etc., you need to tell the customer that when using the back button, unexpected behaviour can occure in the application. Using bread-crumbs, task-oriented applications, separate crud-pages, etc. the customer won’t be that easily temped to use the back-button.

How to Integrate Bpel Processes with a User Interface

There are different ways to call/instantiate bpel processes from a front-end application.
Depending on the customers’ knowledge and expertise the choice between the different solutions can be made accordingly.

In this blog-post I will explain some of these options in short:

  • Call Bpel Process from Java-Code:

String input = “1450”;

// Here you need to define the request-operation of your bpel process

String xml =
“<asyncloanflowprocessrequest
xmlns=”http://xmlns.oracle.com/AsyncLoanFlow”&gt;
<input>”+input+”</input></asyncloanflowprocessrequest>”;

Locator Locator locator = new Locator(“default”,”bpel”);
IDeliveryService deliveryService = (IDeliveryService)locator.lookupService(IDeliveryService.SERVICE_NAME);

// construct the normalized message and send to Oracle BPEL Process Manager
NormalizedMessage nm = new NormalizedMessage();
nm.addPart(“payload”, xml );
deliveryService.post(“AsyncLoanFlow”, “initiate”, nm);

  • Call Bpel Process from your User Interface (JSP, JSPX, JSF, …):

This means you need to define the same code as defined in the above java-sample
in a jsp-script tag.

  • Use the Databinding layer of ADF Faces to integrate the Faces Application with your Bpel Process:
  1. Create BPEL WebService DataControl defined on the WSDL-endpoint of the BPEL Process


  2. Create new JSF JSP page
  3. Drag & Drop UI Components based on DataControl
  4. Run
  • Define a Web Service Proxy on your deployed Bpel process:

  1. Create WebService Proxy defined on the WSDL-endpoint of the BPEL Process

  2. Create new JSF JSP page
  3. Call the Web Service Proxy Service from your backing-bean code to initialize the deployed bpel process. Bind this method to the submit/invoke/initiate-button when you want to call the bpel process.
  4. Run

Other options can be explored as well, but these are the most common ones to think of.

JDeveloper Tips & Tricks

In the different projects I’ve worked on the past few years, I’ve always worked in an Oracle-Java environment. This means I’ve always used an Oracle Database, mostly JDeveloper as my IDE environment and deploying to an OC4J instance or an Oracle IAS instance.

During these projects different issues arose regarding business requirements we needed to implement using JSF/ADF or deployment-issues when porting a 9i application to 10g environment, …

I’ve tried to keep my own cookbook regarding these different issues we’ve faced and how we resolved them.

In this post you will find different challenges we’ve addressed regarding working in an Oracle-Java environment. Please feel free to comment and add challenges/issues to the list !


You want to open up documents in a new screen, such as pdf-documents or word-documents
Use ‘targetFrame=_blank’ for a goLink to open the link in a new window

Refresh a table-component when a dropdown-component is changed, a filter.
To refresh a table given a pre-defined filter you can use the following components ‘selectOneChoice’ with a table-component and this table-component holds a partial-trigger which listens to the ‘selectOneChoice’-component. This means you will use the partial-page-rendering feature of jsf which only render the table-component on the page and no other components.

Buttons aren’t shown correctly on a linux environment when using a custom skin
ADF Faces generates images on the fly for the different widgets (buttons, tabs, …), in the different languages, if it’s a multi-lingual application. The buttons, f.ex. are not standard HTML buttons, but GIF images. They are created in a cache directory
(\public_html\WEB-INF\temp\adf\images\cache\\) and then reused for the next runs.

The generation of the image may fail, f.ex. because the physical font is not available on your OS.
In the case of a button, it will then be generated as a standard HTML button, instead of an empty image, with no text.

Change font to “Dialog” instead of using “Arial, Helvetica’ because “Dialog” is a special font, a virtual font, that doesn’t depend on any physical font installed on your machine.
If the application runs in a Linux environment, you need to use either a virtual font, f.ex. Lucida, or a font physically installed on your Linux system

Navigation between pages without validation-exceptions being thrown
You want to be able to navigate away from a creation-page but the validation-exceptions are always triggered => use ‘immediate=true’ attribute on the command-link or the menutab-component so validation isn’t fired
You’re getting ‘current rowkey has been modified’-exceptions, set the enableTokenValidation-attribute on the pageDefinition-file to false so rowkey-validation isn’t performed

Delete files from Jdeveloper or exclude files from the Jdeveloper project
If you want to delete files from your project make sure to use the ‘File-menu’ ‘Erase from disk’ instead of the delete icon in your application navigator. If you use this delete-icon this means an exclude-option is added to your project-properties so the files aren’t shown anymore, but they still exist.

Your application does not work as expected
Try stopping OC4J, clean up the workspace (go to run-menu and choose clean-up), rebuild the entire workspace and run again.

When running the page, the browser remains empty
Apply the same steps as for the previous problem: ‘Your application does not work as expected’
Delete the WEB-INF/temp folder from the view-project and test the application again

The JSPX Design Editor looks strange

If you see this in the JSPX Design Editor:

Then JDeveloper does not properly recognize the Faces tag libraries.
You can try to click the refresh button (indicated by the arrows in the screen shot above).

If that does not work:
1. Close all JSPX’s in JDeveloper.
2. Go to the ViewController Project, to the Project Properties, and then to the JSP Tag Libraries category.
3. Remove all JSP Tag Libraries. When asked to remove other Tag libraries, click OK, but when asked to remove Java libraries click Cancel.
4. Close JDeveloper and open it again.
5. Add the tag libraries
o JSF Core
o JSF HTML
o ADF Faces Components
o ADF Faces HTML
6. Rebuild the ViewController project
7. Open the JSPX again.

Exporting table-date (master or master-detail) to Excel in an ADF-Faces application
Using your ‘FacesCtrlRangeBinding’ the table-component in your pageDefinition-file, you can export the data to an Excel-file. If you have a table that needs to be exported to Excel and when there are columns that you don’t want as a part of the export, create a new table binding in the pagedef with the right columns and use the name of the new table binding as a parameter of the ExportToExcel method in the backing bean of your page.

This could be the case when a calendar object is displayed in the table, typically you will want to use a dateAsString field in the exportToExcel.

You will find the code to support this functionality below; if you have any questions please comment.


You’re getting the following error when trying to connect to an Oracle Database via JDBC:
Error initializing connection: ORA-00604: error occurred at recursive SQL level 1 ORA-12705: invalid or unknown NLS parameter value specified

When you take a look at this URL: http://www.oracle.com/technology/products/jdev/htdocs/10.1.3.0.3/readme.html#ide5
The next topic is very important regarding this issue:
ORA-604/ORA-12705 Error on Some Unsupported Locales in JDBC (4704421)
Make sure you’re not defining a Locale that isn’t supported by JDK 1.5, have a look at the ‘supported locales’ in the JDK 1.5 specs: http://java.sun.com/j2se/1.5.0/docs/guide/intl/locale.doc.html.

Classpath-issues when deploying an application to OC4J or IAS
When you have a look at the OC4J DeveloperGuide (http://download.oracle.com/docs/cd/B31017_01/web.1013/b28952.pdf), more specifically at chapter Executing Queries at Runtime Through the ClassLoading MBean (page 53). You will find EM has all the needed functionality to have an in depth view of the class loading of your specific project.

An example mentioned in the developer guide:

Executing Queries at Runtime Through the ClassLoading MBean
Queries can be
executed on a running OC4J instance by calling the executeQuery operation on the
ClassLoading MBean.
This MBean is accessible through the Web-based
Application Server Control Console interface. See the Oracle Containers for J2EE
Configuration and Administration Guide for details on accessing and using the
MBeans packaged with OC4J.
1. Click the Administration link in the
Application Server Control Console.
2. Click System MBean Browser.
3.
Expand the ClassLoading node in the navigation pane, then select the singleton
MBean instance.
4. Click the Operations tab in the right-hand pane, then
click the executeQuery operation.
5. Enter the name of the query you want to
execute as the value for queryClassName. For example, LoaderTree.
6. Click
the queryArguments icon, then add a new row for each argument you want to
specify. Do NOT enclose arguments in parentheses; these are added automatically
when the operation is invoked. Click OK when finished specifying
arguments.
7. Click the Invoke button to call the operation.

In the chapter ‘Troubleshooting Class-Loading-Related Problems in OC4J’ an explanation is given about the different exceptions that may occur and how to solve them.

Compiler-errors when checked “Use Javac” Compiler option in the Project Properties dialog
This problem has been reported asBUG 6311285 – OJC ALLOWS CASTING OF GENERIC OF IMPL CLASS TO GENERIC OF INTERFACE CLASSA fix is already included with JDeveloper 11.1 Developer PreviewAs a workaround you can use javac instead of ojc for compilation. javac will report such wrong assignments. You need to compile with ojc only if you want to use JDeveloper profiling or code coach.
For more information have a look at the following forum-thread: http://forums.oracle.com/forums/thread.jspa?threadID=537140

Memory Leaks in Jdeveloper:

1)Check the Virtual Memory used by Jdev: edit jdev.conf and increase the JVM memory ( tag AddVMOption).

2)Don’t load technologies you don’t need ( Jdev Preferences – Extension Manager- Extension to Use ).

3)Uncheck the “bells” in Jdev Preferences:Environment: splash scren, silenty reload, decrease undo level;Diagrams: automatically straighten lines

4)Split the project up into different modules: User Management – Reporting – Administering Site – …

No tip but just fun: SOA Facts.

Invoke an ESB Service in your User Interface and display the response of this service

How can you bind an ESB Service in your User Interface and more specifically how can I call an ESB Routing Service and get the Result back in my UI?

Let’s say I’m developing a JSF Application and I want to use my existing ESB Services for my binding layer. The way you bind a webservice inside a JSF Application can be resolved in 2 different ways:

  • Create a Webservice Data Control
  • Create a Web Service Proxy and call the endpoint of the webservice with a valid parameter using for example a backing bean

OK, now I’m able to call an ESB Service but how can I get the response of this service back into my User Interface …

You need to create a two-way ESB Routing Service, meaning you need to define a request- and response-operation in your routing service.
E.g. You’re invoking a select on a table and the resultset needs to be displayed in your UI. In other words you want to show a list of employees in your user interface, and this list is bound to an esb service.

The steps you need to perform to get this working:

  • Create a new ESB Project
  • Define a system/group for you Esb Services (in this way it isn’t published to the default system)
  • Create a Database Adapter where you define a select statement on a given table
  • Define a new Routing Service where you define the request parameter, being the selectInputParameters-tag which is provided in the xsd that was generated for your DB Adapter and the reply parameter of the Routing Service is the collection returned by this same xsd.
  • Publish the ESB Service to your ESB Server

Now you can test this ESB Service to see that the resultset of the database adapter is returned by your routing service.

The next step is to define a UI where we can call this ESB Service, the steps you need to perform:

  • Create a new project and define a new JSF-page in this project
  • Create a Web Service Data Control ‘which can be found in the ‘Business Tier’ categorie of the ‘new gallery’
  • In step 1 you need to define a meaningfull name for the web service and in the URL you need to copy/paste the ‘Concrete WSDL URL’ of your routing service which is available through the ESB Control’. Then click browse to get the methods/operations available in the ESB Service and click next
  • In step 2 you need to choose the operation ‘execute’ and add it to the ‘selected’ area, click next
  • Click finish

Now you’re almost there, you’ve defined the web service data control which let’s you bind your UI to your ESB Service. The last thing you need to do now is to create a jsf-page and drag and drop your object inside the jsf-page:

  • Create a JSF-page
  • Drag-and-drop a PanelPage component inside the JSF page to have a nice lay-out
  • Go to the Control Palette and choose the ‘employees’-collection, your resulting objects of the db adapter, and drag-and-drop it into your jsf page.
  • Choose a table-component to have a nice view of your data

And now it’s show time … run the page in your embedded container and have a look at how esb services can be seamlessly integrated into your UI.

Create a demo using EJB 3.0, Toplink and ADF as the UI layer and Bpel and ESB as the back-end layer (through web service invocation) – Episode 1

The case I worked out for my demo application is the following: Create a new person via the UI (using JSF and EJB3.0 as data-layer) and initiate a bpel process for the creation of the person. The bpel process will check if all business requirements were met for the person that needs to be created using Business Rules.
A human task was added to make sure the Personal Manager has approved the new person and finally an ESB was added to actually create the person.
The ESB will transform the person-object, an xml-file, to the specific format I need to be able to insert the person in my db.

During the creation of my demo-project I faced some design problems which I will explain in the following chapters:

The first part of the case was simple, create a UI using EJB 3.0 and ADF Faces using JDeveloper as my IDE.
The UI consists of a ListPersons.jspx – page that lists all existing persons of my persons-db and a link to the CreatePerson.jspx-page. In the CreatePerson.jspx page I will create a new Person and initiate the bpel process from here.

But it wasn’t as simple as I thought … to be able to initiate my bpel process using the EJB-objects I needed to prefetch the sequence-value needed for uniquely identifying the person-object, e.g. the Person.personid. This is needed because the bpel process needs all xml-tags to be filled in. If for example the personid, or firstname isn’t filled in you will get the following exception ‘unexpected null value for literal data’.

To be able to prefetch the id in my EJB i thought I could ‘eagerly fetch’ this id using an annotation in EJB 3.0, but there’s no such annotation available :(

What to do next … fetch the sequence value myself and populate the Person.personID with my sequence-value.

I’ve added a new method in my SessionBean that gets the sequence value from my db-sequence, this method is invoked from my custom-method ‘createPersonObject() which constitutes a valid person-object.

The custom-method to fetch the sequence-value uses the ‘createNativeQuery’-method on the EntityManager:

em.createNativeQuery(“select person_seq.nextval from dual”);

The UI now works correctly, using the createPersonObject()-method as binding-layer to go to the CreatePerson.jspx file.

Now I need to link my existing Bpel Process to this UI … coming up soon …