HTML and CSS Reference
In-Depth Information
externalContext.responseReset();
externalContext.setResponseContentType(Constants.APP_PDF_TYPE);
externalContext.setResponseContentLength(content.length);
externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\""
+ book.getTitle() + ".pdf\"");
OutputStream output = null;
try {
output = externalContext.getResponseOutputStream();
output.write(content);
output.flush();
output.close();
} catch (IOException ex) {
Logger.getLogger(BookSearchBacking.class.getName()).log(Level.SEVERE, null, ex);
} finally {
getContext().responseComplete();
}
return null;
}
}
The main methods of
BookSearchBacking
CDI bean are as follows:
•
retrieveBookList
: Calls
getAllBooks
method of
BookManager
EJB passing
searchableBook
object, which contains the searchable title as a parameter. If there are no results returned, a
"No Book results found"
message is displayed to the user. If results are returned, a message
with the number of returned books is displayed to the user including the topics list.
•
requestBookCopy
: Calls
sendBookRequest
method of
BookManager
EJB passing
bookRequest
object (which contains the request owner user and the target book) as a parameter. If the request
is sent successfully, a
"Book request sent"
information message is displayed to the user.
•
deleteBook
: Calls
removeBook
method of
BookManager
EJB passing the currently selected book
ID as a parameter. If the operation is done successfully, a
"Book deleted successfully"
information message is displayed to the user.
downloadBook
: Calls
getBookContent
method of
BookManager
EJB passing the currently
selected book ID as a parameter; in order to give the downloadable content a meaningful
name, the topic title is retrieved using
getBookInformation
method of
BookManager
EJB.
In order to follow up on the requests, the Mega App (administrator or user) can use the
bookRequests.xhtml
page. Listing 13-28 shows the
bookRequests.xhtml
page.
•
Listing 13-28.
bookRequests.xhtml Page
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="
http://www.w3.org/1999/xhtml
"
xmlns:ui="
http://xmlns.jcp.org/jsf/facelets
"
xmlns:h="
http://xmlns.jcp.org/jsf/html
"
xmlns:c="
http://xmlns.jcp.org/jsp/jstl/core
"
xmlns:f="
http://java.sun.com/jsf/core
"
>