Posts

Showing posts with the label Google Guice

Injecting Guice managed object into JSF View Scoped bean

In previous post, I demonstrate how to integrate JSF with Guice and MyBatis. However, my friend experiences some problem when he is using view scoped backing bean. He found that he cannot re-inject the service class after serialization. I have done some tricks to solve this problem.This is simply done by overriding the readObject() and writeObject() method. The BasePageBean in the previous post is changed as follow: BasePageBean.java package org.borislam.view; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import javax.annotation.PostConstruct; import javax.faces.context.FacesContext; import javax.faces.context.Flash; import javax.servlet.ServletContext; import com.google.inject.Inject; import com.google.inject.Injector; import com.ppstation.PpContext; public abstract class BasePageBean implements Serializable{ private transient Injector injector; public BasePageBean() {} pu...

Lightweight Web Application Framework: PrimeFaces (JSF) + Guice + MyBatis (PART 2)

In this part, I will continue to demonstrate the integration of JSF, Guice and MyBatis. DBCP connection pool and MYSQL database is used in persistence layer Integrate Google Guice with MyBatis In the previous post, we have created a ServletContextListener. Now, we just bind the BasicDataSourceProvider and JdbcTransactionFactory in the contextInitialized method. GuiceContextListener.java package org.borislam; import java.util.Properties; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; import org.apache.log4j.xml.DOMConfigurator; import org.borislam.mapper.StaffMapper; import org.borislam.service.SimpleService; import org.borislam.service.impl.SimpleServiceImpl; import org.mybatis.guice.MyBatisModule; import org.mybatis.guice.datasource.dbcp.BasicDataSourceProvider; import org.mybatis.guice.datasource.helper.JdbcHelper; import com.google....

Lightweight Web Application Framework : PrimeFaces (JSF) + Guice + MyBatis (PART1)

Recently, my friend asks me how to build a lightweight java web application. Many Java web developer would choose Spring and hibernate to build a traditional web application. However, it may not be lightweight enough. I suggested him try to use Guice and MyBatis to build the application framework. Although Spring is more feature-riched than Guice, I admitted that Guice is more lightweight and easier to use. MyBatis is also a lightweight SQL map framework. It can integrate with Guice framework very well. Here, I will try to set up a simple web application with PrimeFaces, Guice and MyBatis. I hope that my friend could learn how to do it. :) Using MyFaces and PrimeFaces in presentation layer. Integrate MyFaces and PrimeFaces is simple. Just simply get the JARS file from MyFaces website and PrimeFaces website . For MyFaces, just add the following sample configuration into your web.xml. <display-name>TestGuice</display-name> <context-param> <param-name...