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:
    
    @Model
    public class Index {
    
        @EJB
        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">
    <h:column>
         <f:facet name="header">
             <h:outputText value="Name"/>
         </f:facet>
         <h:outputText value="#{item.name}"/>
     </h:column>
     <h:column>
         <f:facet name="header">
             <h:outputText value="Amount"/>
         </f:facet>
         <h:outputText value="#{item.amount}"/>
     </h:column>
 </h:dataTable>


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.]


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Comments:

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.

Thanks.

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

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License