JSF 2 + JPA 2 + EJB 3.1 Scaffolding With Netbeans 6.8 in 3 Steps - And The Code Is Even Usable

NetBeans 6.8 comes with a new wizard, which generates a JSF 2 application from an existing database using EJB 3.1 and JPA 2. The resulting code is even usable for real world projects. Also interesting: the generator templates can be easily edited directly from the wizard. This is a serious killer feature and really usable. You can apply the wizard to a Java EE 6 WAR project and deploy it to Glassfish v3. For this purpose:

  1. Create a new WAR application and choose Glassfish v3, Java EE 6 and add JSF 2 as a framework.
  2. Right mouse click on the WAR and choose: "Entity Classes From Database....", choose an existing DataSource, then a Table and don't forget to push the "Create Persistence Unit" button. The result: a JPA entity + persistence.xml.
  3. Right mouse click on the WAR and choose: "JSF Pages from Entity Classes..." and choose the even generated JPA entity. On the second page you can even customize the templates (just click on the link in the right bottom corner). This is really useful.
The resulting code is usable after some tweaks. I used this wizard to generate the code for yesterdays post "(JSF + JPA) - EJB = Bloat". You can also generate JPA controller code without EJB 3 from the context menu choosing "JPA Controller Classes From Entities...". This will, however, result in significantly more plumbing...


Adam, when Java EE 6 will be officially officially released?

Posted by Fábio on October 02, 2009 at 07:01 PM CEST #

Thanks Adam, I really LOVED what you made me discover. But, IMHO, two features are lacking :

- Use of JSF2 @ManagedBean Annotations instead of configuration

- Option to select Facelets generation instead of JSP

Do you know if those features will be developed during the 6.8 timeframe ?

Posted by Cédric Marcone on October 07, 2009 at 05:08 PM CEST #

Wow, I just downloaded NB6.8 M2 and I discovered there are facelets generator in this version.

They even generate JSF beans with the @ManagedBean annotation.

Only one feature is lacking on the facelets side : collections are not presented in the edit and view pages.

Congratulations to the NetBean Team, this feature is a real time saver.

Posted by Cédric Marcone on October 09, 2009 at 08:45 PM CEST #

Why don't you use Eclipse instead of Netbeans ? :(

Posted by bob on October 16, 2009 at 08:31 PM CEST #

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