-
Book Overview & Buying
-
Table Of Contents
Oracle JDeveloper 11gR2 Cookbook
By :
In this recipe, we will talk about how to incorporate and use the ADFUtils and JSFUtils utility classes in your ADF application. These are utility classes used at the ViewController level that encapsulate a number of lower level ADF and JSF calls into higher level methods. Integrating these classes in your ADF application early in the development process, and subsequently using them, will be of great help to you as a developer and contribute to the overall project's clarity and consistency. The ADFUtils and JSFUtils utility classes, at the time of writing, are not part of any official JDeveloper release. You will have to locate them, configure them, and expand them as needed in your project.
We will be adding the ADFUtils and JSFUtils classes to the SharedComponents ViewController project that we developed in the Breaking up the application in multiple workspaces recipe in this chapter.
1. To get the latest version of these classes, download and extract the latest version of the Fusion Order Demo application in your PC. This sample application can be found currently in the Fusion Order Demo (FOD) - Sample ADF Application page at the following address: http://www.oracle.com/technetwork/developer-tools/jdev/index-095536.html.
2. The latest version of the Fusion Order Demo application is 11.1.2.1 R2 at the time of this writing and is bundled in a zipped file. So go ahead download and extract the Fusion Order Demo application in your PC.
3. You should be able to locate the ADFUtils and JSFUtils classes in the location where you have extracted the Fusion Order Demo application. If multiple versions of the same class are found, compare them and use the ones that are most up-to-date. For this recipe, we have included in the source code the ADFUtils and JSFUtils found in the SupplierModule\ViewController\src\oracle\fodemo\supplier\view\utils directory.
4. Copy these classes to a specific location in your shared ViewController components project. For this recipe, we have copied them into the SharedComponents\SharedViewController\src\com\packt\jdeveloper\cookbook\shared\view\util directory.
5. Once copied, open both files with JDeveloper and change their package to reflect their new location, in this case to com.packt.jdeveloper.cookbook.shared.view.util.
The public interfaces of both ADFUtils and JSFUtils define static methods, so you can call them directly without any class instantiations. The following are some of the methods that are commonly used.
To locate an iterator in the bindings, use the ADFUtils.findIterator() method. The method accepts the bound iterator's identifier and returns an oracle.adf.model.binding.DCIteratorBinding. The following is an example:
DCIteratorBinding it = ADFUtils.findIterator("IteratorID");
To locate an operation in the bindings, use the ADFUtils.findOperation() method. This method accepts the bound operation's identifier and returns an oracle.binding.OperationBinding.
OperationBinding oper = ADFUtils.findOperation("OperationID");
Use ADFUtils.findControlBinding() to retrieve an attribute from the bindings. This method accepts the bound attribute's identifier and returns an oracle.binding.AttributeBinding.
AttributeBinding attrib = ADFUtils.findControlBinding("AttributeId");
To get or set a bound attribute's value, use the ADFUtils.getBoundAttributeValue() and ADFUtils.setBoundAttributeValue() methods respectively. Both of these methods accept the identifier of the attribute binding as an argument. The getBoundAttributeValue() method returns the bound attribute's data value as a java.lang.Object. The setBoundAttributeValue() method accepts a java.lang.Object and uses it to set the bound attribute's value.
// get some bound attribute data String someData = (String)ADFUtils.getBoundAttributeValue("AttributeId"); // set some bound attribute data ADFUtils.setBoundAttributeValue("AttributeId", someData);
You can get the oracle.adf.model.binding.DCBindingContainer binding container by calling the ADFUtils.getDCBindingContainer() method.
DCBindingContainer bindings = ADFUtils.getDCBindingContainer();
Use the JSFUtils.addFacesInformationMessage() and JSFUtils.addFacesErrorMessage() methods to display Faces information and error messages respectively. These methods accept the message to display as a String argument.
JSFUtils.addFacesInformationMessage("Information message"); JSFUtils.addFacesErrorMessage ("Error message");
To locate a UI component in the root view based on the component's identifier, use the JSFUtils.findComponentInRoot() method. This method returns a javax.faces.component.UIComponent matching the specified component identifier.
UIComponent component = JSFUtils.findComponentInRoot("ComponentID");
Use the JSFUtils.getManagedBeanValue() and JSFUtils.setManagedBeanValue() methods to get and set a managed bean value respectively. These methods both accept the managed bean name. The JSFUtils.getManagedBeanValue() method returns the managed bean value as a java.lang.Object. The JSFUtils.setManagedBeanValue() method accepts a java.lang.Object and uses it to set the managed bean value.
Object filePath = JSFUtils.getManagedBeanValue ("bindings.FilePath.inputValue"); JSFUtils.setManagedBeanValue("bindings.FilePath.inputValue", null);
Change the font size
Change margin width
Change background colour