HTML and CSS Reference
In-Depth Information
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;
@Named
@RequestScoped
public class RegistrationBacking extends BaseBacking {
@EJB
private UserManagerLocal userManager;
public String register() {
FacesContext context = FacesContext.getCurrentInstance();
Map<Object, Object> flowScope = context.getApplication().getFlowHandler().getCurrentFlowScope();
AppUser appUser = new AppUser();
appUser.setId((String) flowScope.get("id"));
appUser.setPassword((String) flowScope.get("password"));
appUser.setEmail((String) flowScope.get("email"));
appUser.setFirstName((String) flowScope.get("fname"));
appUser.setLastName((String) flowScope.get("lname"));
appUser.setProfession((String) flowScope.get("profession"));
appUser.setZipCode((String) flowScope.get("zipCode"));
try {
userManager.registerUser(appUser);
} catch (UserExistsException ex) {
Logger.getLogger(RegistrationBacking.class.getName()).log(Level.SEVERE, null, ex);
context.addMessage(null, new FacesMessage(USERNAME_ALREADY_EXISTS));
return null;
} catch (Exception ex) {
Logger.getLogger(RegistrationBacking.class.getName()).log(Level.SEVERE, null, ex);
context.addMessage(null, new FacesMessage(SYSTEM_ERROR));
return null;
}
return "flowReturn";
}
...
}
RegistrationBacking bean is a backing bean which handles the user registration. In order to get the flow data,
the flow scope is retrieved using context.getApplication().getFlowHandler().getCurrentFlowScope() API. The
AppUser JPA entity class is instantiated and propagated with the user data from the flow scope and then it is passed to
the regiserUser() method of the UserManager EJB. If the registration succeeds, then the registration flow is returned
and the user is forwarded to the home page.
The AppUser JPA entity class will be illustrated in the next section.
 
Search WWH ::




Custom Search