Adam Bien's Weblog
Useful JSF 2 / CDI Table Generation Wizard in NetBeans
- 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; } } - 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 ListgetFireFluids(){ return pcs.all(name); } } - 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.]
Posted at 01:55PM Feb 06, 2011 by Adam Bien in Netbeans | Comments[1] | Views/Hits: 6154
*NEW* Workshop: "Effective Java EE 6/7", July 10th, Airport Munich Tweet Follow @AdamBien



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 04:08 PM CET #