the blog for developers

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:

<html>
<body>
  ${uuid.value}
 </body>
</html>

and the web bean:

package de;

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

@Component
@RequestScoped
@Named("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.

You can leave a Reply here. Of course, you should follow me on twitter here.

You can share this post!
Do you want to tell others about this article? Use the social bookmark icons to submit this artice to the service of your choice. Thanks.

About the author: Stephan Schmidt has more than 15 years of internet technology experience and 10 years experience in agile. He was head of development, consultant and CTO and is a speaker, author and blog writer. He specializes in organizing and optimizing software development helping companies by increasing productivity with lean software development and agile methodologies. Want to know more? All views are only his own.
Leave a reply.

Comments

I’m astonished too…
How come this implementation went under the radar like that?
Great news, finally being able to play with this Web Beans!

stephan

Yes, at Caucho a lot of things seem to happen, all of them under the radar (except sometimes glimpses like the TerraCotta enabled Quercus Drupal version by Bob I think). Currently playing with a Web Beans enabled Jersey. Nice stuff.

Yeah, well, we’re not very good at self-promotion :)

Stephan, if you get some time, it would be great if you can report the problems at http://bugs.caucho.com. Some of these things are easy to fix, but just hit a blind spot in our testing.

stephan

Sure I do :-) Thanks for Web Beans.

Stefan

Can not believe you found this. Once it is final it will simplify web development a lot – especially for larger applications.

Thanks for the hint!
Stefan

stephan

@Stefan: Yes it will. It makes development of a web layer below a UI toolkit much easier.

[...] No signal, no noise. « Playing with JSR 299 – Web Beans [...]

djo.mos

Hi there,
Looks promising !
By the way, I want to mention that you can achieve this using Spring 2.5, but the bottleneck is configuration (you have to add two Spring listeners in web.xml, declare Spring el-resolver in faces-config.xml, some gore stuff in applicationContext.xml), bu once that done, it’s a joy:

@Controller(“sthng”)
@Scope(“session”)
public class Something {

}

and the in a JSF page:

#{sthng.somField}

BTW, does WebBeans extend to all application layers ? I mean with Spring I can manage also my DAOS and my Service layer le DI betwwen them. But I guess WebBeans are limited to the Controller/View layer …

Cheers :D

stephan

WebBeans applies to all application layers though I guess you could integrate it with Spring or Guice should that be needed. But Web Beans is just a DI container.

Leave a Reply

What people wrote somewhere else:

Additional comments powered by BackType

Guide to CodeMonkeyism

Over the last 4 years I wrote many articles on this blog. To make it easier for you to find the relevant ones, I've organized them into topics.

Top 10

6 reasons why my VC funded startup did fail

Go Ahead: Next Generation Java Programming Style

Java Interview questions: Write a String Reverser

The dark side of NoSQL

7 Bad Signs not to Work for a Software Company or Startup

Is Java dead?

Scala vs. Clojure

Never, never, never use String in Java

No future for functional programming in 2008 – Scala, F# and Nu

Clojure vs Scala, Part 2

Java Developer

Is Java Dead?

Go Ahead: Next Generation Java Programming Style

Be careful with magical code

All variables in Java must be final

Never, never, never use String in Java

Bending Java: More readable code with methods that do nothing?

NoSQL Guy

NoSQL: The Dawn of Polyglot Persistence

The dark side of NoSQL

Essential storage tradeoff: Simple Reads vs. Simple Writes

Sharding destroys the goals of your relational database

The unholy legacy of databases

Startup/CTO

Development Dream Teams

6 reasons why my VC funded startup did fail

American vs. European style of Software Development

12 Things to Reduce Your Lead Time and Time to Market

The high cost of overhead when working in parallel

Essential storage tradeoff: Simple Reads vs. Simple Writes

Job Seeker

Another Good (Java) Interview Question

7 Bad Signs not to Work for a Software Company or Startup

Java Interview questions: Write a String Reverser (and use Recursion!)

Java Interview questions: Multiple Inheritance

As a Manager: What I value in developers

Top 10 Tips (+1) to Get a Pay Raise

Agilist

What Developers Need to Know About Agile

5 Practices Better to Change in Your Scrum Implementation

Scrum is not about engineering practices

ScrumMaster and ZenMaster: The joke of certification

What is Trans-Scrum?