HTML and CSS Reference
In-Depth Information
try {
userManager.registerMegaUser(newUser);
infoMessage = "User saved successfully";
newUser = new MegaUser();
} catch (UserAlreadyExists ex) {
Logger.getLogger(UserAddBacking.class.getName()).log(Level.SEVERE, null, ex);
infoMessage = "Login name already exists";
} catch (Exception ex) {
Logger.getLogger(UserAddBacking.class.getName()).log(Level.SEVERE, null, ex);
getContext().addMessage(null, new FacesMessage("An error occurs while registering user"));
}
return null;
}
}
Before going into the registration details, there are two points that need to be highlighted:
1. @javax.faces.view.ViewScoped annotation: It is important to know that CDI does not have
view scope but since CDI is an extensible framework, JSF 2.2 provided an implementation
for CDI View scope and provided the @javax.faces.view.ViewScoped annotation.
2. @Produces annotation: A CDI annotation that is used to identify a method or a field as a
producer method or field. A producer method or field is called whenever another bean in
the application needs an injected object. If @Produces annotation is combined with @Named
annotation with @xxxScoped , this will allow this producer field to be available in the JSF
expression language for the specified xxx scope. In our case, a prototype MegaUser is being
exposed using the named producer to the JSF expression language in the JSF Facelets page
in the request scope, which means it can be accessed using #{newUser.xxx} expression.
it is very important not to be confused by @javax.faces.view.ViewScoped and @javax.faces.bean.
ViewScoped annotations ; the first one is the JSF 2.2 CDi implementation for the view scope, while the second one is
the JSF managed bean view scope, nOt the CDi one.
Caution
registerUser method validates that the entered user password is equal to the confirmed user password and then
calls registerMegaUser method of MegaUserManager EJB to register the user.
After the user logs in to the system, the user is redirected “by default” to bookSearch.xhtml page. Listing 13-26
shows bookSearch.xhtml page code.
Listing 13-26. bookSearch.xhtml Page Code
<?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:f=" http://xmlns.jcp.org/jsf/core "
xmlns:c=" http://xmlns.jcp.org/jsp/jstl/core " >
 
 
Search WWH ::




Custom Search