Tuesday Jan 15, 2013

How to Create a Custom "JSF Pages from JPA Entity Classes" Code Generator

Kay Wrobel is new on the NetBeans Platform developer mailing lists. He's interested in PrimeFaces and really likes NetBeans IDE for that reason (and rightly so, of course). However, being able to modify the templates used to generate JSF pages from entity classes is not enough for him:

Instead, what he'd like is the ability to replace those templates completely, to have multiple PrimeFaces oriented files to be generated, i.e., not following the View/Create/Edit/List approach that you see above, but following his own business requirements.

Currently, there's no API for the above dialog, though that would be nice. So, I've forked the parts of the NetBeans sources that relate to the above dialog (plus some other stuff, since I haven't completely broken it down to its minimum yet) here:


You can get the above via Subversion, open in NetBeans IDE 7.2.1, compile it there (several impl dependencies, so you must use 7.2.1), then run it. Then create a new web application create/generate some entity classes, and then you'll be able to go to this new wizard, which comes from the above code:

As you move through the wizard, right now, you'll have exactly the same steps and results as in the standard "JSF Pages from Entity Classes" wizard. The second panel proves that anything can be changed, i.e., notice "Hi Kay!" in the first label below the heading in the main panel in the dialog below:

The result of the above is, currently, exactly as you have in NetBeans IDE: JSF pages created from entity classes. So, now you have the basis for your own PrimeFaces, or whatever, code generator from entity classes.

Those parts of what you add/change to the source code should be contributed back to the NetBeans project, since changes you make are actually changes to the NetBeans source code. Not everything you contribute back will be useful or necessarily accepted, of course, but the point is that in principle anything you add/change is something you should be open to sharing back with the NetBeans project.


Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« January 2013 »