PrimeFaces Templates in NetBeans

These are customized template files of PrimeFaces to generate JSF pages and their controllers automatically by NetBeans IDE. Original template files in NetBeans 8.2 are put here too to compare what changes are made.

Why customize the template files


NetBeans is the open source IDE provided by Oracle and represents latest techniques, especially in Java EE area. PrimeFaces is one of the JSF frames officially embedded in NetBeans. Following address is the tutorial about "Generating a JavaServer Faces 2.x CRUD Application from a Database"

Automatic generation of files in MVC model with NetBeans saved many efforts for my Java EE projects. Example, one of my project has 80 database tables. By using wizard "New > Entity Classes from Database", 80 JPA entities files are generated automatically in 1 minutes. Then by using wizard "New > JSF Pages from Entity Classes", 80 JPA session beans, 80 JSF controller beans, 320 JSF files, the language bundle file, and other support files are generated automatically in 5 minutes. The left thing is to modify or extend these files as project requirements.

When default templates are not enough and some modification are common for all automatically generated JSF files, template files need be customized in NetBeans.

How to replace the template files


In NetBeans IDE, click the menu item "Tools - Templates" as following: snapshot

Select template files under "JavaServer Faces - JSF from Entity - PrimeFaces" as following: snapshot

Click button "Open in Editor", and replace its contents with the customized file download from this repository.

Changes of the customized "Controller.java"


This file is used to generate all JSF beans automatically by NetBeans when select PrimeFaces template. Following snapshots show the main differences from original file:

differences 1
differences 2
differences 3

The major changes include:

  1. Variables are changed from "private" to "protected" for convenience of inheriting generated beans to customized beans.
  2. "selectRows" is defined for operations of multiple selection of rows.
  3. "needLoadItems" is defined to replace "items == null" for re-querying data.

Changes of the customized "Create.xhtml" and "Edit.xhtml"


Following snapshot shows the main differences from original file:

differences

The major changes include:

  1. Add specific template for the field of automatically increased id: It can not be input and is shown as a message like "automatically generated".
  2. Add specific template for the field of password: It is within component "p:password".
  3. Update template for field of dateTime: Its pattern, timeZone, and locale are defined and its calendar style is changed a little.
  4. Add specific template for the field of "createTime" and "recordTime": It can not be input and will be filled by beans automatically.

Following snapshots show the generated "Create.xhtml" and "Edit.xhtml" with the customized template: snapshot snapshot

Changes of the customized "List.xhtml"


Following snapshot shows the main differences from original file: differences

The major changes include:

  1. "selectionMode" is changed as "multiple". And related ajax events are added.
  2. Paginator is enriched with more elements and information.
  3. Add toggler and tips in the header.
  4. Columns can be sorted and filtered.
  5. Fields of dateTime are defined with pattern, timeZone, and locale.
  6. Multiple selection for deletion.
  7. Confirm dialog when delete.

Following snapshot shows the generated "List.xhtml" with the customized templates: snapshot