The module is being release as an installable NBM plugin module. The module is NetBeans implementation dependent, so please watch for the implementation version indicated in the file. If the IDE you're using is not the same, please go ahead and try [Installing Into Another NetBeans Version].
nbpfcrudgen-x.x-y.y.yimpl.zip
plugin file.PrimeFaces CRUD Generator
.Important: If you are using a newer version of NetBeans (7.3.1+) that ships with Glassfish 4.0 and JSF 2.2, please be sure to download and add the latest PrimeFaces library from the PrimeFaces Download page. As of this writing, PrimeFaces offers version 4.0 under the Community Downloads section. Add the library to your NetBeans installation under Tools -> Ant Libraries and call it "PrimeFaces 4.0". This will make PrimeFaces 4.0 available to the "Web Applciation" wizard.
/faces/*
and select Facelets as Preferred Page Language.Note: If you created a CDI project by adding a beans.xml
file to it, be sure to visit the [Context Dependency Injection And Its Impact On The Generator] Wiki page which highlights some of the code differences.
You have two choices for doing this: you can either program your own entities and persistence unit, or you can let NetBeans generate entities from an existing database. For this sample application, the latter is being used.
jdbc/sample
from the list. NetBeans connects to the server-supplied Derby SAMPLE
database and populates Available Tables.default
java.util.Collection
(default)NetBeans generates the entities package and seven entity classes:
Customer.java
DiscountCode.java
Manufacturer.java
MicroMarket.java
Product.java
ProductCode.java
PurchaseOrder.java
It also added a persistence.xml
file to the project for referencing the sample database.
Note: The code generator can now detect PrimeFaces version and Apache MyFaces CODI CDI-Extension version!
controllers
beans
converters
/WEB-INF/include
/WEB-INF/include/entity
/Bundle
10
10,20,30
descr,name
@ViewAccessScoped
annotations. Recent versions of JSF starting with 2.2 have native support for CDI @ViewScoped
annotations.NetBeans will now generate multiple files under source packages and under Web Pages. Here is a break-down of what was created:
controllers
, entities
and converters
resources
folder containing css/pfcrud.css
Cascading Style Sheetapphome.xhtml
containing PrimeFaces <p:menubar>
and <p:menuitem>
tags for each entitytemplate.xhtml
containing one PrimeFaces <p:layout>
and five <p:layoutUnit>
tags, four for each side, and one for the middle, where the body will be inserted for each page. The layoutUnit
with position="north"
also has the appmenu.xhtml
file included so that the menu bar will show on top.index.xhtml
with a welcome messageCreate.xhtml
, Edit.xhtml
, View.xhtml
and List.xhtml
which are include files containing <ui:composition>
tags, and the publicly exposed index.xhtml
which wraps these files together to one page to be shown to the end-user, containing <ui:include>
tags.Create.xhtml
and Edit.xhtml
containing PrimeFaces <p:dialog>
tag an HTML form, and various other PrimeFaces equivalents of JSF tags, such:<p:messages>
<p:panelGrid>
<p:inputText>
<p:selectOneMenu>
<p:commandButton>
<p:calendar>
View.xhtml
representing a simple view of the dataList.xhtml
containing PrimeFaces <p:panel>
and <p:dataTable>
, various <p:column>
tags, two <p:ajax>
tags for catching rowSelect and rowUnselect** AJAX events to update the View and Edit buttons, which will be disabled when no row is selected and enabled when a row is selected.controllers
package contains Facade files known from NetBeans' own "JSF Pages from Entity Classes" wizard, with one AbstractFacade.java
class encapsulating JPA operations for all kinds of entities, and one EntityFacade.java
for each entitybeans
package has a structure similar to the Facade pattern, with one AbstractController.java
class encapsulating all common JSF operations and then EntityController.java
classes for each entity. Since this project does not use Container-managed Dependency Injection, each entity bean is annotated with @ViewScoped
. Having every bean inside a Session is not recommended.converters
package contains one converter class per entity. @FacesConverter
classes used to be static and embedded inside the EntityController
classes. After identifying problems when many-to-many relationships were used and <p:selectManyMenu>
is generated, a design change was implemented to give Converters their own package and class.itemLabel
attributes in drop-down lists as well as for the outputText
in the List.xhtml
files. If it was unable to identify such fields, the entity's @Id
field was used. This is thanks to the Field name artifacts feature introduced in recent versions of the generator. If an entity field contains either descr
or name
(in that order), that field is then being used for e.g. the manufacturer name or the product code. This will greatly increase developer productivity as this allows developers to provide their own commonly used field names according to their data model!If you followed all the steps exactly as described above, you should now be able to Run the application inside GlassFish. Click on the Run button and observe the new pages. You can find some screen shots here:
None at the time of this writing. Be sure to check the Tickets area for any open issues.
Discussion: Replacing key value with related foreign data
Wiki: Context Dependency Injection And Its Impact On The Generator
Wiki: Home
Wiki: Installing Into Another NetBeans Version