building a custom oracle adf component

55
Custom ADF Components Deep Dive

Upload: wilfred-van-der-deijl

Post on 16-Jul-2015

642 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Building a custom Oracle ADF Component

Custom ADF ComponentsDeep Dive

Page 2: Building a custom Oracle ADF Component

About Us

Richard OlrichsMNwww.olrichs.nl@richardolrichs

Wilfred van der DeijlThe Future Groupwww.redheap.com@wilfreddeijl

Page 3: Building a custom Oracle ADF Component

Agenda

● Live Demo Custom ADF Component● How to use● Deep dive code roundtrip

○ server side java, css, client side javascript○ client and server events

● Lessons Learned

Page 4: Building a custom Oracle ADF Component

Live DemoCustom ADF Component

Page 5: Building a custom Oracle ADF Component

How to use

Page 6: Building a custom Oracle ADF Component

Setup Consuming Project

Page 7: Building a custom Oracle ADF Component

JSF Tag

● Facelets Tag(or JSP Tag for 11.1.1 and backwards compatibility)

Page 8: Building a custom Oracle ADF Component

Let’s Build ItServer Side

https://github.com/wvanderdeijl/adfcomponent (=http://bit.ly/adfcomp)

Page 9: Building a custom Oracle ADF Component

Component

FacesBean

Renderer

Skin

Component

Peer

Event

ItemSelectEvent

Server Side

Client Side

Page 10: Building a custom Oracle ADF Component
Page 11: Building a custom Oracle ADF Component

Facelets Tag Library - rh.taglib.xmlIdentifiers, not Java classes

Component Attributes

Page 12: Building a custom Oracle ADF Component

faces-config.xml - Faces Component

Maps Component-Type identifier to implementing Component Java Class

Page 13: Building a custom Oracle ADF Component

have ADF super classes do the heavy work

holds all state

key per attrreturnType & defaultValue

group of components that typically share a renderer

Page 14: Building a custom Oracle ADF Component

Getters & Settersfor component

properties

Page 15: Building a custom Oracle ADF Component

Component Class

● Server side instance○ what MyBean gets via MyBean.setSelector() with

binding=”#{myBean.selector}”● Setters and Getters for all properties● Internally keeps state in FacesBean with

setProperty, getProperty○ gives automatic state saving of JSF component tree

between requests and on failover in cluster

Page 16: Building a custom Oracle ADF Component

MultiSelect componentsetId, setValue, setItemSelectListener,

setPartialTriggers

Add custom rule to set from super class

Page 17: Building a custom Oracle ADF Component

Facelets Handler Class

● Supplies rules to automap facelets tag attributes from XML file to component class properties

● Needed custom rule to support our ItemSelectListener attribute as Oracle’s ADF version only works for listeners from oracle.adf.view.rich package

Page 18: Building a custom Oracle ADF Component

Component

FacesBean

Renderer

Skin

Component

Peer

Event

ItemSelectEvent

Page 19: Building a custom Oracle ADF Component

faces-config.xml - Renderer

ComponentFamily and RendererType from component used to lookup RendererClass

Page 20: Building a custom Oracle ADF Component

Which properties to expect from rendered component

Find property keys once and describe client side props

Page 21: Building a custom Oracle ADF Component

Encode the Item

Start of the HTML component

Add ADF skin

<input type=”hidden” value=”[0,1,2]”/>

Page 22: Building a custom Oracle ADF Component

render <li> for each itemwith <button> to select and <span> for delete

Page 23: Building a custom Oracle ADF Component

Component selector

pseudo selector

http://myfaces.apache.org/trinidad/devguide/skinning.html

style subclassing

Page 24: Building a custom Oracle ADF Component

Apache Trinidad Content Compression

Off

On

Page 25: Building a custom Oracle ADF Component

Component Renderer

● encodeAll method generates the HTML for the Component.

● ADF Skin (including compression)○ more powerful than plain CSS○ skinning properties for Renderer like -tr-open-

animation-duration○ relative colors: background-color: +#333333

● Renderer lookup based onFamily & RendererType from component

● Taglib custom tag can override RendererType and thus re-use same component with different Renderer

Page 26: Building a custom Oracle ADF Component

Component

FacesBean

Renderer

Skin

Component

Peer

Event

ItemSelectEvent

Page 27: Building a custom Oracle ADF Component

Let’s Build ItClient Side

Page 28: Building a custom Oracle ADF Component

Subclass from base ADF components

Client Side JavaScript Component

Additional methods for client-side interaction with the component

Page 29: Building a custom Oracle ADF Component

Server-side Renderer determines Client JavaScript Component

Page 30: Building a custom Oracle ADF Component

ADF JavaScript Partitioning

ADF only downloads and runs needed JScore.js and any needed features

Dependency JS Client Constructor (defined by Renderer)

Page 31: Building a custom Oracle ADF Component

Component Peer ClassCreates the

RhMultiSelectPeer

Use client side ADFLogger

Register this Peer to ClickEvent

Register this RhMultiSelectPeer for RhMultiSelect component

Page 32: Building a custom Oracle ADF Component

Best practice: assert for correct types

Clicked delete icon

Hidden input[0,1,2] ⇒ [0,2]

DOM interaction

Click button to select: Queue event to propagate to server

Page 33: Building a custom Oracle ADF Component

Client Side Select Event [1/2]

Call superclass initializer with our event name

getters and setters for client side interaction with event

Page 34: Building a custom Oracle ADF Component

Client Side Select Event [2/2]Queue event (called by Peer)

Page 35: Building a custom Oracle ADF Component

Client ComponentRhMultiSelect.js

● Client-side representation of a server-side component

● Public client-side API● Component state: Property container with

support for event handling● All ADF Faces JavaScript classes are

prefixed with Adf to avoid naming conflicts with other JavaScript libraries

Page 36: Building a custom Oracle ADF Component

Peer responsibilities:● DOM initialization and cleanup● DOM event handling● Geometry management● Partial page response handling● Child visibility change handling● Stateless private implementation

Client Peer ObjectRhMultiSelectPeer.js

Page 37: Building a custom Oracle ADF Component

Component

FacesBean

Renderer

Skin

Component

Peer

Event

ItemSelectEvent

Page 38: Building a custom Oracle ADF Component

Handle HTTP postsServer Side

Page 39: Building a custom Oracle ADF Component

Renderer Incoming HTTP Post

Detect submitted value

set Component’s SubmittedValue

Page 40: Building a custom Oracle ADF Component

RestoreView

ApplyRequestValues

Process Validations

UpdateModelValues

InvokeApplication

RenderResponse

Renderer invokesEditableValueHolder.setSubmittedValue()

SubmittedValue is converted to datatype of underlying model and stored in component’s “Local Value”

JSF component’s “Local Value”written to ValueExpressioneg. #{bindings.something.inputValue}

Invoke queued Listeners

JSF Lifecycle

Renderer uses SubmittedValue,

“LocalValue” or “ModelValue”

Page 41: Building a custom Oracle ADF Component

Renderer Incoming HTTP Post

Queue server-side ItemSelectEvent when receiving client itemSelect event

Page 42: Building a custom Oracle ADF Component

MultiSelect JSF Component Class

Page 43: Building a custom Oracle ADF Component

Managed Bean Event Listener

Page 44: Building a custom Oracle ADF Component

Renderer - Wrap up

● Renderer decodeInternal() decodes the incoming http request○ check if component value is submitted in this

request. If so, pass on to JSF component○ check for inbound events in the request

Page 45: Building a custom Oracle ADF Component

Component

FacesBean

Renderer

Skin

Component

Peer

Event

ItemSelectEvent

Page 46: Building a custom Oracle ADF Component

Documentation

Page 47: Building a custom Oracle ADF Component

Starting point (11.1.2.4)

http://docs.oracle.com/cd/E37975_01/web.111240/e16181/ad_custom.htm#CHDJIEDB

Page 48: Building a custom Oracle ADF Component

Documentation

● Full Github sample - http://bit.ly/adfcomp● ADF Web User Interface Dev Guide 11.1.2.4

○ 31 - Creating Custom ADF Faces Components● ADF Web User Interface Dev Guide 12.1.3

○ 4 - ADF Faces Client Side Architecture○ Appendix A.2 - web.xml parameters○ Appendix F.1.1 - adf-js-partitions.xml

● ADF Skin Editor Dev Guide 12.1.3● Apache Trinidad Skinning● JSF 2.1 Reference Documentation● ADF Source Code

○ available from Oracle Support

Page 49: Building a custom Oracle ADF Component

Questions

Page 50: Building a custom Oracle ADF Component

Hidden Backup Slides

Page 51: Building a custom Oracle ADF Component

JavaScript

● JavaScript libraries do not have namespaces, so prefix all JavaScript object names for the custom component using the same prefix.

● Place each JavaScript object in its own separate source file for best practice and consistency.

Page 52: Building a custom Oracle ADF Component

Helpful stuff

● web.xml parameters● Resource loading (zie:

ImageResourceLoader)● Toevoegen <method-signature> in de taglib

voor het snappen van methodExpression.●

Page 53: Building a custom Oracle ADF Component

Componentfaces-config

Tag Lib

view1.jsf

FacesBean

Renderer

Skin

Handler

Component

Peer

Event

ItemSelectEvent

Page 54: Building a custom Oracle ADF Component

Demo ShotsScreen shots from the Demo

Page 55: Building a custom Oracle ADF Component