Valuable Java, JavaScript and ADF resources image11

Valuable Java, JavaScript and ADF resources

In the past few days, I have been working hard on several projects – both ADF and (plain) Java based, with quite a bit of JavaScript involved as well. The three main functional challenges:

  • support keyboard (function key based) navigation in rich ADF Web pages (in addition to mouse based actions)
  • support online and inline editing of customized (per context) resource bundle entries
  • create a stand-alone viewer that allows users to inspect images (jpeg, tiff), PDF documents and Word and Excel documents

While working on these requirements, I have used – through Google, my main tool – a large number of very valuable resources on the internet. From the Oracle Technology Network Forums (OTN) to StackOverflow (, from personal blogs to corporate white papers as well as formal documentation – I have picked an incredible number of brains in a very condensed period of time.

I did not stop to leave notes of gratitude on all the sites I have come across. So I thought – for my own future reference as well as to pay some hommage to all these sites and individuals that helped me and to provide some insight in what challenges I faced and how I addressed them – to write down some notes on my explorations. They may be helpful to some of you as well.

Regular Expressions in JavaScript

I had a need to find all  :<SomeNumber>: occurrences in a string (actually a complex component id inside a table). For example: extract :34:, :45: and :3: from someElement:34:child:parent:45:aaa:higher:3:andmore. I started with this article on Stack Overflow: and continued with – a clear explanation on how the match operation can be used on strings in JavaScript to do a Regular Expression based search and have multiple results returned. The code I ended up with:


Regular Expression in Java

A similar situation in (server side) Java code: how to find numbers surrounded by colons in a string. In a manageable and performant way. StackOverflow helped me with some insights into Pattern and Matcher ( This quickly gave me what I needed. This other article warned about the performance costs of compiling the Pattern and suggested the use of a private static to compile the pattern only once: One of my favorite authors of course published a great article on Regular Expressions in Java – by Lars Vogel – only this time it gave me much more than I needed.

The Java snippet that in the end found its way into my code:



Keyboard short-cuts in major browsers

One of the projects I am involved in has a requirement to provide users with familiar key combinations- familiar that is from a previous generation technology based application – for key functions in the brand new web application. Unfortunately, as it turned out, many of those familiar function keys are not available in (all) modern browsers. Keys such as F3 and ALT+F are hijacked in all major browsers, as are F12 and Shift-F12. F4 is already reserved in IE – though not in Chrome and Firefox. So the list goes on – whatever the end users considered familiar, was typically not available in at least one of the browsers we have to support.

The complete lists of function keys – for easy reference – are on these URLs:

Programmatic Manipulation of ADF Tables

Programmatically moving around in ADF Tables is not a trivial thing. There is some support for doing things on the client side – but these are not well documented and I was not able to get to work as expected some of the things that are documented. The holy grail I was after was to provide end users with easy key combinations that allow navigation to the next and previous record as well as the first and last record in the (editable!) table. Of course navigation in the table should be synchronized on the server with navigation in the underlying iterator as well as associated (detail) iterators and dependent client components. Some of the resources I have consulted on ADF Table manipulation:


Viewing various Document Types in Java

While Java (Swing, AWT and more recently JavaFX) offers various out of the box facilities for displaying different types of files, for other file types we will need to use additional libraries and tools. Some findings on this:

OpenOffice has (Java based) programmatic facilities for converting Word and Excel files to OpenOffice format and from OpenOffice format to PDF. Some tools and libraries have been published that leverage those facilities. This article describes the API in OpenOffice that can be used for exporting PDF documents:

docx4j is a Java library for creating and manipulating Microsoft Open XML (Word docx, Powerpoint pptx, and Excel xlsx) files. See:  It can export DOCX documents to PDF.

PDF previewer in Java: . LGPL edition of jPedal:

Example of loading and displaying an image in a JavaFX 2.0 application:

jPedal JavaFX 2.0 PDF Viewer – – provided under LPGL license. Discussion on showing PDF from JavaFX on OTN Forum:

Open source project JODConverter, the Java OpenDocument Converter, converts documents between different office formats.
It leverages, which provides arguably the best import/export filters for OpenDocument and Microsoft Office formats available today. (Word to PDF; Excel to PDF; PowerPoint to PDF) :

Java Advanced Imaging API Home Page : (for working with TIFF images)


Some important observations I should remember:

  • putting focus on a component too quickly can easily happen with JavaScript being executed after returning from a partial page refresh request – the actual creation of the component seems to lag sometimes a little bit behind. A good way of working around this problem is by deferring the execution of the code that puts the focus, through the use of a JavaScript Timer – for example setTimeOut(function () { codeToExecute; , 250)
  • debugging Java classes that have been imported from an ADF Library can be done by deploying the sources to a normal JAR that is imported as well – see:
  • Useful snippets for doing API stuff with ADF: (How to access the ADF definitions using Managed Bean by Ankit Shah) and (Some handy code for backing beans ( ADF & JSF )  by Edwin Biemond)
  • The locale can be set in JSF using: FacesContext.getCurrentInstance().getViewRoot().setLocale(locale); At ADF level, you can use:
    BindingContext.getCurrent().setLocaleContext(new DefLocaleContext(locale));