All rights reserved. No part of this book may be reproduced, stored in a retrieval system,
or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: April 2013
Production Reference: 1180413
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84968-900-7 www.packtpub.com
Cover Image by Suresh Mogre (email@example.com)
Brandt D'Mello Insiya Morbiwala
Reviewers Frank Nimphius Sten E. Vesterli
Sajeev Raghavan Laxmi Subramanian Aditya Nair
Acquisition Editor Grant Mizen
Proofreaders Katherine Tarr
Lead Technical Editor Azharuddin Sheikh
Maria Gould Indexer Tejal R. Soni
Technical Editors Chirag Jani
Project Coordinator Amey Sawant
Cover Work Manu Joseph
Graphics Ronak Dhruv Valentina Dsilva
About the Author Vinod Krishnan has over eight years' experience in the Information Technology industry
this exposed him to a wide range of technologies that include Java, J2EE, WebLogic, Fusion Middleware, SOA, and Webcenter. He has been working with Oracle ADF Technologies since 2005, and enhanced his affinity towards ADF after he joined Oracle India. For the last five years, Vinod is actively involved in large implementations of next-generation enterprise applications, utilizing Oracle's JDeveloper and Application Development Framework (ADF) technologies. He holds a B.Tech. in Information Technology from Anna University, Chennai, India. He is currently responsible for building and deploying applications using the Oracle Fusion Middleware technology stack as a Project Lead in Oracle America. He is an Oracle Certified Specialist, and the technologies he has worked on include Oracle ADF, SOA, Webcenter, and Identity Management. His contribution towards Jdeveloper and ADF discussion forums is immense. With his experience, he has learned many tips and techniques that will help a new user to learn this technology without any hassles. He writes his own blog (http://vtkrishn.com) that discusses the tips and tricks with using Oracle technologies.
Vinod has had a multifaceted career, he has worked in positions such as Senior Consultant, Senior Applications Engineer, Software Engineer, and Solution Architect for MNCs such as Oracle, Capgemini, and Keane. Currently he is working as a Project Lead in Oracle America. I would like to express my gratitude to the people who saw me through this book, to all those who provided support, talked things over, read, wrote, offered comments, allowed me to quote their remarks, and assisted in the editing, proofreading, and design. I want to thank my wife, Sandhya, who supported and encouraged me in spite of all the time it took me away from her. It was a long and difficult journey for her. I would like to thank Grant Mizen, Stephanie Moss, Ameya Sawant, and Poonam Jain for helping me with the process of selection and editing. Thanks to Packt Publishing for giving me the opportunity to help and guide new users of ADF with my book.
About the Reviewers Frank Nimphius is a Senior Principal Product Manager in the Oracle application development tools group at Oracle Corporation, specializing in Oracle JDeveloper and Oracle Application Development Framework (ADF).
In his current position, Frank represents and evangelizes the Oracle JDeveloper and Oracle ADF products worldwide as a speaker at user group and technology conferences as well as in various publications. Frank runs the ADF Code Corner website, the "OTN Forum Harvest" blog, and is the co-author of the Oracle Fusion Developer Guide book published in 2009 by McGraw-Hill.
Sten E. Vesterli took up Oracle development as his first job after graduating from the
Technical University of Denmark, and hasn't looked back since. He has worked with almost every development tool and server Oracle has produced in the last two decades, including Oracle ADF, JDeveloper, WebLogic, SQL Developer, Oracle Portal, BPEL, Collaboration Suite, Designer, Forms, Reports, and even Oracle Power Objects. He started sharing his knowledge with a conference presentation in 1997 and has since given more than 100 conference presentations at Oracle OpenWorld and at ODTUG, IOUG, UKOUG, DOAG, and other user group conferences around the world. His presentations are highly rated by the participants, and in 2010 he received the ODTUG Best Speaker award. He has also written numerous articles, participated in podcasts, and has written Oracle Web Applications 101, McGraw-Hill, and Oracle ADF Enterprise Application Development – Made Simple, Packt Publishing. He is currently writing his third book on Oracle ADF Essentials.
Oracle has recognized Sten's skills as an expert communicator on Oracle technology by awarding him the prestigious title of Oracle ACE Director, which is carried by less than 100 people in the world. He is also an Oracle Fusion User Experience Advocate and sits on the Oracle Usability advisory board, and he is part of the Oracle WebLogic Partner Council as well. Based in Denmark, Sten is a partner in the Oracle consulting company Scott/Tiger, where he works as a Senior Principal Consultant. When not writing books or presenting, he helps customers choose the appropriate technology for their needs, teaching, mentoring, and leading development projects. In his spare time, Sten enjoys triathlon and completed his first Ironman in 2012.
www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at firstname.lastname@example.org for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.
Fully searchable across every book published by Packt Copy and paste, print and bookmark content On demand and accessible via web browser
Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
Table of Contents Preface1 Chapter 1: Installing and Configuring JDeveloper IDE 7 System requirements for Windows Installing JDeveloper Time for action – downloading the installer Studio edition Time for action – installing JDeveloper Studio Edition Time for action – launching JDeveloper for the first time Knowing the start-up flags/parameters Time for action – setting the start-up options Setting up the user directory (System directory) Working with IDE configuration files Knowing the roles Getting familiar with the IDE Setting the preferences Knowing the IDE components Time for action – opening the sample application Application Navigator Application Resources Data Controls palette Recently Opened Files Structure window Database Navigator The Resource palette Time for action – creating a catalog The Component palette Run Manager The Log window
Model-View-Controller How ADF implements MVC The ADF architecture Creating a simple application in ADF ADF development practice Sample application – employee directory application Time for action – creating the application workspace Planning your application Connect to a database Time for action – setting up the database tables Time for action – creating a database connection Build business services Accessing the project properties
Time for action – creating the business components Running the AM tester Exposing data to the UI layer Time for action – bind data to the UI components Time for action – running the application Summary
Chapter 3: Understanding the Model Layer
ADF business components What is an entity object? Time for action – checking the attributes of an entity object Time for action – creating an entity object for DEPT table Why association? Time for action – creating an association between EmpEO and DeptEO objects About the view object Types of view object
Time for action – creating an entity-based view object Importance of a view link Time for action – creating a view link between EmpVO and DeptVO What is an application module? Time for action – creating an application module Time for action – adding the view link to the application module Business components in action [ ii ]
31 32 33 34 35 35 36 37 39 39 41 41 42 42
43 49 50 51 57 60
61 61 63 64 66 69 70 71 72
73 77 77 80 80 81 83
Table of Contents
Time for action – running the application module Options for the business components Entity object General Attributes Business Rules Java Business Events View Accessor
83 85 86 86 87 90 91 91 91
Chapter 4: Validating and Using the Model Data Declarative validation Knowing the lifecycle of an entity object Types of validation Entity-level validation Attribute-level validation Transaction-level validation
Built-in declarative validators
97 98 98 99
99 99 100
Time for action – adding a collection validator for the DeptEO file
Time for action – creating an alternate key for DeptEO Groovy expression Setting a default value Time for action – setting a default salary for employees Validation execution Some commonly used expressions Time for action – adding a script expression Learning about APIs Generating an entity implementation class
107 108 109 109 111 112 113 115 115
The Compare validator The Key Exists validator The Length validator The List validator The Method validator The Range validator The Regular Expression validator The Script validator The UniqueKey validator
Java classes in entity objects
[ iii ]
104 105 105 105 105 105 106 106 106
Table of Contents
Time for action – generating a Java API for DeptEO
Application module API Time for action – learning to override a method Managing transactions Configuring transactions Time for action – creating configurations Exposing data Time for action – exposing a method using the client interface Summary
119 120 121 121 122 123 123 126
Classes for view objects
Chapter 5: Binding the Data
ADF model layer Data Controls palette Data control The view object collection Attributes Operations Methods Return Parameters View criteria Time for action – adding a Commit button to the UI page Working with the data control layer and binding Time for action – accessing the page definition file Creating the bindings manually Time for action – creating page definition bindings Adding executables accessorIterator invokeAction iterator page searchRegion shuttleRegion
Oracle Three Column Layout Oracle dynamic tabs shell
Creating a page Knowing the page template
Time for action – creating the page template Creating the page with the template [ iv ]
Table of Contents
Time for action – creating the dept.jspx file Layout the page display Time for action – creating the layout for the page Knowing the UI components Input components af:form af:inputText af:inputDate af:inputFile af:selectOneChoice af:selectOneRadio af:selectBooleanCheckbox
Time for action – showing a popup to the user List of values components af:inputComboboxListOfValues
164 166 166
Data visualization components Other tags EL expression
169 169 170
af:forEach af:iterator af:switcher
168 168 169
Table of Contents
Time for action – adding an EL expression Partial page rendering Summary
171 172 174
Chapter 7: Working with Navigation Flows
Task flows Task flow types
Unbounded task flow Bounded task flow
176 176 176 177
Time for action – adding a bounded task flow to EmpDirectoryApplication Task flow components
Time for action – adding a method call activity
Time for action – adding a Task Flow Return
Time for action – adding a View activity to the task flow
Router Save Point Restore Task Flow Call Task Flow Return Parent Action URL View View Control flow Wild card
Task flow options
180 183 183 183 184 185 186 186 188 188
General Visibility Based on a template Managed beans Managed properties Parameters
188 190 190 190 191 191
Time for action – passing parameters to a task flow
Task flow as a region Time for action – adding a task flow as a region ADF life cycle
194 194 195
Memory scopes Relationships between the scopes
Chapter 8: Layout with Look and Feel
Skinning essentials What is a skin? Time for action – adding a skin file to the application Skin selectors [ vi ]
203 203 204 205 207
Table of Contents Pseudo classes in the ADF skinning framework
Using the skin editor Time for action – creating an ADF skin using the skin editor IDE Extended skins Style classes Global selector aliases Faces component selectors Applying skins Deploying skins Time for action – deploying the skin file Summary
208 208 211 211 213 213 214 215 215 218
Chapter 9: Implementing Security
Chapter 10: Deploying the ADF Application
Introduction to security Basic security Time for action – implementing basic security Applying security permissions Security for business objects Security for task flows and page-related files Time for action – adding permissions Creating a login page Time for action – creating a login page Creating roles and groups Time for action – creating roles and assignments Disabling ADF security Time for action – disabling security for ADF applications Summary ADF application deployment Overview Preparing for deployment Connection Deployment profiles Time for action – creating the deployment profile MDS configuration Deployment descriptors web.xml weblogic.xml weblogic-application.xml
Deployment to the WebLogic server Integrated server Time for action – creating a default domain for integrated server Time for action – deployment to integrated server Standalone server Time for action – deploying to the standalone server Summary
Chapter 11: Advanced Features of ADF
Advanced topics on entity objects Tuning Custom properties Property sets A resource bundle Business logic groups Domain The Custom validation rule Custom error messages Advanced topics on view objects Avoid getRowCount, getEstimatedRowCount Working with Rowsets List of values Time for action – creating a list of values of a department UI categories Application module state management Complex data controls Complex task flows Contextual events Time for action – publishing an event and subscribing it Complex usage of a managed bean Debugging the application Debugging practices Exception handling Debugging the lifecycle The Metadata Services framework Customization layers Customization classes Seeded customization Runtime customization The Active Data Services framework The ADS framework [ viii ]
Modes of data transport WebLogic server configurations Domain Servers Deployments The Security realm Data sources Diagnostics Creating an extension The extension.xml file Time for action – creating and running an extension Summary
Pop Quiz Answers Index
282 282 283 283 284 284 284 285 285 286 286 288
[ ix ]
Preface Application Development Framework (ADF) 11gR2 is the next-generation JEE framework from Oracle for building robust and scalable enterprise applications. ADF 11gR2 provides out of the box infrastructure solutions that simplify application development and end user experience. Application development using ADF 11gR2 is fun as it provides a visual and declarative development experience. Some of the noted features offered by ADF 11gR2 are rich and powerful components support for rich Internet applications, Page Flow 2.0 support, drag-and-drop support for data bindings, ADF business components support, mobile development support, security implementation support, declarative development support, runtime customization, reusability support, and so on. Oracle ADF 11gR2 Development Beginner's Guide aims to provide step-by-step instructions for designing, developing, and deploying a highly scalable, secured, and rich Internet application. This book will help any user with basic programming skills to quickly learn what options are available, and how to develop web applications using ADF 11gR2. This book has been designed to help you learn basics and have fun while developing practical applications using ADF 11gR2. In this book, you will learn about developing web-based applications using ADF 11gR2 in a simple and easy way. Screenshots and practical instructions are included to make the book more interactive. This book will serve as a faithful friend to its readers.
What this book covers Chapter 1, Installing and Configuring JDeveloper IDE will teach you how to install and configure the JDeveloper IDE, and how to work with the IDE. Chapter 2, Getting Started with ADF will teach you the basics of the Model-View-Controller architecture, how ADF fits into the MVC pattern, the components of ADF, and how to build a simple ADF application.
Chapter 3, Understanding the Model Layer will teach you about ADF Business Components, how they work, and it will help you familiarize with the components. Chapter 4, Validating and Using the Model Data describes how to write business logic declaratively. Learn groovy expressions, and how to manage transactions and expose the data. Chapter 5, Binding the Data teaches you how to use the data controls and bind the data for the user interface. Chapter 6, Displaying the Data shows how to display the data in the UI using layers and components. Chapter 7, Working with Navigation Flows describes how to use page flows and activities, pass parameters, and about the ADF life cycle. Chapter 8, Layout with Look and Feel will teach you how to style the page and make it presentable. Chapter 9, Implementing Security will help in securing the page that you have created, and show how to allow and restrict access for different roles and groups. Chapter 10, Deploying the ADF Application will help you deploy the application to the server. Chapter 11, Advanced Features of ADF delves into the Advanced features of the ADF 11gR2 framework.
What you need for this book You will need a computer running either the Windows or Linux or Mac operating system with a minimum of 2 GB of RAM. A minimum of 1024 x 768 resolution is desired for development. It will be good if you have a minimum of 3 GB of hard drive space in your machine. These requirements are detailed in Chapter 1, Installing and Configuring JDeveloper IDE. An Internet connection is required to download the files. You should have modern browsers such as Internet Explorer, Firefox, or Chrome installed on your machine to test the application.
Who this book is for The book is intended for beginners who know a little bit of HTML and Java programming and would like to learn how to develop rich web applications using Oracle ADF 11gR2.
Conventions In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning. Code words in text are shown as follows: " Accept the prompt to save jdevstudio11123install.exe on your machine " A block of code is set as follows: org.apache.myfaces.trinidad.CHECK_FILE_MODIFICATION param-name> true
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold: [default] exten => s,1,Dial(Zap/1|30) exten => s,2,Voicemail(u100) exten => s,102,Voicemail(b100) exten => i,1,Voicemail(s0)
Any command-line input or output is written as follows: # cp /usr/src/asterisk-addons/configs/cdr_mysql.conf.sample /etc/asterisk/cdr_mysql.conf
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen". Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Reader feedback Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of. To send us general feedback, simply send an e-mail to email@example.com, and mention the book title via the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Errata Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy. Please contact us at firstname.lastname@example.org with a link to the suspected pirated material. We appreciate your help in protecting our authors, and our ability to bring you valuable content.
Questions You can contact us at email@example.com if you are having a problem with any aspect of the book, and we will do our best to address it.