Useful JSF 2 / CDI Table Generation Wizard in NetBeans

  1. You will need a (JPA) domain object with getters / setters. Sample:
    public class FireFluid {
        private long id;
        private String name;
        private int amount;
        public FireFluid() {
        public String getName() {
            return name;
        public int getAmount() {
            return amount;
  2. An in EL accessible Collection / List returning the domain objects is also necessary. The simplest way is to use a CDI bean to expose the list to the view:
    public class Index {
        PalincaCommanderService pcs;
        public List getFireFluids(){
            return pcs.all(name);
  3. Go to Window -> Palette. Drag the last Entry "JSF Data Table From Entity" and NetBeans will pop-up a dialog with a property and entity suggestion. After confirming the choice, you will only have to import the f: namespace. This can be done with Alt+Enter: The result is:

<h:dataTable id="table" value="#{index.fireFluids}" var="item">
         <f:facet name="header">
             <h:outputText value="Name"/>
         <h:outputText value="#{}"/>
         <f:facet name="header">
             <h:outputText value="Amount"/>
         <h:outputText value="#{item.amount}"/>

The freemarker template of the generated code can be also customized. Just click on the link in the pop-up.
[I borrowed the code from Palinca JUG Transylvania sample.]


Hi Adam,

I don´t know if i'm asking something where doesnt belong. I'm evaluating
presentation tier frameworks, i have worked with JSF 1.2 and had a lots of problems specially with the lifecycle of JSF, backing beans methods called twice, insuficient scope for beans .....
Do you recommend JSF2 as a web framework for enterprise applications? (with response times requirements) , i like the idea of CDI + JSF2 but the R.I. Weld seems to be still a little buggy.


Posted by Paul on February 24, 2011 at 05:08 PM CET #

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