Upload
berry-clemens
View
1.866
Download
4
Tags:
Embed Size (px)
DESCRIPTION
Programming tips and tricks for ADP starters in Fusion Apps
Citation preview
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 1
Oracle ADF Programming Best Practices for Beginners
Frank Nimphius
Senior Principal Product Manager
Application Development Tools
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 3
Program Agenda
Simplify Your Development Choice
ADF Business Components
ADF Task Flow
ADF Binding
ADF Faces
JavaScript
Break Out Of Isolation
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 4
Simplify Your Development Choice
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 5
Simplify Your Technology Choice Choose a Development Approach
Java EE Oriented Database Oriented SOA Oriented
RDBMS
ADF BC
ADF Binding
ADF Task Flow
ADF Faces
Data Visualization
• EJB / JPA
• ADF Binding
• ADF Task Flow
• ADF Faces
• Data Visualization
• Services
• ADF Binding
• ADF Task Flow
• ADF Faces
• Data Visualization
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 6
Simplify Your Technology Choice Common Technologies
RDBMS
ADF BC
ADF Binding
ADF Task Flow
ADF Faces
Data Visualization
• EJB / JPA
• ADF Binding
• ADF Task Flow
• ADF Faces
• Data Visualization
• Services
• ADF Binding
• ADF Task Flow
• ADF Faces
• Data Visualization
Java EE Oriented Database Oriented SOA Oriented
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 7
ADF Business Components
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 8
ADF Business Components
Application
Module
View
Object
Entity
Object
1 *
Data Model XML
Definition
View Object
Base Class
XML
Definition
Entity Object
Base Class
References References
XML
Definition
AM
Base Class
References
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 9
ADF Business Components Architecture Best Practices
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 10
Use ADF Business Components Preferences
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 11
Use ADF Business Components Preferences
EntityImpl
YourOrgEntityImpl
YourAppEntityImpl
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 12
Use ADF Business Components Preferences
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 13
Use ADF Business Components Preferences
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 14
ADF Architecture Square
Development
– Oracle ADF Development
Essentials
– ADF Code Guidelines (v1.00)
– ADF Naming and Project Layout
Guidelines (v2.00)
http://bit.ly/adfarchsquare
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 15
ADF Business Components Implementation Best Practices
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 16
General Considerations
Always create and use custom base-classes for at least
– ApplicationModuleImpl
– EntiyImpl
– ViewRowImpl
– ViewObjectImpl
Note that creating custom super classes for <object>Def classes are
less common
Custom Framework Extension Classes
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 17
Entity & View Object
Generate Java Impl files when entity objects are accessed from Java
or Groovy
Ensure code that accesses entity objects directly uses type safe APIs
instead of the generic framework APIs
Do not generate Impl classes without a need
– Keep code base size reasonable.
– Impl classes for the *def classes are rarely needed
When to generate Java Impl files
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 18
View Criteria
Not necessary to create separate VO that only differ by their WHERE
clause
Apply view criteria declaratively when defining view accessor and AM
data model instances
– Use bind variables with View Criteria
– Be aware that "Ignore Null Values" options is of bad performance
Avoid direct user input in ADF BC queries to protect against SQL
injection attacks
Prefer One View Object with Many View Criteria
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 19
Performance Tuning And Optimization
Premature optimizations as the root of all evil
– Measure Performance, don't guess it.
– If performance measures as bad, look for optimizations
Make the general assumption that ADF will probably get it right
– Consider the greater cost of do-it-yourself (DIY)
Think AM Pools!
– Good rule of thumb: One AM instance serves 10 - 15 users comfortably
– Size for peak load based on this.
Developers always strive for "better"
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 20
Read. Understand. Tune.
http://docs.oracle.com/middleware/1212/adf/
adf-monitortune.htm
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 21
ADF Task Flow
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 22
Bounded Task Flow Flows, Sub-Flows, Regions
Bounded Task Flow
Return Value
Return Value
Input Parameter
Input Parameter
Input Parameter Managed
Beans
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 23
ADF Task Flow Architecture Best Practices
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 24
Task Flow Oriented Architecture (TOA)
Think task flow from design time on
– Inventory existing task flows
– Identify patterns and standardize on them
Ensure objectives and requirements reflect task flow benefits
– Reuse, loose-coupling
Think "unit-of-work" and factor task flow functionality into subflows
– Share Data Control frame with sub-flows
– Hide sub-flows from showing in ADF library
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 25
Use Task Flow as a "Common Language"
Use task flow diagrammer as "common language"
– Use task flow templates as blue prints
– Use verbs and meaningful names in control flow case names
editOrder, createOrder, manageEmployee
Use the display and description properties of the contained
activities to explain the non-obvious
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 26
Task Flow Design
Build Composite Task Flows
– Larger task flows built out of several smaller task flows
– Only top level task flow exposed for reuse
– Encapsulates task flow dependencies
Good for distributing work among developers
Dependency management "by agreement" in smaller teams
Smaller memory foot print through load-on-demand and task flow
private memory scopes
Task Flow Sizing Considerations
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 27
ADF Task Flow Implementation Best Practices
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 28
Handling Input / Return Parameter Values
Save task flow input / return parameter values
in managed beans in pageFlowScope
– Easy to document
– Type safe API
– EL accessible
– Easy to discover and manipulate
input parameter values
– NPE protection
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 29
Managed Beans
Java classes configured in faces-config.xml, adfc-config.xml
or <task-flow-name>.xml
Managed by JSF or ADF Controller
– Java EE scopes
request, session, application
– Additional ADF scopes
backingBean, view, pageFlow
Hold code for UI related logic and data
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 30
Bounded Task Flow & Managed Beans
Always use the smallest possible scope for managed beans
– Helps Framework to "clean up" memory footprints
– Think "state"
Does the managed bean need to keep state?
If so, how long?
Don't reference managed beans in session or application scope
– Violates task flow isolation and reuse
Best Practice
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 31
Data Control Scope
Use shared data control scope as often as possible
– Less database connections
– Simplifies task flow inter-communication
– Automatic parent view collection to child task flow detail
collection synchronization
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 32
Task Flow Exception Handler
Define an exception handler activity in every bounded task flow
Leverage Task Flow Templates
– Use as Blueprint or Reference
– Define exception handlers for
all bounded task flows
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 33
What Could Happen Task Flow Exception Propagation
Memory Stack
Current Task Flow
Task Flow 4
Task Flow 3
Task Flow 2
Task Flow 1
Task Flow 2
Call
Task Flow 3
Call
Task Flow 4
Call
!
!
View1
View2
View3
View4
Task Flow 1
Task Flow 2
Task Flow 3
Task Flow 4
EH
EH
Method
Call
Current Task Flow
BANG!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 34
What Could Happen Task Flow Exception Propagation
Memory Stack
Current Task Flow
Task Flow 2
Task Flow 1
Task Flow 2
Call
Task Flow 3
Call
Task Flow 4
Call
Propagate
Exception
Propagate
Exception
!
!
View1
View2
View3
View4
Task Flow 1
Task Flow 2
Task Flow 3
Task Flow 4
EH
EH
Current Task Flow
Method
Call
BANG!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 35
What Could Happen Task Flow Exception Propagation
!
!
View1
View2
Task Flow 1
Task Flow 2
EH
EH
Memory Stack
Current Task Flow
Task Flow 2
Task Flow 1
Task Flow 2
Call
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 36
Visual Example Task Flow Exception Propagation
BANG!
!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 37
Best Practices at a Glance
Avoid cluttering diagrams for common navigation rules
Use wild card navigation for common functionality
– Cancel
– Commit
Wildcard Navigation
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 38
ADF Binding
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 39
Understanding ADF Bindings How Oracle ADF binds into JSF
Business Service ADF Data Binding
Web Service
POJO
ADF BC
EJB
JMX
TopLink
BAM UI Renderer
Component
FacesCtrl Binding
Expression Language
JSF Page
Data Control
Data Binding
ADF Faces Component Tag (<af:name../>)
Server Side JSF Component
Component Model
JUCtrl Generic Binding
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 40
Programming Against the Binding Layer
Expression Language
– Current binding layer can be accessed from #{bindings} or ${bindings}
Use from JSF components
– Populate UI component value #{bindings.firstName.inputValue}
Use from PageDef file
– E.g. access field binding value - ${bindings.firstName.inputValue}
Java
– ADF binding layer is represented by Java objects at runtime
– BindingContext.getCurrent()is the generic entry point
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 41
Use Public APIs Only
ADF classes have an API package and an IMPL package
– Define logical framework abstractions
– Simplifies implementation of future product changes
APIs in IMPL package are internal-only
– Not to be used outside of framework
– Internal packages have "internal" in the naming (It’s a clue!)
If you are not sure …
– Use EL in Java: #{bindings.allDepartments.treeModel.makeCurrent}
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 42
Understanding ADF Programming Example: Accessing the Binding Layer
import oracle.adf.model.BindingContext;
import oracle.binding.BindingContainer;
…
BindingContext bctx = BindingContext.getCurrent();
BindingContainer bindings = null;
bindings = bctx.getCurrentBindingsEntry();
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 43
Understanding ADF Programming Example: Accessing Attribute Binding
AttributeBinding attributeBinding = null;
attributeBinding =
(attributeBinding)bindings.get("AttributeName");
/* set / get value */
attributeBinding.setInputValue(value);
attributeBinding.getInputValue();
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 44
Understanding ADF Programming Example: Method and Action Bindings
//get method or action binding
OperationBinding methodBinding =
(OperationBinding)bindings.get("methodOrActionName");
//optional: if method expects arguments
Map paramsMap = methodBinding.getParamsMap();
paramsMap.put("argumentName1",value);
Object result = methodBinding.execute();
//check for errors, e.g. exceptions
List errors = method.getErrors();
If(!errors.isEmpty()){ …}
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 45
Accessing Business Service Methods
Encapsulate all model manipulation code in custom AM and/or VO
methods & invoke them declaratively
– Makes your app easier to regression test
Only code that belongs in a JSF managed bean is…
– Complex, dynamic UI component manipulation
– Complex conditional navigation
Even if you require backing bean code, invoke custom AM or VO
methods using action binding
– Guarantees uniform error handling
Best Practice
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 46
Always Work Through the Binding Layer Best Practice – Accessing Business Service Methods
PageDef
method
binding
Managed
Bean
Button
attribute
binding
Text
Application
Module
Data Model
AM Impl public void invokePlSQL()
AM Client Interface public void invokePlSQL()
Business Service Business Layer View Layer
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 47
ADF Model Error Handler
The ADF model error handler deals with
– All ADF binding errors
– Business service errors that occur when accessing a service trough the
ADF binding layer
Formats and displays error message
Default error handler skips the top-level JboException because it
only is a bundled exception wrapper for other business exceptions
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 48
Build A Custom ADF Model Error Handler
Extend oracle.adf.model.binding.DCErrorHandlerImpl and configure your custom
error error handler in DataBindings.cpx
Override the following methods as needed
– reportException
Override this method to analyze exceptions for errors you want to handle
– getDisplayMessage
Override to change or suppress (null value) the displayed message
– getDetailedDisplayMessage
Override this method to provide HTML markup formatted detail information
– skipException(Exception ex)
Called by the framework to check if an exception should be ignored
Best Practice
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 49
Configuring A Custom Error Handler
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 50
ADF Faces
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 51
ADF Faces Rich Client Components
Ajax & HTML5 enabled JSF
components
Pluggable look and feel
Accessibility & internationalization
Touch gesture support
Built-in advanced functionality:
– Partial Page Refresh (PPR),
Partial Submit
– Drag and drop framework
– Dialog and pop-up framework
Based on Java Server Faces Standard
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 52
Backing Bean
"Special use" of a managed bean
– Contain UI Component references
<af:inputText label="…" binding="#{BackingBeanName.lastNameField}"/>
– Must be defined in request scope
JSF components are not serializable (!)
Best Practices
– Avoid backing beans and perform dynamic component lookup using
FacesContext.getCurrentInstance().getViewRoot().findComponent(…)
Relative search: component.findComponent()
org.apache.myfaces.trinidad.util.ComponentUtils.findRelativeComponent(…, …)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 53
When Using Backing Beans …
Use separate beans for separate views
– Avoids "pinning" of UI components and their state
– If views are exactly identical, consider reuse
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 54
Avoid Expression Language Gotcha
EL accessing managed beans in Java EE scopes
– Request, session, application
– No scope prefix
– #{beanName}
EL accessing managed beans in ADF scopes
– backingBean, view, pageFlow
– Require scope prefix
– #{scope.beanName}, #{backingBeanScope.beanName}
Manage Bean Scope – Prefix or don't Prefix?
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 55
Put use of HTML on a "By Exception" List
HTML and JavaServer Faces are different technologies
– Markup oriented vs. component oriented
– Compile – Render, vs. multi stop request lifecycle
Facelets in JSF 2.x support mixing of HTML and JavaServer Faces
components
– Prior to Facelets and JSF 2.x, mixing HTML and JSF is a no-go
– Still with JSF 2.0 problems may occur because ADF Faces components come with
their own sizing behavior (geometry management)
Recommendation: Build pages and views with ADF Faces components
Avoid Mixing HTML and JSF components
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 56
Avoid ui:include and jsp:include Tags
ADF PageDef file is not aware of ui:include or jsp:include references
in a page or view
– Included fragments fail at runtime if they use ADF bound components
– You can copy ADF bindings used by the included content into the view's
PageDef file.
Prevents reuse of the fragments
Recommendation
– Use ui:include and jps:include for layouts only (if at all)
– Use ADF regions to add ADF bound content to a page at runtime
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 57
Use inlineStyle and contentStyle By Exception
inlineStyle property allows developers to add CSS to a component
rendering
– CSS is applied to top-level DOM component
– CSS is directly added to the page output
– Best Practice: Use ADF Faces skinning and reduce the use of CSS to the
absolute minimum (e.g. conditional color coding)
contentStyle property allows developers to add CSS to the value content
area of an ADF Faces component
– Styles component content area better than inlineStyle but has same issue as
mentioned above
Learn to Love Skinning
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 58
JavaScript
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 59
ADF Faces Client JavaScript Architecture
Label1
Label2
Label3
DOM
Peer Objects
Document
UI Components
Servlet
JSF Lifecycle
Component Tree
View Root
Form
Renderer
OK
Form
Form
UI Components
Server Side Client Side
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 60
ADF Faces Client JavaScript Architecture
JavaScript component API
af:clientListener
– Listens to DOM and ADF Faces component events
af:serverListener
– XMLHttp JavaScript call to server
– Queued as custom event on client
– Answered by managed bean
ExtendedRenderKitService
– Trinidad class to invoke JavaScript from Java
Features
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 61
Using JavaScript in ADF Faces
Use JavaScript by Exception
Don't overuse JavaScript and first try and find a solution in ADF Faces
Put JavaScript code in external *.js files
– Include using af:resource
Code against ADF Faces component model, not the browser DOM
– Component oriented vs. markup oriented
– "document.getElementById" is a serious programming mistake
Don't use JS classes in internal packages
– See JavaScript docs
Best Practice
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 62
Break Out Of Isolation.
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 63
Join A Community
OTN forum
– Best Practice
Articulate your question well
– Take the same time for asking a question that you want
forum members to spend on answering it
– Keep questions short but comprehensive
– Include your JDeveloper version
Use Google prior to asking to save time
Contribute
EMG
– Architecture, integration, concepts and infrastructure topics
– https://groups.google.com/forum/#!forum/adf-methodology
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 64
Schau Dich Schlau Make yourself a smart cookie by watching ADF Architecture TV
http://bit.ly/adftvsub
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 65
Best Practices Summary Dress For Success
Don't fight the
framework
Always work
through the binding layer
Think Task Flow
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 66
Best Practices Summary Dress For Even More Success
Use Case Matters
Join a Community
& Participate
Schau Dich Schlau!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 67
Join the Oracle ADF Community http://oracle.com/ADF
@jdeveloper
/jdeveloper ADF Insider
ADF Architecture
JDeveloper
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 68
Learn More at Oracle OpenWorld
Title Time Location
Oracle ADF and Oracle ADF Mobile: Lessons Learned
in Real-World Implementations
Wed
11:45
Marriot – Golden Gate C3
Hands-on Lab: Developing Mobile Applications with
Oracle ADF Mobile
Wed
10:15
Marriot – Salon 12
One Size Doesn’t Fit All: Oracle ADF Architecture
Fundamentals
Thu
11:00
Marriot – Golden Gate A
Related sessions and labs
Oracle ADF booth at the Oracle Demo Ground – Moscone South
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 69
Graphic Section Divider
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 70