HTML and CSS Reference
In-Depth Information
bookManager.registerBook(newBook);
infoMessage = "Book saved successfully";
newBook = new Book();
} catch (BookAlreadyExists ex) {
Logger.getLogger(BookAddBacking.class.getName()).log(Level.SEVERE, null, ex);
infoMessage = "A book with the same ISBN already exists";
} catch (Exception ex) {
Logger.getLogger(BookAddBacking.class.getName()).log(Level.SEVERE, null, ex);
getContext().addMessage(null, new FacesMessage("An error occurs while saving book"));
}
return null;
}
public void validateFile(FacesContext ctx, UIComponent comp, Object value) {
List<FacesMessage> msgs = new ArrayList<FacesMessage>();
Part file = (Part) value;
if (file.getSize() > 1048576) {
msgs.add(new FacesMessage("file size must not exceed 1 MB"));
}
if (! "application/pdf".equals(file.getContentType())) {
msgs.add(new FacesMessage("Book format must be PDF"));
}
if (! msgs.isEmpty()) {
throw new ValidatorException(msgs);
}
}
}
In saveBook and in order to save the topic information, a call to registerBook method of BookManager is done
passing the topic information as a parameter. IOUtils.toByteArray is a utility function in Apache Commons IO that
can be used to convert the file input stream to byte array in order to save the topic content as a byte array.
Listing 13-32 shows userList.xhtml which is used for listing all the Mega App users to the administrator
user(s).
Listing 13-32. userList.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:f=" http://xmlns.jcp.org/jsf/core "
xmlns:h=" http://xmlns.jcp.org/jsf/html " >
Search WWH ::




Custom Search