HTML and CSS Reference
In-Depth Information
As shown in the bolded line, in order to retrieve the current user information,
loadUser()
method of
weatherBacking
bean is called in the
preRenderView
event (which is called each time before the view is rendered).
RegistrationBacking
class has to be updated as well. Listing 12-9 shows the updated
RegistrationBacking
bean.
Listing 12-9.
Updated RegistrationBacking Bean
@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"));
//Assign a group to the user ...
AppGroup appGroup = new AppGroup(appUser.getId(), "weather_user");
List<AppGroup> appGroups = new ArrayList<>();
appGroups.add(appGroup);
appUser.setAppGroupList(appGroups);
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";
}
//...
}