Two Amazing NetBeans 6.8Beta Features

1. NetBeans 6.8Beta generates Unit-Tests for EJB 3.1 with Embeddable Container code. It looks like:


    public void testHello() throws Exception {


        HelloService instance = (HelloService)javax.ejb.embeddable.EJBContainer.createEJBContainer().getContext().lookup("java:global/classes/HelloService");

        String expResult = "";

        String result = instance.hello();

        assertEquals(expResult, result);

        // TODO review the generated test code and remove the default call to fail.

        fail("The test case is a prototype.");


This is a nice feature: you don't have to look-up the JNDI-name...

2. NetBeans is capable to auto-complete a bound item in the data table:

                <h:dataTable id="hugo" value="#{newTweet.messages}" var="message">


                        <h:outputText value="#{message.content}"/>  //the auto-completion works here!



I tested NetBeans 6.8Beta in the last few days. It is stable, fast and especially interesting for Java EE 6 projects... Especially EJB 3.1 / JPA 2.0 support and JSF 2.0 editor were improved significantly.... 


Apparently it also has refactoring of xhtml portions into facelets components too, can't remember where I saw that, but sounds pretty amazing.

The JSF support is very welcome, I've tried out the previous RC and was very happy

Posted by James Barrow on October 29, 2009 at 01:58 PM CET #


a good hint - will try that!,



Posted by Adam Bien on October 29, 2009 at 02:01 PM CET #

Yay, happy the embedded container worked for me at last!

I'm facing one problem, though: my EJBs use JPA, which in turn uses a connection pool defined in GF; the problem is the embedded container doesn't seem to find that pool or the JDBC resource via JNDI, as the test fails with a message like:
javax.naming.NamingException: Lookup failed for 'jdbc/mypool' in SerialContext [Root exception is javax.naming.NameNotFoundException: mypool not found]

Any clue on this? Did you guys experience this too?

BTW, nice work with the blog, keep it up! :)

Oh, and I must say that after 5 years using Eclipse, I'm starting to like NB best :)

Posted by Jay on October 29, 2009 at 06:17 PM CET #

I will never switch to a non final version of netbeans!!! It's the first time that I am really having troubles with it.
My ear project worked perfectly, until I switched to Netbeans 6.8 M2 (from 6.7.1). No I can't deploy it anymore, as Netbeans tells me that the EJB project within the ear doesn't contain an ejb. ARRRGH!
The EAR files looks good, I can't see any error.. I guess I have to clean or reinstall glassfish. As a Websphere user I am used to it, but I never had to this with glassfish..
Greetings from Stuttgart!!

Posted by Daniel on October 30, 2009 at 01:47 AM CET #

I just installed NB on Tuesday morning before my talk where I planned to use the profiler during my demo. Well, it not only crashed when running, it took down VisualVM 1.2 as well as VisualVM 1.1.1 and my previous install of NetBeans (6.7). Needless to say I spent some time scrambling to fix the mess before my talk but it was a WTF moment.

That said, the new features are really nice... and once the segv is fixed, it will be even better ;-)


Posted by kirk on October 30, 2009 at 08:37 AM CET #


I haven't tried it, I just read about it somewhere and thought "Awesome!" :)

I'm really pleased with JSF 2 though.

One thing I did try is Bean Validation, it's not only integrated to JPA but also tied into JSF2. For example:

public class Dummy {
@Size(min=1,max=50,message="A name must have more than 1 and less than 50 characters") private String name;

public class DummyController {
private Dummy dummy = new Dummy();


<h:inputText id="dummyName" value="#{}"/>
<h:message for="dummyName"/>

Due to the bean validation, the name length will be validated, and if an error occurs, the message declared in the annotation will be displayed by the h:message, which I just think is pretty damn cool! :D

Posted by James Barrow on October 30, 2009 at 10:54 AM CET #

.. ignore the line please -.-

Posted by James.Barrow on October 30, 2009 at 10:55 AM CET #

.. and any other mistakes in the code, just an example :D

Posted by James Barrow on October 30, 2009 at 10:56 AM CET #

@James I tried Bean Validation myself yesterday and was also delighted of how easy they've made it :)

What do you mean with "it's [...] integrated to JPA"? Do you mean you can configure both by just annotating attributes or getters? Or am I missing something?


Posted by Jay on October 30, 2009 at 12:21 PM CET #

- that shows composite component extraction thing


If I recall correctly, the bean validation annotations are validated before persisting in JPA.

So if you forget anything in the frontend, and build a bean to persist, the annotations will catch it; very useful! Not sure how partial validation works though - e.g. maybe something isn't always required to be set.. null in some cases, not null other. I'd hope there must be some way to configure what validation groups are applied when... somehow...

Posted by James Barrow on October 30, 2009 at 05:17 PM CET #


Or in otherwords, yes, you annotate the attributes, and JPA will first validate it before allowing the bean entry to be committed, throwing the corresponding validation exceptions.

So you annotate in one place, and get validation on the frontend and backend for free [ very cool :)] Just make sure it's the right kind of validation - class invariants, and not pre/post-conditions.

Check out OVal too:

Posted by James Barrow on October 30, 2009 at 05:25 PM CET #

@jay: to use an existing JNDI config, you can pass the home to an existing GlassFish install (and thus an existing domain.xml) using code documented here:

You can find another interesting approach here too:

Posted by Alexis MP on October 30, 2009 at 09:03 PM CET #

This is indeed very exciting. Netbeans has come a long way. I like your "lean" approach.

I tried a simple example but it has not worked for me. I created @Stateless BookEJB and generated the tests using NB.

The following line fails:
BookEJB instance = (BookEJB)javax.ejb.embeddable.EJBContainer.createEJBContainer().getContext().lookup("java:global/classes/BookEJB");

Looking very promising, but it seems it's not there yet. I've tried several ways to get the EJB container but no luck so far.

Posted by Stanley on November 04, 2009 at 12:17 AM CET #

Hi Stanley,

it highly depends, which version of the embeddable container you are using. I opened some issues regarding "nightly build bugs". Stay tuned.

I like your URL:

thanks for your feedback!,


Posted by Adam Bien on November 04, 2009 at 11:04 AM CET #

Really a good stuff...nice post..

Posted by Programming Pad on January 20, 2013 at 02:25 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments