HTML and CSS Reference
In-Depth Information
currentAppUser.setLastName(appUser.getLastName());
currentAppUser.setZipCode(appUser.getZipCode());
currentAppUser.setProfession(appUser.getProfession());
} catch (Exception ex) {
Logger.getLogger(LoginBacking.class.getName()).log(Level.SEVERE, null, ex);
getContext().addMessage(null, new FacesMessage(SYSTEM_ERROR));
return null;
}
return "/protected/weather";
}
...
}
LoginBacking
bean is a backing bean which handles the login action. It calls the
UserManager
EJB in order to
know if the user is registered in the system using
getUser()
method (
UserManager
EJB will be illustrated in detail in
the “Application Back End” section). In order to get the
AppUser
's CDI managed bean instance which is binded with
the user name and password fields,
evaluateEL()
method is called in order to evaluate the #
{appUser}
expression.
evaluateEL()
method is located in the base backing bean (
BaseBacking
) class.
If
getUser()
method returns
null
, this means that the user is not registered in the system with the entered
username and password combination and an invalid user name or password message is shown for the user. If the user
name and password combination is valid, then the user's information is retrieved and set in
#{appUser}
managed
bean instance (
AppUser
is both a request-scoped CDI managed bean and a JPA entity class, which will be illustrated in
detail in the “Application Back End” section), and the page is forwarded to the weather page.
■
@EJB
annotation can be used for annotating bean's instance variable to specify a dependence on an eJB.
application server automatically initializes the annotated variable with the reference to the eJB on which it depends
using dependency injection. this initialization occurs before any of the bean's business methods are invoked and after the
bean's eJBContext is set.
Note
All of the weather application's backing beans extend from
BaseBacking
class as shown in Figure
10-7
.
Figure 10-7.
Weather Application's backing beans

