Playing with JSR 299 – Web Beans

You can play with WebBeans! WebBeans looks nice as a web-layer-aware IoC container. I've been starring at Seam and Gavin to get my hands on a WebBeans implementation. Waiting. Consider my astonishment when I found the working Resin WebBeans implementation.

It's easy to get started with the JSF example. There are also example implementations for Wicket and Struts2. WebBeans in Resin works with simple JSPs too though. Suppose we want a page which uses a web bean to display an UUID. Simple, the JSP page:


and the web bean:

package de;

import javax.webbeans.Component;
import javax.webbeans.RequestScoped;
import javax.webbeans.Named;
import java.util.UUID;

public class UUIDService {
  private String value = UUID.randomUUID().toString();

  public String getValue() { return this.value; }

The annotations tell the container that it's a web beans component, we want to refer to it by the "uuid" name and the scope is a request. This means we want a new bean every request.

I had some smaller problems getting Resin working, but the nice thing about Resin are the excellent error messages. Very helpful.

Thanks for listening.