Java Reference
In-Depth Information
As you can see, the implementation is simple. The Album is a simple POJO that con-
tains several properties B : the name of the album, author of the album, and so on.
We have also added getters and setters for those properties and a constructor C to
instantiate different albums.
Listing 15.2 shows a manager class used to manipulate the albums.
Listing 15.2
The AlbumManager performs different operations on Album s
[...]
public class AlbumManager {
final static List<Album> albums = new ArrayList<Album>();
static {
albums.add( new Album( ... ) );
albums.add( new Album( ... ) );
albums.add( new Album( ... ) );
albums.add( new Album( ... ) );
albums.add( new Album( ... ) );
}
public static List<Album> getAvailableAlbums() {
return albums;
}
public static Album getAlbumByTitle(String title) {
for (Album album : albums) {
if (album.getName().equals(title)) {
return album;
}
}
return null ;
}
}
The MusicStore application focuses only on JSF . We avoid additional layers such as
interacting with a database. That's why we start the implementation with a declaration
and initialization of a list of five hardcoded Album s B . Normally we'd invoke a data-
base layer to get these albums, but for the sake of simplicity, we use hardcoded values.
To keep the code listing simple and readable, we removed the Album declarations.
Next, we implement a number of methods: one for retrieving all the available albums
C and another for finding an album by title D .
Listing 15.3 implements the bean that communicates with the frontend.
B
C
D
Listing 15.3 ListAvailableAlbumsBean implementation
[...]
public class ListAvailableAlbumsBean {
B
C
private List<Album> albums = new ArrayList<Album>();
public List<Album> getAlbums() {
this .albums = AlbumManager.getAvailableAlbums();
return albums;
}
 
 
Search WWH ::




Custom Search