HTML and CSS Reference
In-Depth Information
<h:commandButton value="#{bundle['application.login']}"
action="#{loginBacking.login}"/> <br/>
<h:link value="#{bundle['application.loginpage.register']}" outcome="registration"/>
<br/><br/>
<h:messages styleClass="errorMessage"/>
</h:form>
</ui:define>
</ui:composition>
</html>
As shown in the previous code, the weather application's home page contains user name
InputText
and
password
InputSecret
. The login
CommandButton
calls the
login
method of the
LoginBacking
bean and the
registration link navigates to
"registration"
flow (will be illustrated in more detail in the next section). Listing 10-2
shows the
LoginBacking
bean.
Listing 10-2.
LoginBacking Bean
package com.jsfprohtml5.weather.backing;
import com.jsfprohtml5.weather.model.AppUser;
import com.jsfprohtml5.weather.model.UserManagerLocal;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.inject.Named;
@Named
@RequestScoped
public class LoginBacking extends BaseBacking {
@EJB
private UserManagerLocal userManager;
public String login() {
AppUser currentAppUser = (AppUser) evaluateEL("#{appUser}", AppUser.class);
try {
AppUser appUser = userManager.getUser(currentAppUser.getId(),
currentAppUser.getPassword());
if (appUser == null) {
getContext().addMessage(null, new FacesMessage(INVALID_USERNAME_OR_PASSWORD));
return null;
}
//Set Necessary user information
currentAppUser.setEmail(appUser.getEmail());
currentAppUser.setFirstName(appUser.getFirstName());