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 List
getFireFluids(){ 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.]