HTML and CSS Reference
In-Depth Information
} catch (Exception ex) {
Logger.getLogger(WeatherBacking.class.getName()).log(Level.SEVERE, null, ex);
getContext().addMessage(null, new FacesMessage(SYSTEM_ERROR));
}
}
public String logout() {
try {
getRequest().logout();
return "/home.xhtml?faces-redirect=true";
} catch (ServletException ex) {
Logger.getLogger(WeatherBacking.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
}
As shown in the code, loadUser() method retrieves the current user information using its ID (user ID can be
retrieved from java.security.Principal , which can be gotten using getUserPrincipal() API of HTTPServletRequest ).
logout() calls the logout() method of HTTPServletRequest in order to log the user out from the current authenticated
session. Listing 12-8 shows the updated weather.xhtml page.
Listing 12-8. Updated weather.xhtml Page
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns=" http://www.w3.org/1999/xhtml "
xmlns:ui=" http://java.sun.com/jsf/facelets "
xmlns:h=" http://java.sun.com/jsf/html "
xmlns:f=" http://java.sun.com/jsf/core "
xmlns:mashup=" http://code.google.com/p/mashups4jsf/ " >
<ui:composition template="/WEB-INF/templates/main.xhtml">
<ui:define name="title">
#{bundle['application.weatherpage.title']}
</ui:define>
<ui:define name="content">
<f:event listener="#{weatherBacking.loadUser}" type="preRenderView" />
<h:form>
#{bundle['application.welcome']}, #{appUser.firstName} #{appUser.lastName}! <br/><br/>
#{bundle['application.weatherpage.currentInfo']} for #{appUser.zipCode}:
<mashup:yahooWeather temperatureType="c" locationCode="#{appUser.zipCode}"/> <br/><br/>
<h:commandLink value="#{bundle['application.weatherpage.logout']}"
action="#{weatherBacking.logout}"></h:commandLink> <br/><br/>
</h:form>
</ui:define>
</ui:composition>
</html>
 
Search WWH ::




Custom Search