10_planning navigation and page flow
TRANSCRIPT
-
8/14/2019 10_Planning Navigation and Page Flow
1/34
10Copyright 2007, Oracle. All rights reserved.
Planning Navigation and
Page Flow
-
8/14/2019 10_Planning Navigation and Page Flow
2/34
10-2 Copyright 2007, Oracle. All rights reserved.
Objectives
After completing this lesson, you should be able to do
the following:
Use a JavaServer Faces (JSF) Navigation diagram
to plan the pages of an application and thenavigation between them
Describe JSF Navigation
Describe the types of JSF Navigation cases
Create a backing bean for a JSF page
-
8/14/2019 10_Planning Navigation and Page Flow
3/34
10-3 Copyright 2007, Oracle. All rights reserved.
Go To My New Page
Traditional Navigation
In traditional navigation, a button or hyperlink is used
to navigate to a specific page.
-
8/14/2019 10_Planning Navigation and Page Flow
4/34
10-4 Copyright 2007, Oracle. All rights reserved.
What Is JSF Navigation?
JSF Navigation is defined through rules.
Rules use outcomes to determine which page is
displayed on a User Interface (UI) event.
Rules can be defined as: Static
Dynamic
They are defined in faces-config.xml.
-
8/14/2019 10_Planning Navigation and Page Flow
5/34
10-5 Copyright 2007, Oracle. All rights reserved.
JSF Navigation: Example
myNewPage
firstPage.jsp myNewPage.jsp
success
firstPage
Button
JSF Navigation Rules
-
8/14/2019 10_Planning Navigation and Page Flow
6/34
10-6 Copyright 2007, Oracle. All rights reserved.
JSF Navigation Rules
Navigation rules are stored in faces-config.xml.
Navigation rules can be defined using:
The faces-config console
The Pageflow diagrammer The faces-config.xmlfile directly
-
8/14/2019 10_Planning Navigation and Page Flow
7/3410-7 Copyright 2007, Oracle. All rights reserved.
JSF Navigation Rules
Example:
/login.jsp navigation rule with two cases
login.jsp managed by the login backing bean
loginAction() is the method that returnssuccess orfailure:
If the method returns
success, forward the user to
/successPage.jsp.
If the method returnsfailure, forward the
user to /failurePage.jsp.
-
8/14/2019 10_Planning Navigation and Page Flow
8/3410-8 Copyright 2007, Oracle. All rights reserved.
faces-config Console
-
8/14/2019 10_Planning Navigation and Page Flow
9/3410-9 Copyright 2007, Oracle. All rights reserved.
faces-config.xml
/login.jsp
success
/successPage.jsp
failure
/failurePage.jsp
-
8/14/2019 10_Planning Navigation and Page Flow
10/3410-10 Copyright 2007, Oracle. All rights reserved.
JSF Navigation Modeler
You create a JSF Navigation Diagram by dragging anddropping elements from the Component Palette. The
faces-config.xml diagram is automatically updated.
-
8/14/2019 10_Planning Navigation and Page Flow
11/3410-11 Copyright 2007, Oracle. All rights reserved.
JSF Navigation Diagram
With the JSF Navigation Diagrammer, you can visually
design your application from a birds-eye view.
-
8/14/2019 10_Planning Navigation and Page Flow
12/3410-12 Copyright 2007, Oracle. All rights reserved.
Navigation Elements
/SREdit.jspx
success
/SRSearch.jspx
-
8/14/2019 10_Planning Navigation and Page Flow
13/3410-13 Copyright 2007, Oracle. All rights reserved.
-
8/14/2019 10_Planning Navigation and Page Flow
14/3410-14 Copyright 2007, Oracle. All rights reserved.
Global Rules
Global rules apply to all pages in an application.
Examples: Help page, Home page, Contact page
Define thewith an asterisk (*)
wildcard. Define(help).
Define(help.jsp).
Any page in the application that returns help
displays help.jsp.
-
8/14/2019 10_Planning Navigation and Page Flow
15/3410-15 Copyright 2007, Oracle. All rights reserved.
Pattern-Based Rules
Pattern-based rules are similar to global rules.
Include a pattern for theelement:
/staffPages/*
This rule is used by all pages in the /staffPagespath.
/staffPages/*
help
/menu/staffHelp.jsp
-
8/14/2019 10_Planning Navigation and Page Flow
16/3410-16 Copyright 2007, Oracle. All rights reserved.
JSF: Example
Sample JSF login application:
-
8/14/2019 10_Planning Navigation and Page Flow
17/3410-17 Copyright 2007, Oracle. All rights reserved.
JSF: Example
A simple example of a JSF Login Application:
loginAction
login.jsp
Success
success.jsp
Failure
failure.jsp
-
8/14/2019 10_Planning Navigation and Page Flow
18/3410-18 Copyright 2007, Oracle. All rights reserved.
JSF Navigation: Example
UI components and value binding to a managed bean:
login.jsp
Login: A managed bean with the userIdand
passwordfields and the login()method
Submit
-
8/14/2019 10_Planning Navigation and Page Flow
19/3410-19 Copyright 2007, Oracle. All rights reserved.
JSF Navigation: Example
A command UI component bound to an action:
login.jsp
Login: A managed bean (Login.java) with an action
method called loginAction()
Returns string: failure orsuccess
-
8/14/2019 10_Planning Navigation and Page Flow
20/3410-20 Copyright 2007, Oracle. All rights reserved.
JSF Navigation: Example
public String loginAction() {
String userId =
(String)this.getUserId().getValue();
String password =(String)this.getPassword().getValue();
if (userId.equalsIgnoreCase("gary") &
password.equalsIgnoreCase("test")){
return "success"; }
return "failure";
}
-
8/14/2019 10_Planning Navigation and Page Flow
21/3410-21 Copyright 2007, Oracle. All rights reserved.
Using the JSF Configuration Editor
-
8/14/2019 10_Planning Navigation and Page Flow
22/3410-22 Copyright 2007, Oracle. All rights reserved.
Managed Beans
Managed beans can: Store state
Execute a Java routine
Define a handler for event listeners
They have no-argument constructors.
Lazy initialization is performed by JavaServerFaces.
Access scope: None, Request, Application, or
Session Backing beans: Are special types of managed beans
Contain getter and setter methods for UIcomponents
-
8/14/2019 10_Planning Navigation and Page Flow
23/3410-23 Copyright 2007, Oracle. All rights reserved.
-
8/14/2019 10_Planning Navigation and Page Flow
24/3410-24 Copyright 2007, Oracle. All rights reserved.
Creating Managed Beans
Entry in faces-config.xml:
UserInfo
org.srdemo.view.backing.UserInfo
session
-
8/14/2019 10_Planning Navigation and Page Flow
25/3410-25 Copyright 2007, Oracle. All rights reserved.
Managed Bean: Example
Definition:
Usage on a page:
Usage in code:
userbean
com.oracle.sample.User
request
Application app =FacesContext.getCurrentInstance().getApplication();
ValueBinding bind = app.createValueBinding("#{userbean}");
User user = (User)bind.getValue(ctx);
-
8/14/2019 10_Planning Navigation and Page Flow
26/34
10-26 Copyright 2007, Oracle. All rights reserved.
Setting Managed Bean Scope
Each managed bean has a
scope:
Application
Session Request
None
-
8/14/2019 10_Planning Navigation and Page Flow
27/34
10-27 Copyright 2007, Oracle. All rights reserved.
Relationships Between Managed Beans
Managed beans can access other beans:
YesYesYesYesrequest
NoYesYesYessession
NoNoYesYesapplication
NoNoNoYesnone
requestsessionapplicationnone
Access beans in scopeBeans in
scope
-
8/14/2019 10_Planning Navigation and Page Flow
28/34
10-28 Copyright 2007, Oracle. All rights reserved.
Managed Properties
Managed bean variables that are exposed through
getter and setter methods
Configured in faces-config.xml
Possible values:
Null Literal string
Lists and maps
Value binding expression (EL)
(map-entries|null-value|value|list-entries))>
-
8/14/2019 10_Planning Navigation and Page Flow
29/34
10-29 Copyright 2007, Oracle. All rights reserved.
Managed Properties: Examples
Literal string:
EL accessing a managed bean:
label
Hello World
label
#{UserInfo['firstname']}
-
8/14/2019 10_Planning Navigation and Page Flow
30/34
10-30 Copyright 2007, Oracle. All rights reserved.
Managed Properties: Examples
Populating a list:
Useto specify managed properties
that are of theMap type.
bookmarks
http://otn.oracle.com/products/jev
http://otn.oracle.com/products/ias
-
8/14/2019 10_Planning Navigation and Page Flow
31/34
10-31 Copyright 2007, Oracle. All rights reserved.
Using the Managed Bean in the JSF Page
Access UI components and values
Getter for userIdSetter for userId
Login.java managed bean:
successPage.jsp:
-
8/14/2019 10_Planning Navigation and Page Flow
32/34
10-32 Copyright 2007, Oracle. All rights reserved.
Summary
In this lesson, you should have learned how to:
Use a JSF Navigation Diagram to plan the pages of
an application and the navigation between them
Describe JSF Navigation Define types of JSF Navigation cases
Create a backing bean for a JSF page
-
8/14/2019 10_Planning Navigation and Page Flow
33/34
10-33 Copyright 2007, Oracle. All rights reserved.
Practice Overview:
Developing JSF Applications
This practice covers the following topics:
Using a JSF Navigation Diagram to model page
flow in an application
Creating the JSF pages of the application Adding a managed bean to the project
-
8/14/2019 10_Planning Navigation and Page Flow
34/34