Java Reference
In-Depth Information
175
176
return
"AddressStoredStatus"
;
go to a new page
177 }
178
179
public
String getStatus() {
180
return
status;
181 }
182 }
A session-scoped managed bean must implement the
java.io.Serializable
interface.
So, the
AddressRegistration
class is defined as a subtype of
java.io.Serializable
.
The action for the
Register
button in the
AddressRegistration
JSF page is
processSubmit()
(line 64 in AddressRegistration.xhtml). This method checks if last name
and first name are not empty (lines 106-111 in AddressRegistrationJSFBean.java). If so, it
returns a string
"ConfirmAddress"
, which causes the
ConfirmAddress
JSF page to be
displayed.
The
ConfirmAddress
JSF page displays the data entered from the user
(line 12 in ConfirmAddress.xhtml). The
getInput()
method (lines 120-133 in
AddressRegistrationJSFBean.java) collects the input.
The action for the
Confirm
button in the
ConfirmAddress
JSF page is
storeStudent()
(line 15 in ConfirmAddress.xhtml). This method stores the address in the database (lines
157-177 in AddressRegistrationJSFBean.java) and returns a string
"AddressStoredStatus"
,
which causes the
AddressStoredStatus
page to be displayed. The status message is dis-
played in this page (line 12 in AddressStoredStatus.xhtml).
The action for the
Go Back
button in the
ConfirmAddress
page is
"AddressRegistration"
(line 17 in ConfirmAddress.xhtml). This causes the
AddressRegistration
page to be displayed for the user to reenter the input.
The scope of the managed bean is session (line 9 AddressRegistrationJSFBean.java) so the
multiple pages can share the same bean.
Note that this program loads the database driver explicitly (line 139
AddressRegistrationJSFBean.java). Sometimes, an IDE such as NetBeans is not able to find a
suitable driver. Loading a driver explicitly can avoid this problem.
K
EY
T
ERMS
application scope
1233
scope 1233
session scope
JavaBean 1217
request scope
1233
1233
view scope
1233
C
HAPTER
S
UMMARY
1.
JSF enables you to completely separate Java code from HTML.
2.
A
facelet
is an XHTML page that mixes JSF tags with XHTML tags.
3.
JSF applications are developed using the Model-View-Controller (MVC) architecture,
which separates the application's data (contained in the model) from the graphical pres-
entation (the view).
4.
The controller is the JSF framework that is responsible for coordinating interactions
between view and the model.
Search WWH ::
Custom Search