Sample Apps: Spring data MongoDB and JSF Integration tutorial (PART 3)


Table of Contents:
1. Introduction to sample application (MongoShop Product Catalog)
2. MongoDB schema design and data preparation
3. JSF (PrimeFaces) and Spring data MongoDB Integration
4. Enquriy data with spring data repository and mongotemplate
5. Create, Edit and delete data


JSF (PrimeFaces) and Spring data MongoDB Integration

pom.xml of the project

 4.0.0
 com.borislam
 mongoShop
 war
 1.0-SNAPSHOT
 MongoShop Webapp
 http://maven.apache.org
 
 
 org.jboss.el
 com.springsource.org.jboss.el
 2.0.0.GA
 
  
 org.primefaces.themes 
 all-themes 
 1.0.9 
 
  
 org.primefaces 
 primefaces 
 3.4.2 
 
 
 commons-beanutils
 commons-beanutils
 1.8.3
  
 
 
 commons-codec
 commons-codec
 1.3
  
 
 org.apache.directory.studio
 org.apache.commons.lang
 2.6
 
 
 commons-digester
 commons-digester
 1.8
 
 
 commons-collections
 commons-collections
 3.2
 
 
 
 org.apache.myfaces.core
 myfaces-api
 2.1.9
 
 
 
 org.apache.myfaces.core
 myfaces-impl
 2.1.9
 
 
 
 org.mongodb
 mongo-java-driver
 2.10.1
 
 
 junit
 junit
 3.8.1
 test
 
 
 org.springframework.data
 spring-data-mongodb
 1.0.3.RELEASE
  
 
 org.springframework
 spring-context
 3.2.0.RELEASE
  
 
 org.springframework
 spring-web
 3.2.0.RELEASE
 
 
 
 
 java.net
 https://maven.java.net/content/repositories/public/
 
  
 prime-repo 
 PrimeFaces Maven Repository 
 http://repository.primefaces.org 
 default 
 
 
 com.springsource.repository.bundles.release
 SpringSource Enterprise Bundle Repository - SpringSource Releases
 http://repository.springsource.com/maven/bundles/release
 
 
 com.springsource.repository.bundles.external
 SpringSource Enterprise Bundle Repository - External Releases
 http://repository.springsource.com/maven/bundles/external
 
 
 
 false
 
 
 true
 
 apache.snapshots
 Apache Snapshot Repository
 https://repository.apache.org/content/repositories/snapshots
  
 
 jboss-deprecated-repository
 JBoss Deprecated Maven Repository
 https://repository.jboss.org/nexus/content/repositories/deprecated/
 default
 
 true
 never
 
 
 false
 never
 
 
 
 
 mongoShop
 


MyFaces
MyFaces is used as the JSF implementation in this application. The following details should be added in web.xmlPrimeFaces Theme
As said before, PrimeFaces library is used to enhance the UI. There is nearly no configuration required for this library. PrimeFaces provides many pre-designed theme for your web application. In our case, we use “blue-sky” theme. We just add the following setting in web.xml


 primefaces.THEMEglass-x

JSF and Spring Integration:
To integrate JSF with Spring, you have to specify the SpringBeanFacesELResolver in Faces-config.xml
Faces-config.xml

 
 org.springframework.web.jsf.el.SpringBeanFacesELResolver
 
 
 org.primefaces.context.PrimePartialViewContextFactory
  


Full web.xml

 
 contextConfigLocationWEB-INF/spring-application-context.xml
 
 errorPageUrl/pages/systemError.do
 
 facelets.DEVELOPMENTfalse
 
 facelets.REFRESH_PERIOD2
 
 javax.faces.STATE_SAVING_METHODclient
 
 javax.servlet.jsp.jstl.fmt.localizationContextresources.application
 
 org.apache.myfaces.ALLOW_JAVASCRIPTtrue
 
 org.apache.myfaces.AUTO_SCROLLfalse
 
 org.apache.myfaces.DETECT_JAVASCRIPTfalse
 
 org.apache.myfaces.ERROR_HANDLINGfalse
 
 org.apache.myfaces.EXPRESSION_FACTORYorg.jboss.el.ExpressionFactoryImpl
 
 org.apache.myfaces.PRETTY_HTMLfalse
 
 primefaces.THEMEglass-x 
 
 Faces Servlet
 org.apache.myfaces.webapp.MyFacesServlet
 1
 
 
 Faces Servlet
 *.jsf
 
 
 org.apache.myfaces.webapp.StartupServletContextListener
 
 
 org.springframework.web.context.ContextLoaderListener
 

MongoDB connection Details
In to order connect to MongoDB, you have to register a MongoDbFactory instance in XML. The connection details is specified in spring-application-context.xml
spring-application-context.xml


 
 
 
  
 
 
 
 
 
 
 


Comments