Java Reference
In-Depth Information
<table border='1'>
<th>Name</th>
<th>Author</th>
<th>Year</th>
<th>Price</th>
<c:forEach var="album" items="#{listAlbumsBean.albums}">
<tr>
<td>
<h:commandLink
action="#{albumDetailsBean.showAlbumDetails}">
C
D
<h:outputText value="${album.name}" />
<f:param name="albumName" value="#{album.name}" />
</h:commandLink></td>
<td>${album.author}</td>
<td>${album.year}</td>
<td>$ ${album.price}</td>
</tr>
</c:forEach>
</table>
</h:form>
</body>
</html>
We need to import the tag libraries that we want to use in this
JSP
B
. All that our
JSP
is
doing is iterating over all the albums
C
and displaying the information for every
album that we want. We use the standard
JSTL
tag libraries
C
as well core
JSF
tag
libraries
D
.
The
JSP
contains a link that to a managed bean we haven't defined yet:
<h:commandLink action="#{albumDetailsBean.showAlbumDetails}">
[...]
</h:commandLink>
We want to implement the following: the list_albums.jsp presents all the albums to the
user, and on clicking the name of an album you're redirected to a page that displays
the album details. The new page then allows you to purchase the album or navigate
back to the listing page.
Listing 15.6 gives the code for the bean that displays the details for the
selected album.
Listing 15.6
AlbumDetailsBean
implementation
[...]
public class
AlbumDetailsBean {
private
String status =
null
;
B
private
HttpServletRequest request =
null
;
C
private
Album album =
null
;
D
public
String showAlbumDetails() {
HttpServletRequest request = getRequest();