Java Reference
In-Depth Information
33. <listener>
34. <listener-class>
35. org.springframework.web.context.ContextLoaderListener
36. </listener-class>
37. </listener>
38. <listener>
39. <listener-class>
40. org.springframework.web.context.request.RequestContextListener
41. </listener-class>
42. </listener>
43. </web-app>
Line 33 to 37
: Configures
ContextLoaderListener
Line 38 to 42
: Configures
RequestContextListener
SpringBeanFacesELResolver
is an
ELResolver
implementation that delegates to Spring's
WebApplicationContext
and the default resolver of the underlying JSF implementation. Listing 6-19
illustrates adding the
el-resolver
.
Listing 6-19. faces-config.xml
1. <?xml version="1.0" encoding="UTF-8"?>
2. <faces-config
3. xmlns="
http://java.sun.com/xml/ns/javaee
"
4. xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance
"
5. xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
6. version="2.0">
7. <application>
8. <el-resolver>
9. org.springframework.web.jsf.el.SpringBeanFacesELResolver
10. </el-resolver>
11. </application>
12. </faces-config>
Lines 7 to 11
: Configures Spring EL resolver
JSF is now integrated with the Spring Framework, and you should be able to access the database
via Spring
JDBCTemplate
.
Accessing a Database from the Web Layer via Spring JDBCTemplate
Next you will create the managed bean to access the database from the web layer. You already
created the Spring
JDBCTemplate
in Chapter 5. The managed bean you are going to create now will
use the
JDBCTemplate
created earlier via the
BookService
, which was also created in Chapter 5. In
other words, we will create the managed bean to access the database via the service layer and data
access layer created in Chapter 5. Listing 6-20 illustrates the
BookController
managed bean.