Friday, August 24, 2012

Get bean instance in CDI

In some cases it's required to get the bean instance instead of the reference.
You can simply do it with the following method:

public static <T> T getBeanInstance(final Class<T> type, final Class<? extends Annotation> scope, final BeanManager beanManager)
   final Context context = beanManager.getContext(scope);
   final Set<<Bean<?>> beans = beanManager.getBeans(type);
   final Bean<T> bean = (Bean<T>) beanManager.resolve(beans);
   final CreationalContext<T> creationalContext = beanManager.createCreationalContext(bean);

   return context.get(bean, creationalContext);

Tuesday, August 21, 2012

Increase your JSF application performance (Part 1 - Environment & Configuration)

  • Always use the newest MyFaces version (As you can read here: Blog Entry)
  • If you just need a plain servlet container, use Tomcat instead of Jetty
  • Use JUEL as EL implementation 
    • Add the newest JUEL API + implementation as depedency
    • Configure MyFaces to use JUEL:
    • <context-param>
  • Increase expression cache in JUEL
    • Create src/main/resources/
    • Add property javax.el.cacheSize with a custom size. The default size is 1000. In my application i use a size of 3000.
  • If you use CDI, consider to use OpenWebBeans as implementation and configure this in your web.xml:
  • <context-param>
  • Enable MyFaces EL caching as described in MyFaces Wiki
  • Disable JSP support in MyFaces:
  • <context-param>
    Attention: If you set this, you need to provide the "org.apache.myfaces.EXPRESSION_FACTORY" parameter.
  • Other params to increase performance:
  • <context-param>
  • Configure state management as described in MyFaces Wiki
  • Use a custom ServletFilter to set the correct expires/cache headers of your resources (images, stylesheets, javascripts)
  • Compress and optimize your Javascripts in your build process. If you use maven, try primefaces-extensions' closure compiler maven plugin

Monday, August 20, 2012

Enable failover with OpenWebBeans (> 1.1.3)

With Tomcat 7.0.22, some changes has be done when


will be called. This caused that session replication was done before OpenWebBeans prepared the beans for the failover.

Therefore a new ServletFilter, which prepares the bean failover before session replication, was added in OpenWebBeans 1.1.4.

Just add it as FIRST filter in your web.xml:


and map it for example to the FacesServlet.

Also don't forget the src/main/resources/META-INF/openwebbeans/ with following entries:


Update for OWB 1.2.0 -> Click