Java Reference
In-Depth Information
D
public void
setAlbums( List<Album> albums ) {
this
.albums = albums;
}
}
Listing 15.4 describes the bean for our application. For every attribute we want to dis-
play in the frontend, we specify a corresponding property of the bean
B
. Depending
on whether you only read or also write in your property, every property needs to have
a getter method
C
and a setter method
D
.
JSP
s interact with this bean, and the bean
itself interacts with the
AlbumManager
. Before this bean can expose itself to the
JSP
s,
we need to configure the bean in a configuration file called faces-config.xml.
Listing 15.4
faces-config.xml to configure our beans
<faces-config>
[...]
<application>
<view-handler>
com.sun.facelets.FaceletViewHandler
</view-handler>
</application>
<managed-bean>
<managed-bean-name>
listAlbumsBean
</managed-bean-name>
<managed-bean-class>
com.manning.junitbook.ch15.beans.ListAvailableAlbumsBean
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
[...]
</faces-config>
We start with an application declaration
B
, which contains some information that's
global for the whole application (like the view handlers, the locale parameters, and so
on). The
managed-bean
declaration
C
is used to expose our beans to the
JSP
s. Notice
the
managed-bean-name
declaration
D
; this name will be used in the
JSP
to reference
the bean with a class defined in the
managed-bean-class
declaration.
The only thing that we're missing to have the full picture of the
MusicStore
appli-
cation is the page to display all the albums available. We show this in listing 15.5.
B
C
D
Listing 15.5
The JSP to display all the available albums
<html xmlns="
http://www.w3.org/1999/xhtml"
xmlns:h="
http://java.sun.com/jsf/html"
xmlns:f="
http://java.sun.com/jsf/core"
xmlns:c="
http://java.sun.com/jstl/core">
<body>
<h:form id="list_albums">
B
[...]