ADF Faces. • Oracle JSF component libraries. – Released to MyFaces open
source project in Jan. 2006. • Trinidad project at myfaces.apache.org. – Available
in ...
Now I Remember!
Hello Worldwide Web: Your First JSF in JDeveloper
There are three things I always forget. Names, faces, and— the third I can’t remember.
Peter Koletzke —Italo
Technical Director & Principal Instructor
Svevo (1861–1928)
2
Survey
Agenda
• Job responsibilities? – DBA, developer
• What is JSF?
• Languages? – PL/SQL – Java – JSF – C++ – Other
• Related files
Note: Examples use JDeveloper 11g and ADF Faces.
• Accessing the database Warning: This material contains more depth than you need to create apps in JDev 11g.
• Tools? – Developer Forms/Reports – JDeveloper – Other
Slides and white paper will be on the NoCOUG website soon. 3
4
JSF Application
JSF Code
• JavaServer Faces technology • Relatively new technology
• Usually used for a web-based application – Technically can be any client – PDA, cell phone
– Ratified JCP in 5/2004 – Part of Java EE (v.5) – Offers reference implementation – code library
• XML-like (or just plain old XML) – Start and end tag required – Elements, commonly called “components” – Attributes
• Effort to simplify JSP development – Component-ize it
• Its components represent JSP action tags
• High-level components provide much functionality
– Integrate the controller
– Requires a prefix and tag library definition (.tld file) to back it – Tag library definition points to the Java class that implements the tag
• No Struts needed
– Write less HTML (than JSP) • Component handles HTML writing
• JSF is often run in a JSP file
• Following example mixes standard JSF with ADF Faces Rich Client
– XML-like tags: elements and attributes 5
JSF Code Snippet ... ...
7
6
The Result
in a footer facet
Demo 1
8
JSF Communication Process
The Steps
Web Server Web Browser
1
login
TP HT est u q Re
Which application? 3
2
Web Container login.jsp 7
H res TTP pon se
web.xml
JSP 4 translation & compilation ***
6
login.class
Database Note: JSP translation and compilation is a one-time process
Faces Servlet
5
1. The browser issues an HTTP request to the web server. 2. The web server determines the application and passes the request to the web container (WLS or OC4J) 3. The web server reads web.xml to determine that this is a JSF JSP. 4. The JSP is translated to a servlet and compiled (the first time it is run) 5. The web server passes the request to the Faces Servlet. The Faces Servlet instantiates a life cycle class, which processes the JSP JSF. 6. The servlet accesses any necessary Model layer code to obtain values from the data source (such as a database). 7. The Faces Servlet then assembles the page and sends it using an HTTP response to the browser.
9
10
ADF Faces
JSF Features
• Oracle JSF component libraries
• Rich component set
– Released to MyFaces open source project in Jan. 2006
– Core library – for application tasks – HTML library – for HTML tags, forms – JSP tag library included
• Trinidad project at myfaces.apache.org
– Available in JDeveloper 10.1.3 as ADF Faces – In JDeveloper 11g as ADF Faces Rich Client
• Implements components available in UIX
• Can be implemented in other languages
– Uses JSF mechanisms – Adds even more functionality to JSF – Over 150 components, For example, selectOrderShuttle:
– Include data binding properties
• Embedded controller – Previously, no standard controller for JSPs – Struts was/is a popular controller framework
• Event-driven – Events on the component level – Like Forms triggers 11
12
Agenda
JSF Files Request
Web Tier Container
• What is JSF?
Faces Servlet
Other Model Code
Life Cycle
• Related files
1
2
3
6
5
4
Backing bean
Database
Response
• Accessing the database
login.jsp login.class
faces-config.xml Message bundle
HTML Render Kit
Not to scale
web.xml
13
The Files
14
web.xml
• web.xml – used to start FacesServlet, which instantiates and runs the life cycle class • faces-config.xml – the controller file used to manage page flow • Backing bean – code for the components on the page • Message bundle – supplies text for the JSP • login.jsp – JSF (JSP) source code that is compiled into login.class • Model layer code – used to obtain values from the data source (such as a database). • HTML render kit – converts components in memory to HTML tags Demo 2
• web.xml –web module deployment descriptor – Contains an entry such as this: forum_query.jsp
• Contains the URL pattern used to determine which servlet will take control • Contains the servlet name and class file name 15
• Navigation occurs when action property of a button is set to the outcome name 19
20
Editing faces-config.xml
Editing in the Overview Tab
• JSF Navigation Diagram – Look under WEB-INF – Double click the faces-config.xml file in the navigator – Use drag and drop to add elements 21
Editing in the Structure Window
22
Backing Beans • Backing bean: a Java class file used for code pertaining to a specific page – For example, login.jsp would use a Login.java backing bean
• Contain accessors for components on the page and other code for just that page • Optional file: only create it if you need to change the logic • These are registered in faces-config.xml: • Use the right-click menu to edit nodes • Drag and drop to reposition code • OR use the code editor 23
backing_login login.view.backing.Login session Comment line declares that JDeveloper will create accessors when you add a component to the JSF page. 24
Creating the Bean
Backing Bean Contents • Variables for each component • Setters and Getters for each component • If JDeveloper created the backing bean it will maintain it
• Create a Java class from the New Gallery – Enter it in faces-config manually
• OR from the Create JSF Page dialog
– Uses the comment line shown earlier in the faces-config.xml file – Adding a component adds the variable and accessors for that component – Deleting a component removes them – Renaming a component renames them
– Specify the name in faces-config and the class file name
25
Alternative for Creating the Backing Bean
26
Managed Beans or Backing Beans?
• Double click an action component (button or link)
• A bean (JavaBean) is a Java class file with a standard set of methods • Managed bean is a Java class file used to handle operations and data for a resource – such as a JSF page • Backing bean is a managed bean that supports a specific page • The terms “managed bean” and “backing bean” are sometimes used interchangeably
– These dialogs will set up the Java class and register it in faces-config
27
28
Backing Bean Snippet
About Scope
package login.view.backing;
• Values in a bean or a FacesContext variable are cleared out of memory at certain times • You can declare a scope for these objects:
– request: for the HTTP request/response – session: for the user’s session with the app server (until they log out or time out) – application: across client sessions; held in the app server memory
• Imports and private variables for each component 29
Backing Bean Snippet (continued)
30
Message Bundles
public void setLoginForm(RichForm form) { this.loginForm = form; }
• Also called “resource bundles” • Separate properties (text) or Java class file containing labels and messages • Linked to the page through expressions on the components • Also readable by code in the backing bean • Allow for centralization of messages • Automated localization and internationalization (language-specifics)
public RichForm getLoginForm() { return loginForm; } public void setUsernameField(RichInputText it1) { this.usernameField = it1; } public RichInputText getUsernameField() { return usernameField; } // and accessors for all other components }
• Getters and setters for each component • Other contents: validation code 31
32
Message Bundle Snippet
Message Bundles in JDeveloper • Define the message bundle name
#English welcome message WELCOME_HOME=Welcome Home
– Project properties – Resource bundle page
• Add the message using a dialog
# login attempt messages incorrectLogin=Incorrect login. Try again. loginHint=You seem to have forgotten the password.
– Select “Select Text Resource” from the pulldown by an applicable component
• Refer to the message using Expression Language, for example: #{viewcontrollerBundle.WELCOME_HOME}
• This expression will be resolved at runtime and at design time Demo 3 33
Agenda
34
The JDeveloper Technique • Create ADF Business Components (ADF BC)
• What is JSF?
– Declares database structures (tables and views) – Similar functionality to EJBs
• Related files • Accessing the database
• Drop data controls onto the page – This binds the components to the ADF BC components – A separate PageDef file is created for the bindings 35
36
Summary Designer Handbook
• JSF evolved to make web development easier • Some awareness of the runtime environment and life cycle will help in your first JSF • You need to create the JSF JSP file • You also need supporting files:
JDeveloper 3 Handbook
– web.xml – created automatically to assist in loading pages – faces-config.xml – the main JSF configuration file – Backing beans – programmatic code for the page – Message bundles – centralized text strings for the page
ORACLE JDeveloper 10g Handbook
• JDeveloper offers many tools to assist – Including frameworks to access the database What a surprise!
37
Developer Advanced Forms & Reports
ORACLE9i JDeveloper Handbook
Please fill out the evals Books co-authored with Dr. Paul Dorsey, Avrom Roy-Faderman, & Duncan Mills Personal web site:
http://www.quovera.com • Founded in 1995 as Millennia Vision Corp. • Profitable for 7+ years without outside funding • Consultants each have 10+ years industry experience • Strong High-Tech industry background • 200+ clients/300+ projects • JDeveloper Partner • More technical white papers and presentations on the web site 38