HTML and CSS Reference
In-Depth Information
Listing 10-3 shows the code of the
BaseBacking
class.
Listing 10-3.
BaseBacking Bean Class
package com.jsfprohtml5.weather.backing;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
public class BaseBacking {
protected FacesContext getContext() {
return FacesContext.getCurrentInstance();
}
protected Map getRequestMap() {
return getContext().getExternalContext().getRequestMap();
}
protected HttpSession getSession() {
return (HttpSession) getContext().getExternalContext().getSession(false);
}
protected Object evaluateEL(String elExpression, Class beanClazz) {
return getContext().getApplication().evaluateExpressionGet(getContext(), elExpression,
beanClazz);
}
...
}
BaseBacking
class is a base class which contains shortcuts for getting the JSF Faces context, getting the HTTP
session, getting the HTTP request map, and evaluating the JSF expressions. Listing 10-4 shows the
weather.xhtml
page code.
Listing 10-4.
Weather Main 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: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>