Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Oracle JDeveloper 11gR2 Cookbook

You're reading from   Oracle JDeveloper 11gR2 Cookbook Using JDeveloper to build ADF applications is a lot more straightforward when you learn through practical recipes. This book has over 85 of them to take you beyond the basics and raise your knowledge to a new level.

Arrow left icon
Product type Paperback
Published in Jan 2012
Publisher Packt
ISBN-13 9781849684767
Length 406 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Nick Haralabidis Nick Haralabidis
Author Profile Icon Nick Haralabidis
Nick Haralabidis
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Oracle JDeveloper 11gR2 Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
1. Preface
1. Prerequisites to Success: ADF Project Setup and Foundations FREE CHAPTER 2. Dealing with Basics: Entity Objects 3. A Different Point of View: View Object Techniques 4. Important Contributors: List of Values, Bind Variables, View Criteria 5. Putting them all together: Application Modules 6. Go with the Flow: Task Flows 7. Face Value: ADF Faces, JSF Pages, and User Interface Components 8. Backing not Baking: Bean Recipes 9. Handling Security, Session Timeouts, Exceptions, and Errors 10. Deploying ADF Applications 11. Refactoring, Debugging, Profiling, and Testing 12. Optimizing, Fine-tuning, and Monitoring

Using ADFUtils/JSFUtils


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.

Getting ready

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.

How to do it…

  1. 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. 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. 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. 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. 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.

How it works…

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.

Locating an iterator binding

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");

Locating an operation binding

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");

Locating an attribute binding

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");

Getting and setting an attribute binding value

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);

Getting the binding container

You can get the oracle.adf.model.binding.DCBindingContainer binding container by calling the ADFUtils.getDCBindingContainer() method.

DCBindingContainer bindings = ADFUtils.getDCBindingContainer();

Adding Faces messages

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");

Finding a component in the root view

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");

Getting and setting managed bean values

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);
You have been reading a chapter from
Oracle JDeveloper 11gR2 Cookbook
Published in: Jan 2012
Publisher: Packt
ISBN-13: 9781849684767
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime