Home » Java » Enterprise Java » Spring Data, MongoDB and JSF Integration tutorial

About Boris Lam

Boris Lam
Boris is an experienced Java developer with in Hong Kong. His expertise is in Java EE technology, object-oriented application development, and the use of open source frameworks (e.g. Spring , Apache MyFaces). In recent years, he is primarily involved in framework development and architectural design in serveral Government related software development projects.

Spring Data, MongoDB and JSF Integration tutorial

Introduction to sample application (MongoShop Product Catalog)

After this tutorial, a sample application (MongoShop Product Catalog) with the following functional requirement will be built:
 
 
 
 
 
 
 
1. Searching product with different criteria (e.g. sku, product type, title, stc)

2. Create a new product with different category.

3. Edit selected product details

4. Delete selected product from the enquiry screen.

Presentation Layer:

JSF is used as presentation layer technology in this sample application. PrimeFaces is a one of lightweight component for enhancing the JSF UI. Frontend interaction is controlled by JSF backing bean in this layer.

Service Layer:

Spring managed singleton service object is used. Business service and application logic are written in this layer

Data Layer:

Spring data MongoDB component is used. It provides integration with the MongoDB document-oriented database. It provides MongoTemplate so that MongoDB operation could be performed easily. Moreover, Spring repository style data access layer could be easily written with spring data MongoDB.

MongoDB schema design and data preparation

MongoDB Introduction

MongoDB is a open-source scalable, high-performance NoSQL database. It is a document-oriented Storage. It can store JSON-style documents with dynamic schemas. In this application, each product is stored as JSON-style document in MongoDB.

Schema Design in MongoDB

Each product in the catalog contains general product information (e.g. sku, title, and product type), price details (e.g. retail and list price) and product sub-details (e.g. tracks of audio CDs / chapters of books). In this application, MongoDB is used. The schema design will be focus more on the data usage. It is different from traditional RDBMS schema design. The schema design in MongoDB should be:

Sample Data:

x= {
  sku: '1000001',
  type: 'Audio Album',
  title: 'A Love Supreme',
  description: 'by John Coltrane',
  publisher: 'Sony Music',
  pricing: {
    list: 1200,
    retail: 1100
  },

  details: {
    title: 'A Love Supreme [Original Recording Reissued]',
    artist: 'John Coltrane',
    genre:  'Jazz' ,
    tracks: [
      'A Love Supreme Part I: Acknowledgement',
      'A Love Supreme Part II - Resolution',
      'A Love Supreme, Part III: Pursuance',
      'A Love Supreme, Part IV-Psalm'
    ],
  }
}

y= {
  sku: '1000002',
  type: 'Audio Album',
  title: 'Love Song',
  description: 'by Khali Fong',
  publisher: 'Sony Music',
  pricing: {
    list: 1000,
    retail: 1200
  },

  details: {
    title: 'Long Song [Original Recording Reissued]',
    artist: 'Khali Fong',
    genre:  'R&B',
    tracks: [
      'Love Song',
      'Spring Wind Blow',
      'Red Bean',
      'SingAlongSong'
    ],
  }
}

z= {
  sku: '1000003',
  type: 'Book',
  title: 'Node.js for PHP Developers',
  description: 'by Owen Peter',
  publisher: 'OReilly Media',

  pricing: {
    list: 2500,
    retail: 2100
  },

  details: {
    title: 'Node.js for PHP Developers',
    author: 'Mark Owen',
    genre:  'Technology',
    chapters: [
      'Introduction to Node',
      'Server-side JS',
      'PHP API',
      'Example'
    ],
  }
}

Sample query to add the data:

db.product.save(x);
db.product.save(y);
db.product.save(z);

Sample query to test the sample data:

db.product.find({'sku':'1000004'});
db.product.find({'type':'Audio Album'});
db.product.find({'type':'Audio Album', 'details.genre': 'Jazz'});

JSF (PrimeFaces) and Spring data MongoDB Integration

pom.xml of the project

<project xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd'>
  <modelversion>4.0.0</modelVersion>
  <groupid>com.borislam</groupId>
  <artifactid>mongoShop</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>MongoShop Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
  <dependency>
     <groupid>org.jboss.el</groupId>
     <artifactid>com.springsource.org.jboss.el</artifactId>
     <version>2.0.0.GA</version>
 </dependency>
    <dependency>  
     <groupid>org.primefaces.themes</groupId>  
     <artifactid>all-themes</artifactId>  
     <version>1.0.9</version>  
    </dependency>
    <dependency>  
  <groupid>org.primefaces</groupId>  
  <artifactid>primefaces</artifactId>  
  <version>3.4.2</version>  
 </dependency>
 <dependency>
  <groupid>commons-beanutils</groupId>
  <artifactid>commons-beanutils</artifactId>
  <version>1.8.3</version>
 </dependency> 

 <dependency>
  <groupid>commons-codec</groupId>
  <artifactid>commons-codec</artifactId>
  <version>1.3</version>
 </dependency> 

 <dependency>
  <groupid>org.apache.directory.studio</groupId>
  <artifactid>org.apache.commons.lang</artifactId>
  <version>2.6</version>
 </dependency>

 <dependency>
  <groupid>commons-digester</groupId>
  <artifactid>commons-digester</artifactId>
  <version>1.8</version>
 </dependency>

 <dependency>
  <groupid>commons-collections</groupId>
  <artifactid>commons-collections</artifactId>
  <version>3.2</version>
 </dependency>

 <dependency>
  <groupid>org.apache.myfaces.core</groupId>
  <artifactid>myfaces-api</artifactId>
  <version>2.1.9</version>
 </dependency>

 <dependency>
  <groupid>org.apache.myfaces.core</groupId>
  <artifactid>myfaces-impl</artifactId>
  <version>2.1.9</version>
 </dependency>

   <dependency>
  <groupid>org.mongodb</groupId>
  <artifactid>mongo-java-driver</artifactId>
  <version>2.10.1</version>
 </dependency>
    <dependency>
      <groupid>junit</groupId>
      <artifactid>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
 <dependency>
  <groupid>org.springframework.data</groupId>
  <artifactid>spring-data-mongodb</artifactId>
  <version>1.0.3.RELEASE</version>
 </dependency> 
 <dependency>
   <groupid>org.springframework</groupId>
   <artifactid>spring-context</artifactId>
   <version>3.2.0.RELEASE</version>
 </dependency> 
 <dependency>
   <groupid>org.springframework</groupId>
   <artifactid>spring-web</artifactId>
   <version>3.2.0.RELEASE</version>
 </dependency>
  </dependencies>
  <repositories>
    <repository>
  <id>java.net</id>
  <url>https://maven.java.net/content/repositories/public/</url>
    </repository>
 <repository>  
  <id>prime-repo</id>  
  <name>PrimeFaces Maven Repository</name>  
  <url>http://repository.primefaces.org</url>  
  <layout>default</layout>  
 </repository>

 <repository>
  <id>com.springsource.repository.bundles.release</id>
  <name>SpringSource Enterprise Bundle Repository - SpringSource Releases</name>
  <url>http://repository.springsource.com/maven/bundles/release</url>
 </repository>

 <repository>
  <id>com.springsource.repository.bundles.external</id>
  <name>SpringSource Enterprise Bundle Repository - External Releases</name>
  <url>http://repository.springsource.com/maven/bundles/external</url>
 </repository>
 <repository>
         <releases>
           <enabled>false</enabled>
         </releases>
         <snapshots>
           <enabled>true</enabled>
         </snapshots>
         <id>apache.snapshots</id>
         <name>Apache Snapshot Repository</name>
         <url>https://repository.apache.org/content/repositories/snapshots</url>
    </repository> 
 <repository>
          <id>jboss-deprecated-repository</id>
          <name>JBoss Deprecated Maven Repository</name>
          <url>https://repository.jboss.org/nexus/content/repositories/deprecated/</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
            <updatepolicy>never</updatePolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
            <updatepolicy>never</updatePolicy>
          </snapshots>
        </repository>
  </repositories>
  <build>
    <finalname>mongoShop</finalName>
  </build>
</project>

MyFaces

MyFaces is used as the JSF implementation in this application. The following details should be added in web.xml

PrimeFaces 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

<context-param>
  <param-name>primefaces.THEME</param-name><param-value>glass-x</param-value></context-param>

JSF and Spring Integration:

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

Faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version='2.0' xmlns='http://java.sun.com/xml/ns/javaee'
  xmlns:xi='http://www.w3.org/2001/XInclude'
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
  xsi:schemaLocation='http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd'>
   <application>
     <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
   </application>
   <factory>
 <partial-view-context-factory>org.primefaces.context.PrimePartialViewContextFactory</partial-view-context-factory>
   </factory> 
</faces-config>

Full web.xml

<?xml version='1.0' encoding='UTF-8'?>
<web-app id='WebApp_ID' version='3.0'
 xmlns='http://java.sun.com/xml/ns/javaee'
 xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
 xsi:schemaLocation='http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd'>
 <context-param>
 <param-name>contextConfigLocation</param-name><param-value>WEB-INF/spring-application-context.xml</param-value></context-param>
 <context-param>
  <param-name>errorPageUrl</param-name><param-value>/pages/systemError.do</param-value></context-param>
 <context-param>
  <param-name>facelets.DEVELOPMENT</param-name><param-value>false</param-value></context-param>
 <context-param>
   <param-name>facelets.REFRESH_PERIOD</param-name><param-value>2</param-value></context-param>
 <context-param>
   <param-name>javax.faces.STATE_SAVING_METHOD</param-name><param-value>client</param-value></context-param>
 <context-param>
   <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name><param-value>resources.application</param-value></context-param>
 <context-param>
   <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name><param-value>true</param-value></context-param>
  <context-param>
    <param-name>org.apache.myfaces.AUTO_SCROLL</param-name><param-value>false</param-value></context-param>
 <context-param>
    <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name><param-value>false</param-value></context-param>
 <context-param>
  <param-name>org.apache.myfaces.ERROR_HANDLING</param-name><param-value>false</param-value></context-param>
 <context-param>
  <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name><param-value>org.jboss.el.ExpressionFactoryImpl</param-value></context-param>
 <context-param>
  <param-name>org.apache.myfaces.PRETTY_HTML</param-name><param-value>false</param-value></context-param>
 <context-param>
  <param-name>primefaces.THEME</param-name><param-value>glass-x</param-value></context-param>  
 <servlet>
   <servlet-name>Faces Servlet</servlet-name>
   <servlet-class>org.apache.myfaces.webapp.MyFacesServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
  </servlet>
 <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
 </servlet-mapping>
 <listener>
 <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
 </listener>
 <listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
</web-app>

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

<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns='http://www.springframework.org/schema/beans'
xmlns:context='http://www.springframework.org/schema/context'
 xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
 xmlns:util='http://www.springframework.org/schema/util'
 xmlns:mongo='http://www.springframework.org/schema/data/mongo'
 xsi:schemaLocation='http://www.springframework.org/schema/beans        
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
          http://www.springframework.org/schema/data/mongo
          http://www.springframework.org/schema/data/mongo/spring-mongo.xsd            
              http://www.springframework.org/schema/data/repository
    http://www.springframework.org/schema/data/repository/spring-repository.xsd 
             http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context-3.2.xsd
                http://www.springframework.org/schema/util 
                http://www.springframework.org/schema/util/spring-util-3.2.xsd'>

 <context:annotation-config/>
 <context:component-scan base-package='com.borislam'/>

 <mongo:mongo host='localhost' port='27017'> 
  <mongo:options
       connections-per-host='5'       
       connect-timeout='30000'
       max-wait-time='10000'       
       write-number='1'
       write-timeout='0'
       write-fsync='true'/>
 </mongo:mongo>

 <mongo:db-factory dbname='test' mongo-ref='mongo'/>

 <mongo:repositories base-package='com.borislam.repository' />

 <bean id='mongoTemplate' class='org.springframework.data.mongodb.core.MongoTemplate'>
     <constructor-arg ref='mongo'/><constructor-arg name='databaseName' value='test'/></bean>
</beans>

Enquriy data with spring data repository and mongotemplate

Spring Data Repository:

Spring Data repository abstraction reduces the boilerplate code to write the data access layer of the application. Automatic implementation of Repository interfaces provides simple operation on mongoDB. It helps our product save and delete function make

MongoTemplate:

MongoTemplate offers convenience operations to create, update, delete and query for MongoDB documents and provides a mapping between your domain objects and MongoDB documents. In our application, since the spring data repository cannot fulfill the requirement of searching function, we use MongoTemplate to archive the searching capability.

Customizing Spring Data Repository:

Since the searching of product cannot be easily implement with Spring data repository abstraction, we would like to implements the multi-criteira product search with MongoDBTemplate. To enrich Spring data repository with MongoTemplate, we can do the following to customize the repository:

ProductRepository.java

package com.borislam.repository;

import java.util.List;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.borislam.domain.Product;

public interface ProductRepository  extends PagingAndSortingRepository<Product, String> , ProductRepostitoryCustom{

 List<product> findByType(String type);
 List<product> findByTypeAndTitle(String type, String title); 
 Product findBySku(String sku);
}

ProductRepositoryCustom.java

package com.borislam.repository;

import java.util.List;
import com.borislam.domain.Product;
import com.borislam.view.ProductSearchCriteria;

public interface ProductRepostitoryCustom {
 public List<product> searchByCriteria(ProductSearchCriteria criteria);

}

ProductRepositoryImpl.java

package com.borislam.repository.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.util.StringUtils;
import com.borislam.domain.Product;
import com.borislam.repository.ProductRepostitoryCustom;
import com.borislam.view.ProductSearchCriteria;

public class ProductRepositoryImpl implements ProductRepostitoryCustom{

 @Autowired
 private MongoTemplate mongoTemplate;

 @Override
 public List<product> searchByCriteria(ProductSearchCriteria criteria) {
  Query query = new Query();
  if ( StringUtils.hasText(criteria.getSku())) 
  { 
   Criteria c = Criteria.where('sku').is(criteria.getSku());
   query.addCriteria(c);
  }
  if (StringUtils.hasText(criteria.getTitle())) {
   Criteria c = Criteria.where('title').regex('.*' + criteria.getTitle() + '.*', 'i');
   query.addCriteria(c);
  }
  if (StringUtils.hasText(criteria.getDescription())) {
   Criteria c = Criteria.where('description').regex('.*' + criteria.getDescription() + '.*', 'i');
   query.addCriteria(c);
  }
  if (StringUtils.hasText(criteria.getProductType())) {
   Criteria c = Criteria.where('type').is(criteria.getProductType());
   query.addCriteria(c);

  }  
  if (StringUtils.hasText(criteria.getTrack())) {
   Criteria c = Criteria.where('details.tracks').regex('.*' + criteria.getTrack() + '.*', 'i');
   query.addCriteria(c);
  }
  if (StringUtils.hasText(criteria.getChapter())) {
   Criteria c = Criteria.where('details.chapters').regex('.*' + criteria.getChapter() + '.*', 'i');
   query.addCriteria(c);
  }
  return mongoTemplate.find(query, Product.class);
 }

}

Data Model:Product.java

package com.borislam.domain;

public class Product {
  private String id;
  private String sku ;
  private String  type;
  private String title;
  private String description;
  private String publisher;
  private Pricing pricing;
  private Detail details;
 public String getId() {
  return id;
 }
 public void setId(String id) {
  this.id = id;
 }
 public String getSku() {
  return sku;
 }
 public void setSku(String sku) {
  this.sku = sku;
 }
 public String getType() {
  return type;
 }
 public void setType(String type) {
  this.type = type;
 }
 public String getTitle() {
  return title;
 }
 public void setTitle(String title) {
  this.title = title;
 }
 public String getDescription() {
  return description;
 }
 public void setDescription(String description) {
  this.description = description;
 }
 public String getPublisher() {
  return publisher;
 }
 public void setPublisher(String publisher) {
  this.publisher = publisher;
 }
 public Pricing getPricing() {
  return pricing;
 }
 public void setPricing(Pricing pricing) {
  this.pricing = pricing;
 }
 public Detail getDetails() {
  return details;
 }
 public void setDetails(Detail details) {
  this.details = details;
 }    
}

Pricing.java

package com.borislam.domain;

public class Pricing {
 private String id;
 private double list;
 private double retail;
 public String getId() {
  return id;
 }
 public void setId(String id) {
  this.id = id;
 }
 public double getList() {
  return list;
 }
 public void setList(double list) {
  this.list = list;
 }
 public double getRetail() {
  return retail;
 }
 public void setRetail(double retail) {
  this.retail = retail;
 }
 public Pricing(double list, double retail) {
  super();
  this.list = list;
  this.retail = retail;
 }

}

Detail.java

package com.borislam.domain;

import java.util.List;

public class Detail {
 private String id;
 private String title;
 private String author;
 private String artist;
 private String genre;
 private List<string> pic;
 private List<string> chapters;
 private List<string> tracks;
 public String getTitle() {
  return title;
 }
 public void setTitle(String title) {
  this.title = title;
 }
 public String getAuthor() {
  return author;
 }
 public void setAuthor(String author) {
  this.author = author;
 }
 public String getGenre() {
  return genre;
 }
 public void setGenre(String genre) {
  this.genre = genre;
 }
 public List<string> getPic() {
  return pic;
 }
 public void setPic(List<string> pic) {
  this.pic = pic;
 }
 public List<string> getChapters() {
  return chapters;
 }
 public void setChapters(List<string> chapters) {
  this.chapters = chapters;
 }
 public String getId() {
  return id;
 }
 public void setId(String id) {
  this.id = id;
 }
 public String getArtist() {
  return artist;
 }
 public void setArtist(String artist) {
  this.artist = artist;
 }
 public List<string> getTracks() {
  return tracks;
 }
 public void setTracks(List<string> tracks) {
  this.tracks = tracks;
 }

}

JSF Part:common.xhtml

<html xmlns='http://www.w3.org/1999/xhtml'
 xmlns:h='http://java.sun.com/jsf/html'
 xmlns:f='http://java.sun.com/jsf/core'
 xmlns:ui='http://java.sun.com/jsf/facelets'
 xmlns:p='http://primefaces.org/ui'>

<f:view contentType='text/html'>

 <h:head>

  <f:facet name='first'>
   <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
   <title><ui:insert name='pageTitle'>Page Title</ui:insert></title>
   <ui:insert name='head' />
  </f:facet>

 </h:head>

 <h:body>
  <div style='margin:auto;width:1024px;'>
<div id='header' class='ui-widget' >
<div id='logo' style='border:1px  solid #acbece; border-bottom: none; '>
<p:graphicImage   value='/resources/image/mongoshopheader.jpg'/></div>
<div id='logo' style='border:1px solid #acbece;'>
<p:menubar style='border:none'><p:menuitem value='Search' url='/search.jsf' icon='ui-icon-search' /><p:menuitem value='New Product' url='/detail.jsf' icon='ui-icon-document' /></p:menubar></div>
</div>
<div id='page' class='ui-widget' style='overflow:hidden;'>
<div id='content'  style='display:block'>
<ui:insert name='content'>...</ui:insert>     
             </div>
</div>
</div>
</h:body>

</f:view>
</html>

Search.xhml

<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:p='http://primefaces.org/ui'>

 <ui:composition template='/template/common.xhtml'>

  <ui:define name='pageTitle'>
   <h:outputText value='Product Search' />
  </ui:define>

  <ui:define name='content'>
      <h:form id='searchForm'>
       <p:growl id='mainGrowl' sticky='true'  /><p:panelGrid style='width:1024px'><f:facet name='header'>
     <p:row><p:column colspan='4'>Product Search
             </p:column></p:row></f:facet>  
       <p:row><p:column><h:outputLabel for='sku' value='sku: ' />
         </p:column><p:column><p:inputText id='sku' value='#{productSearchBean.criteria.sku}' /></p:column><p:column><h:outputLabel for='productType' value='Product Type: ' />
         </p:column><p:column><p:selectOneMenu id='productType'   label='Type'   value='#{productSearchBean.criteria.productType}'  ><f:selectItem itemLabel='Select One' itemValue='' />  
                 <f:selectItem itemLabel='Audio Album' itemValue='Audio Album' />  
                 <f:selectItem itemLabel='Book' itemValue='Book' /> 
             </p:selectOneMenu></p:column></p:row><p:row><p:column><h:outputLabel for='title' value='Title: ' />
         </p:column><p:column><p:inputText id='title' value='#{productSearchBean.criteria.title}' /></p:column><p:column><h:outputLabel for='description' value='Description: ' />
         </p:column><p:column><p:inputText id='description' value='#{productSearchBean.criteria.description}' /></p:column></p:row><p:row><p:column><h:outputLabel for='track' value='Track: ' />
         </p:column><p:column><p:inputText id='track' value='#{productSearchBean.criteria.track}' /></p:column><p:column><h:outputLabel for='chapter' value='Chapter: ' />
         </p:column><p:column><p:inputText id='chapter' value='#{productSearchBean.criteria.chapter}' /></p:column></p:row></p:panelGrid><p:commandButton value='search' icon='ui-icon-search'  actionListener='#{productSearchBean.doSearch}' update='dataTable'/><hr/><p:dataTable id='dataTable' var='prod' value='#{productSearchBean.productList}'  
     paginator='true' rows='10'><p:column><f:facet name='header'>  
                    <h:outputText value='Sku' />  
                </f:facet>  
                <h:outputText value='#{prod.sku}' />  
            </p:column><p:column><f:facet name='header'>  
                    <h:outputText value='Type' />  
                </f:facet>  
                <h:outputText value='#{prod.type}' />  
            </p:column><p:column><f:facet name='header'>  
                    <h:outputText value='Title' />  
                </f:facet>  
                <h:outputText value='#{prod.title}' />  
            </p:column><p:column><f:facet name='header'>  
                    <h:outputText value='Publisher' />  
                </f:facet>  
                <h:outputText value='#{prod.publisher}' />  
            </p:column><p:column><f:facet name='header'>  
                    <h:outputText value='Artist' />  
                </f:facet>  
                <h:outputText value='#{prod.details.artist}' />  
            </p:column><p:column><f:facet name='header'>  
                    <h:outputText value='Author' />  
                </f:facet>  
                <h:outputText value='#{prod.details.author}' />  
            </p:column></p:dataTable></h:form>
  </ui:define>
 </ui:composition>
</html>

ProductSearchCriteria.java

package com.borislam.view;

public class ProductSearchCriteria {
 private String sku;
 private String description;
 private String productType;
 private String track;
 private String chapter;
 private String title;
 public String getSku() {
  return sku;
 }
 public void setSku(String sku) {
  this.sku = sku;
 }
 public String getDescription() {
  return description;
 }
 public void setDescription(String description) {
  this.description = description;
 }
 public String getProductType() {
  return productType;
 }
 public void setProductType(String productType) {
  this.productType = productType;
 }
 public String getTrack() {
  return track;
 }
 public void setTrack(String track) {
  this.track = track;
 }
 public String getTitle() {
  return title;
 }
 public void setTitle(String title) {
  this.title = title;
 }
 public String getChapter() {
  return chapter;
 }
 public void setChapter(String chapter) {
  this.chapter = chapter;
 }

}

ProductSearchBean.java

package com.borislam.view;

import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;
import com.borislam.domain.Product;
import com.borislam.service.ProductService;

@Component
@Scope('session')
public class ProductSearchBean {

 private Product selectedProduct;

 private ProductSearchCriteria criteria = new ProductSearchCriteria();

 private List<product> productList;

 public Product getSelectedProduct() {
  return selectedProduct;
 }

 public void setSelectedProduct(Product selectedProduct) {
  this.selectedProduct = selectedProduct;
 }

 public List<product> getProductList() {
  return productList;
 }

 public void setProductList(List<product> productList) {
  this.productList = productList;
 }

 public ProductSearchCriteria getCriteria() {
  return criteria;
 }

 public void setCriteria(ProductSearchCriteria criteria) {
  this.criteria = criteria;
 }
 @Autowired
 private ProductService productService;

 public void doSearch(ActionEvent event){
  productList= productService.searchByCriteria(criteria);
 }
}

Service Layer:ProductService.java

package com.borislam.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.borislam.domain.Product;
import com.borislam.repository.ProductRepository;
import com.borislam.view.ProductSearchCriteria;

@Service
public class ProductService {

 @Autowired
 private ProductRepository productRepository;

 public List<product> searchByCriteria(ProductSearchCriteria criteria){
  return productRepository.searchByCriteria(criteria);
 }

 public Product getProduct(String sku) {
  return productRepository.findBySku(sku);
 }
}

Create, Edit and Delete data with Spring data repository

In the last part of this tutorial, we will add create, edit and delete function to the MongoShop Product Catalog application. The search page is modified. A modal confirm dialogue box is added before the product is physically deleted

updated search.xhtml

<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:p='http://primefaces.org/ui'>

 <ui:composition template='/template/common.xhtml'>

  <ui:define name='pageTitle'>
   <h:outputText value='Product Search' />
  </ui:define>

  <ui:define name='content'>
      <h:form id='searchForm'>
       <p:growl id='mainGrowl' sticky='true'  />
       <p:panelGrid style='width:1024px'>  
        <f:facet name='header'>
         <p:row>  
                <p:column colspan='4'>  
              Product Search
             </p:column>
            </p:row>
        </f:facet>  
       <p:row> 
        <p:column>
          <h:outputLabel for='sku' value='sku: ' />
         </p:column>
         <p:column>  
          <p:inputText id='sku' value='#{productSearchBean.criteria.sku}' />
         </p:column>  
         <p:column>  
          <h:outputLabel for='productType' value='Product Type: ' />
         </p:column>
            <p:column>  
          <p:selectOneMenu id='productType'   label='Type'   value='#{productSearchBean.criteria.productType}'  >  
                 <f:selectItem itemLabel='Select One' itemValue='' />  
                 <f:selectItem itemLabel='Audio Album' itemValue='Audio Album' />  
                 <f:selectItem itemLabel='Book' itemValue='Book' /> 
             </p:selectOneMenu>
         </p:column>
       </p:row>
       <p:row> 
        <p:column>
          <h:outputLabel for='title' value='Title: ' />
         </p:column>
         <p:column>  
          <p:inputText id='title' value='#{productSearchBean.criteria.title}' />
         </p:column>  
         <p:column>  
          <h:outputLabel for='description' value='Description: ' />
         </p:column>
            <p:column>  
          <p:inputText id='description' value='#{productSearchBean.criteria.description}' />
         </p:column>
       </p:row>      

       <p:row> 
        <p:column>
          <h:outputLabel for='track' value='Track: ' />
         </p:column>
         <p:column>  
          <p:inputText id='track' value='#{productSearchBean.criteria.track}' />
         </p:column>  
         <p:column>  
          <h:outputLabel for='chapter' value='Chapter: ' />
         </p:column>
            <p:column>  
          <p:inputText id='chapter' value='#{productSearchBean.criteria.chapter}' />
         </p:column>
       </p:row> 

     </p:panelGrid>
     <p:commandButton value='search' icon='ui-icon-search'  actionListener='#{productSearchBean.doSearch}' update='dataTable'/>
     <hr/>

     <p:dataTable id='dataTable' var='prod' value='#{productSearchBean.productList}'  
                  paginator='true' rows='10'>  

            <p:column>  
                <f:facet name='header'>  
                    <h:outputText value='Sku' />  
                </f:facet>  
                <h:outputText value='#{prod.sku}' />  
            </p:column>  

        <p:column>  
                <f:facet name='header'>  
                    <h:outputText value='Type' />  
                </f:facet>  
                <h:outputText value='#{prod.type}' />  
            </p:column> 

            <p:column>  
                <f:facet name='header'>  
                    <h:outputText value='Title' />  
                </f:facet>  
                <h:outputText value='#{prod.title}' />  
            </p:column>  

            <p:column>  
                <f:facet name='header'>  
                    <h:outputText value='Publisher' />  
                </f:facet>  
                <h:outputText value='#{prod.publisher}' />  
            </p:column>  

             <p:column>  
                <f:facet name='header'>  
                    <h:outputText value='Artist' />  
                </f:facet>  
                <h:outputText value='#{prod.details.artist}' />  
            </p:column>  

       <p:column>  
                <f:facet name='header'>  
                    <h:outputText value='Author' />  
                </f:facet>  
                <h:outputText value='#{prod.details.author}' />  
            </p:column>  

        <p:column>  
                <f:facet name='header'>  
                    <h:outputText value='Edit' />  
                </f:facet>  
                 <p:commandButton value='Edit'  action='#{productSearchBean.doEditDetail}' ajax='false'>
                  <f:setPropertyActionListener target='#{productSearchBean.selectedProduct}' value='#{prod}' />
                 </p:commandButton>
            </p:column>  

       <p:column>  
                <f:facet name='header'>  
                    <h:outputText value='Delete' />  
                </f:facet>

                <p:commandButton id='showDialogButton' value='Delete' oncomplete='confirmation.show()' ajax='true' update=':searchForm:confirmDialog'>  
                  <f:setPropertyActionListener target='#{productSearchBean.selectedProduct}' value='#{prod}' />
                </p:commandButton>

            </p:column>

        </p:dataTable>

      <p:confirmDialog id='confirmDialog' message='Are you sure to delete this product (#{productSearchBean.selectedProduct.sku})?'  
                    header='Delete Product' severity='alert' widgetVar='confirmation'>  

            <p:commandButton id='confirm' value='Yes' update='mainGrowl' oncomplete='confirmation.hide()'  
                        actionListener='#{productSearchBean.doDelete}' />  
            <p:commandButton id='decline' value='No' onclick='confirmation.hide()' type='button' />   

        </p:confirmDialog>

      </h:form>
  </ui:define>
 </ui:composition>
</html>

updated ProductSearchBean.java

package com.borislam.view;

import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;
import com.borislam.domain.Product;
import com.borislam.service.ProductService;

@Component
@Scope('session')
public class ProductSearchBean {

 private Product selectedProduct;

 private ProductSearchCriteria criteria = new ProductSearchCriteria();

 private List<Product> productList;

 public Product getSelectedProduct() {
  return selectedProduct;
 }

 public void setSelectedProduct(Product selectedProduct) {
  this.selectedProduct = selectedProduct;
 }

 public List<Product> getProductList() {
  return productList;
 }

 public void setProductList(List<Product> productList) {
  this.productList = productList;
 }

 public ProductSearchCriteria getCriteria() {
  return criteria;
 }

 public void setCriteria(ProductSearchCriteria criteria) {
  this.criteria = criteria;
 }
 @Autowired
 private ProductService productService;

 public void doSearch(ActionEvent event){
  productList= productService.searchByCriteria(criteria);
 }

 public String doEditDetail() {
  (FacesContext.getCurrentInstance().getExternalContext().getFlash()).put('selected', selectedProduct);
  return 'detail.xhtml';
 }

 public void doDelete(ActionEvent event){
  try {   
   productService.deleteProduct(selectedProduct);

   FacesContext context = FacesContext.getCurrentInstance();  
         context.addMessage(null, new FacesMessage('Delete Successfully!'));
  }
  catch (DataAccessException e ) {
   FacesContext context = FacesContext.getCurrentInstance();  
         context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,'Error when deleting product!',null));
  }

 }
}

A product detail page is added to view the produc details. Creation and edition of product is done in the product detail page.

detail.xhtml

<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:p='http://primefaces.org/ui'>

 <ui:composition template='/template/common.xhtml'>

  <ui:define name='pageTitle'>
   <h:outputText value='Product Search' />
  </ui:define>

  <ui:define name='content'>
     <f:event listener='#{productDetailBean.initProduct}' type='preRenderView' />

      <h:form id='mainForm'>      
       <p:growl id='mainGrowl' sticky='true'  />
       <p:panelGrid style='width:1024px'>  
        <f:facet name='header'>
         <p:row>  
                <p:column colspan='2'>  
              Product Details
             </p:column>
            </p:row>
        </f:facet>  
       <p:row> 
        <p:column>
          <h:outputLabel for='sku' value='sku: *' />
         </p:column>
         <p:column>  
          <p:inputText id='sku' required='true' value='#{productDetailBean.product.sku}' label='Sku'  rendered='#{productDetailBean.newProduct}'/>
          <h:outputText  value='#{productDetailBean.product.sku}' label='Sku' rendered='#{not productDetailBean.newProduct}'/>
         </p:column>  
       </p:row>
       <p:row> 
        <p:column>
          <h:outputLabel for='type' value='Type *' />
         </p:column>
         <p:column>  
          <p:selectOneMenu id='type' required='true'  label='Type'  valueChangeListener='#{productDetailBean.clearDetails}' value='#{productDetailBean.product.type}'  >  
                 <f:selectItem itemLabel='Select One' itemValue='' />  
                 <f:selectItem itemLabel='Audio Album' itemValue='Audio Album' />  
                 <f:selectItem itemLabel='Book' itemValue='Book' /> 
                 <f:ajax  render='buttonPanel trackPanel chapterPanel'/>
             </p:selectOneMenu>
         </p:column>  
       </p:row> 
       <p:row> 
        <p:column>
          <h:outputLabel for='title' value='Title: *' />
         </p:column>
         <p:column>  
          <p:inputText id='title' required='true' value='#{productDetailBean.product.title}' label='Title' />
         </p:column>  
       </p:row> 
       <p:row> 
        <p:column>
          <h:outputLabel for='description' value='Description: *' />
         </p:column>
         <p:column>  
          <p:inputText id='description' required='true' value='#{productDetailBean.product.description}' label='Description' />
         </p:column>  
       </p:row> 
       <p:row> 
        <p:column>
          <h:outputLabel for='publisher' value='Publisher: *' />
         </p:column>
         <p:column>  
          <p:inputText id='publisher' required='true' value='#{productDetailBean.product.publisher}' label='Publisher' />
         </p:column>  
       </p:row> 

        <p:row> 
        <p:column>
          <h:outputLabel for='artist' value='Artist: ' />
         </p:column>
         <p:column>  
          <p:inputText id='artist'  value='#{productDetailBean.product.details.artist}' label='Artist' />
         </p:column>  
       </p:row>  

        <p:row> 
        <p:column>
          <h:outputLabel for='listPrice' value='List Price: ' />
         </p:column>
         <p:column>  
          <p:inputText id='listPrice'  required='true' value='#{productDetailBean.product.pricing.list}' label='List Price' />
         </p:column>  
       </p:row>  

         <p:row> 
        <p:column>
          <h:outputLabel for='retailPrice' value='Retail Price: ' />
         </p:column>
         <p:column>  
          <p:inputText id='retailPrice'  required='true' value='#{productDetailBean.product.pricing.retail}' label='REtail Price' />
         </p:column>  
       </p:row>  

        <p:row> 
        <p:column>
          <h:outputLabel for='author' value='Author: ' />
         </p:column>
         <p:column>  
          <p:inputText id='author'  value='#{productDetailBean.product.details.author}' label='Author' />
         </p:column>  
       </p:row> 

        <p:row> 
        <p:column>
          <h:outputLabel for='genre' value='Genre: *' />
         </p:column>
         <p:column>  
          <p:inputText id='genre' required='true' value='#{productDetailBean.product.details.genre}' label='Genre' />
         </p:column>  
       </p:row> 

      <p:row>  
            <p:column colspan='2' styleClass='ui-widget-header'>  
             <p:outputPanel id='buttonPanel'>            
                 <p:commandButton value='Add Tracks'   onclick='addTrackDlg.show();' type='button' rendered='#{productDetailBean.product.type == 'Audio Album'}'/>               
                 <p:commandButton value='Add Chapters'   onclick='addChapterDlg.show();' type='button' rendered='#{productDetailBean.product.type == 'Book'}'/>
                </p:outputPanel>
            </p:column>  
        </p:row>

        <p:row>  
            <p:column colspan='2' > 
             <p:outputPanel id='trackPanel' >
                 <p:dataList value='#{productDetailBean.product.details.tracks}' var='track' type='ordered' rendered='#{productDetailBean.product.details.tracks.size() > 0}'>  
            #{track} 
        </p:dataList> 
       </p:outputPanel>
       <p:outputPanel id='chapterPanel' >
        <p:dataList value='#{productDetailBean.product.details.chapters}' var='chapter' type='ordered' rendered='#{productDetailBean.product.details.chapters.size() > 0}'>  
            #{chapter} 
        </p:dataList> 
       </p:outputPanel> 

            </p:column>  
        </p:row> 

        <f:facet name='footer'> 
         <p:row>
          <p:column colspan='2'>  
           <p:commandButton value='Save' icon='ui-icon-disk'  actionListener='#{productDetailBean.doSave}' update='mainGrowl' />
           <p:button value='Back to Search' icon='ui-icon-back'  outcome='search.xhtml' />
          </p:column>
         </p:row>          
        </f:facet>  
    </p:panelGrid>   

   </h:form>

   <h:form>   
    <p:growl id='trackGrowl' sticky='true'  />
    <p:dialog id='addTrackDlg' header='Adding Tracks for the product' widgetVar='addTrackDlg' modal='true' height='100' width='450' resizable='false'>  
        <h:outputLabel for='track' value='Track: ' /> 
        <p:inputText id='track' required='true' value='#{productDetailBean.newTrack}' label='Track' /> 
        <p:commandButton value='Add' actionListener='#{productDetailBean.doAddTracks}' icon='ui-icon-check'  update='trackGrowl, :mainForm:trackPanel' oncomplete='addTrackDlg.hide()'/>
    </p:dialog> 
   </h:form> 

   <h:form>
    <p:growl id='chapterGrowl' sticky='true'  /> 
    <p:dialog id='addChapterDlg' header='Adding Chapters for the product' widgetVar='addChapterDlg' modal='true' height='100' width='450' resizable='false'>  
        <h:outputLabel for='chapter' value='Chapter: ' /> 
        <p:inputText id='chapter' required='true' value='#{productDetailBean.newChapter}' label='Chapter' /> 
        <p:commandButton value='Add' actionListener='#{productDetailBean.doAddChapters}' icon='ui-icon-check'  update='chapterGrowl, :mainForm:chapterPanel' oncomplete='addChapterDlg.hide()'/>

    </p:dialog> 
   </h:form> 
  </ui:define>
 </ui:composition>
</html>

ProductDetailsBean.java

package com.borislam.view;

import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.dao.DataAccessException;

import com.borislam.domain.Detail;
import com.borislam.domain.Pricing;
import com.borislam.domain.Product;
import com.borislam.service.ProductService;

@Component
@Scope('session')
public class ProductDetailBean {

 @Autowired
 private ProductService productService;
 private boolean newProduct;
 private Product product;
 private String newTrack;
 private String newChapter;

 public boolean isNewProduct() {
  return newProduct;
 }

 public void setNewProduct(boolean newProduct) {
  this.newProduct = newProduct;
 }

 public Product getProduct() {
  return product;
 }

 public void setProduct(Product product) {
  this.product = product;
 }

 public String getNewTrack() {
  return newTrack;
 }

 public void setNewTrack(String newTrack) {
  this.newTrack = newTrack;
 }

 public String getNewChapter() {
  return newChapter;
 }

 public void setNewChapter(String newChapter) {
  this.newChapter = newChapter;
 }

 public void initProduct(){
  Object selectedProduct = (FacesContext.getCurrentInstance().getExternalContext().getFlash()).get('selected');

  if (selectedProduct==null &&  !FacesContext.getCurrentInstance().isPostback()) {
   product = new Product();
   product.setDetails(new Detail());
   product.setPricing(new Pricing(0,0));
   setNewProduct(true);
  }
  if (selectedProduct!=null) {
   product = (Product)selectedProduct;
   setNewProduct(false);
  }

 }

 public void  doSave(ActionEvent event) {

  try {
   productService.saveProduct(product);

   FacesContext context = FacesContext.getCurrentInstance();  
         context.addMessage(null, new FacesMessage('Save Successfully!'));
  }
  catch (DataAccessException e)
  { 
   e.printStackTrace();

   FacesContext context = FacesContext.getCurrentInstance();  
         context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,'Error when saving product!',null));

  }

 }

 public void  doAddTracks(ActionEvent event) {
  List<String> tracks = product.getDetails().getTracks();
  if (CollectionUtils.isEmpty(tracks)) {
   product.getDetails().setTracks(new ArrayList<String>());
  }
  product.getDetails().getTracks().add(this.newTrack);

 }

 public void  doAddChapters(ActionEvent event) {
  List<String> tracks = product.getDetails().getChapters();
  if (CollectionUtils.isEmpty(tracks)) {
   product.getDetails().setChapters(new ArrayList<String>() );
  }
  product.getDetails().getChapters().add(this.newChapter);

 }

 public void clearDetails(ValueChangeEvent  event) {

  if ('Audio Album'.equalsIgnoreCase(event.getNewValue().toString()) ) {
   product.getDetails().setChapters(null);
  }
  if ('Book'.equalsIgnoreCase( event.getNewValue().toString())) {
   product.getDetails().setTracks(null);
  }
 }
}

updated ProductService.java

package com.borislam.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.borislam.domain.Product;
import com.borislam.repository.ProductRepository;
import com.borislam.view.ProductSearchCriteria;

@Service
public class ProductService {

 @Autowired
 private ProductRepository productRepository;

 public List<Product> searchByCriteria(ProductSearchCriteria criteria){
  return productRepository.searchByCriteria(criteria);
 }

 public Product getProduct(String sku) {
  return productRepository.findBySku(sku);
 }

 public void saveProduct(Product p){  
  productRepository.save(p);
 }

 public void deleteProduct(Product p){  
  productRepository.delete(p);
 }

}

Conclusion:

1. Spring Data Mongo DB provides MongoTemplate which allow you to perform MongoDB operation easily.

2. MongoDB JSON-style document could mapped to POJO easily with the help of Spring Data MongoDB

3. Repository abstraction of spring data reduces the boilerplate code write for accessing MongoDB.

4. You add custom behaviour to spring data repository.

 

Reference: Introduction to sample application (MongoShop Product Catalog), MongoDB schema design and data preparationJSF (PrimeFaces) and Spring data MongoDB IntegrationEnquriy data with spring data repository and mongotemplate, Create, Edit and delete data, from our JCG partner Boris Lam at the Programming Peacefully blog.

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
Email address:

Leave a Reply

5 Comments on "Spring Data, MongoDB and JSF Integration tutorial"

avatar
  Subscribe  
newest oldest most voted
Notify of
Sheila Leverson
Guest

Excellent! Thank you so much. I had never heard of PrimeFaces before; I was looking for a Java/Maven/MongoDB tutorial. This is a bonus. The code works perfectly after I solved a few configuration issues on my own environment.

Saeid
Guest

This tutorial never works. There are fundamental missing keys in the XML files. Why on earth did you thank this tutorial? You have never tested it right?

zubair khan
Guest

Dear @Saeid this tutorial works fine, i think You don’t even know the ABC of programing thats why you are enable to run it. Give some time to your programing. thanks

zubair khan
Guest

*Unable

kev216
Guest
nice work, Thank you so much. but these is some changes in pom.xml here is http://, not https 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 and add “dependency” commons-fileupload commons-fileupload 1.3.1
Want to take your Java skills to the next level?
Grab our programming books for FREE!
Here are some of the eBooks you will get:
  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns
The Spring Framework Cookbook
  • Learn the best practices of the Spring Framework
  • Build simple, portable, fast and flexible JVM-based systems and applications
  • Explore specific projects like Boot and Batch
The Spring Data Programming Cookbook
  • Learn how to use data access technologies and cloud-based data services
  • Set up the environment and create a basic project
  • Learn how to handle the various modules (e.g. JPA, MongoDB, Redis etc.)
The Selenium Programming Cookbook
  • Kick-start your own projects using this testing framework for web applications
  • Learn JUnit integration and Standalone Server functionality
  • Find out the most popular Interview Questions about the Selenium Framework
The Mockito Programming Cookbook
  • Kick-start your own web projects using this open source testing framework
  • Write simple test cases using the Mockito Framework
  • Learn how to integrate with JUnit, Maven and other frameworks
The JUnit Programming Cookbook
  • Learn basic usage and configuration of JUnit
  • Create multithreaded tests
  • Learn how to integrate with other testing frameworks
The JSF 2.0 Programming Cookbook
  • Build component-based user interfaces for web applications
  • Set up the environment and create a basic project
  • Learn Internationalization and Facelets Templates
The Amazon S3 Tutorial
  • Develop your own Amazon S3 based applications
  • Learn API usage and pricing
  • Get your own projects up and running in minimum time
Java Design Patterns
  • Learn how Design Patterns are implemented and utilized in Java
  • Understand the reasons why patterns are so important
  • Learn when and how to apply each one of them
Java Concurrency Essentials
  • Dive into the magic of concurrency
  • Learn about concepts like atomicity, synchronization and thread safety
  • Learn about testing concurrent applications
The IntelliJ IDEA Handbook
  • Kick-start your own programming projects using IntelliJ IDEA
  • Learn how to setup and install plugins
  • Create UIs with this Java integrated development environment
The Git Tutorial
  • Learn why Git differs from other version control systems
  • Explore Git's usage and best practises
  • Learn branching strategies
The Eclipse IDE Handbook
  • Explore the most widely used Java IDE
  • Learn how to setup and install plugins
  • Built your own projects up and running in minimum time
The Docker Containerization Cookbook
  • Explore the world’s leading software containerization platform
  • Learn how to wrap a piece of software in a complete filesystem
  • Learn how to use DNS and various commands
Developing Modern Applications With Scala
  • Develop modern Scala applications
  • Build SBT and reactive applications
  • Learn about testing and database access
The Apache Tomcat Cookbook
  • Explore Apache Tomcat open-source web server
  • Learn about installation, configuration, logging and clustering
  • Kick-start your own web projects using Apache Tomcat
The Apache Maven Cookbook
  • Explore the Apache Maven build automation tool
  • Learn about Maven's project structure and configuration
  • Learn about Maven's dependency management and plug-ins
The Apache Hadoop Cookbook
  • Explore the Apache Hadoop open-source software framework
  • Learn distributed caching and streaming
  • Kick-start your own web projects using Apache Hadoop
The Android Programming Cookbook
  • Explore the Android mobile operating system
  • Learn about services and page views
  • Learn about Google Maps and Bluetooth functionality
The Elasticsearch Tutorial
  • Explore the Elasticsearch search engine
  • Develop your own Elasticsearch based applications
  • Learn operations, Java API Integration and reporting
Amazon DynamoDB Tutorial
  • Develop your own Amazon DynamoDB based applications
  • Learn DynamoDB Concepts and Best Practices
  • Get your own projects up and running in minimum time
Java NIO Programming Cookbook
  • Learn features for intensive I/O operations
  • Follow a series of tutorials on Java NIO examples
  • Get knowledge on Java Nio Socket and Asynchronous Channels
JBoss Drools Cookbook
  • Explore Drools business rule management system
  • Follow a series of tutorials on Drools examples
  • Get knowledge on business rules for a shopping domain model
Vaadin Programming Cookbook
  • Explore Vaadin web framework for rich Internet applications
  • Learn the Architecture and Best Practices
  • Get knowledge on Data Binding and Custom Components
Groovy Programming Cookbook
  • Explore Apache Groovy object-oriented programming language
  • Create sample applications and explore interview questions
  • Get knowledge on Callback functionality and various widgets
GWT Programming Cookbook
  • Explore the open source Google Web Toolkit
  • Create sample applications and explore interview questions
  • Create and maintain complex JavaScript front-end applications in Java
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
and many more ....
Email address:
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
and many more ....
Email address:
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
Email address:
Want to be a DynamoDB Master ?
Subscribe to our newsletter and download the Amazon DynamoDB Tutorial right now!
In order to help you master this Amazon NoSQL database service, we have compiled a kick-ass guide with all the major DynamoDB features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Programming Interview Coming Up?
Subscribe to our newsletter and download the Ultimate Multithreading and Concurrency interview questions and answers collection right now!
In order to get you prepared for your next Programming Interview, we have compiled a huge list of relevant Questions and their respective Answers. Besides studying them online you may download the eBook in PDF format!
Email address:
Java Interview Coming Up?
Subscribe to our newsletter and download the Ultimate Spring interview questions and answers collection right now!
In order to get you prepared for your next Java Interview, we have compiled a huge list of relevant Questions and their respective Answers. Besides studying them online you may download the eBook in PDF format!
Email address:
Java Interview Coming Up?
Subscribe to our newsletter and download the Ultimate Java interview questions and answers collection right now!
In order to get you prepared for your next Java Interview, we have compiled a huge list of relevant Questions and their respective Answers. Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a Java NIO Master ?
Subscribe to our newsletter and download the Java NIO Programming Cookbook right now!
In order to help you master Java NIO Library, we have compiled a kick-ass guide with all the major Java NIO features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a Drools Master ?
Subscribe to our newsletter and download the JBoss Drools Cookbook right now!
In order to help you master Drools Business Rule Management System, we have compiled a kick-ass guide with all the major Drools features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be an iText Master ?
Subscribe to our newsletter and download the iText Tutorial right now!
In order to help you master iText Library, we have compiled a kick-ass guide with all the major iText features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be an Elasticsearch Master ?
Subscribe to our newsletter and download the Elasticsearch Tutorial right now!
In order to help you master Elasticsearch search engine, we have compiled a kick-ass guide with all the major Elasticsearch features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a Scala Master ?
Subscribe to our newsletter and download the Scala Cookbook right now!
In order to help you master Scala, we have compiled a kick-ass guide with all the basic concepts! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a JUnit Master ?
Subscribe to our newsletter and download the JUnit Programming Cookbook right now!
In order to help you master unit testing with JUnit, we have compiled a kick-ass guide with all the major JUnit features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to master Amazon Web Services ?
Subscribe to our newsletter and download the Amazon S3 Tutorial right now!
In order to help you master the leading Web Services platform, we have compiled a kick-ass guide with all its major features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to master Spring Framework ?
Subscribe to our newsletter and download the Spring Framework Cookbook right now!
In order to help you master the leading and innovative Java framework, we have compiled a kick-ass guide with all its major features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to master Eclipse IDE ?
Subscribe to our newsletter and download the Eclipse IDE Handbook right now!
In order to help you master Eclipse, we have compiled a kick-ass guide with all the basic features of the popular IDE! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to master IntelliJ IDEA ?
Subscribe to our newsletter and download the IntelliJ IDEA Handbook right now!
In order to help you master IntelliJ IDEA, we have compiled a kick-ass guide with all the basic features of the popular IDE! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to master Docker ?
Subscribe to our newsletter and download the Docker Containerization Cookbook right now!
In order to help you master Docker, we have compiled a kick-ass guide with all the basic concepts of the Docker container system! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to create a kick-ass Android App ?
Subscribe to our newsletter and download the Android Programming Cookbook right now!
With this book, you will delve into the fundamentals of Android programming. You will understand user input, views and layouts. Furthermore, you will learn how to communicate over Bluetooth and also leverage Google Maps into your application!
Email address:
Want to be a GIT Master ?
Subscribe to our newsletter and download the GIT Tutorial eBook right now!
In order to help you master GIT, we have compiled a kick-ass guide with all the basic concepts of the GIT version control system! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a Hadoop Master ?
Subscribe to our newsletter and download the Apache Hadoop Cookbook right now!
In order to help you master Apache Hadoop, we have compiled a kick-ass guide with all the basic concepts of a Hadoop cluster! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to master Spring Data ?
Subscribe to our newsletter and download the Spring Data Ultimate Guide right now!
In order to help you master Spring Data, we have compiled a kick-ass guide with all the major features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to create a kick-ass Android App ?
Subscribe to our newsletter and download the Android UI Design mini-book right now!
With this book, you will delve into the fundamentals of Android UI design. You will understand user input, views and layouts, as well as adapters and fragments. Furthermore, you will learn how to add multimedia to an app and also leverage themes and styles!
Email address:
Want to be a Java 8 Ninja ?
Subscribe to our newsletter and download the Java 8 Features Ultimate Guide right now!
In order to get you up to speed with the major Java 8 release, we have compiled a kick-ass guide with all the new features and goodies! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to master Java Annotations ?
Subscribe to our newsletter and download the Java Annotations Ultimate Guide right now!
In order to help you master the topic of Annotations, we have compiled a kick-ass guide with all the major features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a JUnit Master ?
Subscribe to our newsletter and download the JUnit Ultimate Guide right now!
In order to help you master unit testing with JUnit, we have compiled a kick-ass guide with all the major JUnit features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to master Java Abstraction ?
Subscribe to our newsletter and download the Abstraction in Java Ultimate Guide right now!
In order to help you master the topic of Abstraction, we have compiled a kick-ass guide with all the major features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to master Java Reflection ?
Subscribe to our newsletter and download the Java Reflection Ultimate Guide right now!
In order to help you master the topic of Reflection, we have compiled a kick-ass guide with all the major features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a JMeter Master ?
Subscribe to our newsletter and download the JMeter Ultimate Guide right now!
In order to help you master load testing with JMeter, we have compiled a kick-ass guide with all the major JMeter features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a Servlets Master ?
Subscribe to our newsletter and download the Java Servlet Ultimate Guide right now!
In order to help you master programming with Java Servlets, we have compiled a kick-ass guide with all the major servlet API uses and showcases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a JAXB Master ?
Subscribe to our newsletter and download the JAXB Ultimate Guide right now!
In order to help you master XML Binding with JAXB, we have compiled a kick-ass guide with all the major JAXB features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a JDBC Master ?
Subscribe to our newsletter and download the JDBC Ultimate Guide right now!
In order to help you master database programming with JDBC, we have compiled a kick-ass guide with all the major JDBC features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a JPA Master ?
Subscribe to our newsletter and download the JPA Ultimate Guide right now!
In order to help you master programming with JPA, we have compiled a kick-ass guide with all the major JPA features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a Hibernate Master ?
Subscribe to our newsletter and download the Hibernate Ultimate Guide right now!
In order to help you master JPA and database programming with Hibernate, we have compiled a kick-ass guide with all the major Hibernate features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a JSF Master ?
Subscribe to our newsletter and download the JSF 2.0 Programming Cookbook right now!
In order to get you prepared for your JSF development needs, we have compiled numerous recipes to help you kick-start your projects. Besides reading them online you may download the eBook in PDF format!
Email address:
Want to be a Java Master ?
Subscribe to our newsletter and download the Advanced Java Guide right now!
In order to help you master the Java programming language, we have compiled a kick-ass guide with all the must-know advanced Java features! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a Java Master ?
Subscribe to our newsletter and download the Java Design Patterns right now!
In order to help you master the Java programming language, we have compiled a kick-ass guide with all the must-know Design Patterns for Java! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be a Hadoop Master ?
Subscribe to our newsletter and download the Hadoop Tutorial right now!
In order to help you master Apache Hadoop, we have compiled a kick-ass guide with all the basic concepts of a Hadoop cluster! Besides studying them online you may download the eBook in PDF format!
Email address:
Want to be an Elastic Beanstalk Master ?
Subscribe to our newsletter and download the Amazon Elastic Beanstalk Tutorial right now!
In order to help you master AWS Elastic Beanstalk, we have compiled a kick-ass guide with all the major Elastic Beanstalk features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Amazon Elastic Beanstalk Tutorial
  • Develop your own Amazon Elastic Beanstalk based applications
  • Learn Java Integration and Command Line Interfacing
  • Get your own projects up and running in minimum time
Want to take your Java skills to the next level?
Grab our programming books for FREE!
Here are some of the eBooks you will get:
  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns
Insiders are already enjoying weekly updates and complimentary whitepapers!
Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.
Email address:
Want to be an ActiveMQ Master ?
Subscribe to our newsletter and download the Apache ActiveMQ Cookbook right now!
In order to help you master Apache ActiveMQ JMS, we have compiled a kick-ass guide with all the major ActiveMQ features and use cases! Besides studying them online you may download the eBook in PDF format!
Email address:
Apache ActiveMQ Cookbook
  • Explore Apache ActiveMQ Best Practices
  • Learn ActiveMQ Load Balancing and File Transfer
  • Develop your own Apache ActiveMQ projects