Java Reference
In-Depth Information
E
String name = request.getParameter( "albumName" );
if ( name == null ) {
return "";
}
F
setAlbum( AlbumManager.getAlbumByTitle( name ) );
return "showAlbumDetails";
}
protected HttpServletRequest getRequest() {
if ( this .request == null ) {
return (HttpServletRequest)
FacesContext.getCurrentInstance()
.getExternalContext().getRequest();
} else {
return this .request;
}
}
G
public String cancel() {
return "cancel";
}
H
public void purchase() throws InterruptedException {
Thread.sleep( 1500 );
// empty implementation
System.out.println( "Here we must implement the purchase logic." );
}
//Additional getters and setters follow.
}
The bean tracks the request B and the album that the user has selected C . The
method that's called when the user clicks the name of a given album is showAlbum-
Details D . In this method, we get the request and extract a parameter with the name
"albumName" E . Then we use the AlbumManager to extract the Album object F . Pay
attention to the way we extract the request G ; if the attribute of the bean is null , we
get it from the FacesContext object. In the next section, we mock the request object
and set it as an attribute to the bean. The last method is the purchase method H ; we
call this method when a user wants to purchase a given album. For simplicity, we pro-
vide an empty implementation. Notice that we stop the execution exactly for a second
and a half because we want to simulate that this method is time consuming, which we
address when we write performance tests in the last section of this chapter.
Now let's move on to the JSP that provides the details for the bean (shown in list-
ing 15.7).
Listing 15.7
album_details.jsp presenting the details for a given product
<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:rich=" http://RichFaces.org/rich"
 
 
Search WWH ::




Custom Search