Java · Open Source Software · Oracle ADF · Oracle Webcenter · Technology

Oracle Fusion ADF – JSF Rich Text and Table Component (Data Input and Refresh)


Goal:

The ADF framework is quite powerful and you should be able to quickly create a page that will let you do Partial Page Rendering (PPR) in no time … there are plenty of good examples online about  how to do this (and you should be able to work things out on your own in no time).

However, my problem was that by using out of box “Partial Triggers” property on the table component, I was unable to “re-query” the underlying table model.  Instead, I used an explicit call to the underlying UI controls and ended up learning quite a bit in the process.

Build a very simple example with a basic java “Map” data model to accept “key/value” data pair as inputs on a page and display the growing “list”/”map” as a table below. Use framework based or custom built Partial Page Rendering (PPR) to refresh the table and tie this to the “Submit” button on the page.

The example below should walk you through a very basic ADF web application build using plain java classes to demonstrate MVC interaction in this framework.

Please Note: In an effort to quickly pen down my observations, the first draft might be not-so-polished.  I will work on refining this post over time.

Here’s what I was thinking of building/experimenting with:

<img class="alignnone size-full wp-image-363" title="Sample Page – Table from a List” src=”https://techiecook.files.wordpress.com/2011/02/page-view.jpg” alt=”” width=”489″ height=”285″ />

Outline

The application is a very simple, two project fusion web app. It has a Model and View project – the model was started from a POJO Service class (I don’t use any patterns to ensure that multiple instances of the service class refer to the same data model etc – it is very basic).

Here’s how you might build a service class … and after you are done – right click and create a Data Control

…. right click on the Service Java Class, to create/update the DataControl,  and select “Create Data Control”

The overall project will look something like this:  Data Controls built from the POJO service will be available to the UI via Data Bindings. The page will consist of 3-4 components (two Rich Input Texts, One Button and One Table). The page (and its 3-4 components) will be backed by a custom bean (Managed Bean) , that is …. there will be a “Java class” with RichInput Text fields, RichTable field and methods that accept ValueChangedEvent etc. There will be a definition in the ADF config file about this class which will tie this to the JSF page so that details of the fields are available to the class (as you change it on the screen) and when you click the button component on the screen it invokes a method on the class.

PPR – Using out-of-box features

As explained above, the page bean has the meat of the logic. We could have entirely avoided this using out-of-box PP, this is done by clicking on the Rich Component (you want to be refreshed) and  under “Properties -> Behavior” selecting “Partial Triggers” to specify a trigger that will cause a partial page refresh for this component.

Once you click on Edit – the wizard opens and you can use it to select “which component causes the trigger” …

PPR – Using custom method in page bean

The bean class,  notice:

  • the fields and  their accessors/mutators
  • the methods with ValueChangeEvent – these are tied to the RichTextInput components changing
  • The “cb3_action” method – this one is tied to the “button” on the page.  This calls the “refresh table”. Details on the method’s comments.

Code to handle the button event:

public String cb3_action() {
 // Should be final Strings in a shared class
 String insertMethodInPOJO = "insertIntoStringTable";
 String paramNameForKey = "key";
 String paramNameForValue = "value";

 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // Steps to execute a method as defined in a Data Control
 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 BindingContainer bindings =
 BindingContext.getCurrent().getCurrentBindingsEntry();
 OperationBinding operationBinding =
 bindings.getOperationBinding(insertMethodInPOJO);
 // mKey and mValue are instances of RichInputText class
 operationBinding.getParamsMap().put(paramNameForKey, mKey.getValue());
 operationBinding.getParamsMap().put(paramNameForValue,
 mValue.getValue());
 Object result = operationBinding.execute();

 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // REFRESH the table
 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 refreshTable();

 if (!operationBinding.getErrors().isEmpty()) {
 return null;
 }

 //do Something with the errors
 return null;
 }

The table refresh code

/***
 * REFRESH Table Model:
 *    Grab the Collection Model, Get the JUCtrlHierBinding, Execute Query to force refetch
 */
 public void refreshTable() {
 CollectionModel cm = (CollectionModel)richTableBinding.getValue();
 JUCtrlHierBinding tableBinding =
 (JUCtrlHierBinding)cm.getWrappedData();
 tableBinding.executeQuery();
 }
Advertisements

One thought on “Oracle Fusion ADF – JSF Rich Text and Table Component (Data Input and Refresh)

  1. Hi,

    Thanks mate I was looking for this table refresh code. Any way the 1st method(partial triggers) didn’t worked for me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s