Primefaces technology is available at http://primefaces.org/. Shortname in this page 'PF'.

MinuteProject 4 Primefaces generates a primefaces presentation stack managing advanced CRUD operations:
  • Create
  • Update
  • Delete
  • Master-detail
  • Pagination, sort, order list
  • View entity associations
    • One to many via
      • drop-down list
      • SubUC
    • Many to one via collection tabs, where element can be added (created) or removed
    • Many to many via
      • collections tab where element can be associated (referenced) or dis-associated
      • picklist where multiple element can be associated (referenced) or dis-associated

It exists with 2 backend:
  • EJB only (BELA -Basic Enterprise Layer Architecture)
  • Spring only (BSLA - Basic Enterprise Layer Architecture)

Both backend are based on JPA2.

A live demo can be found on Cloudbees at http://petshopapp.minuteproject.cloudbees.net for primefaces-spring backend.

It will also indicate you how to customize your MinuteProject 4 JSF templates. The idea is to put best-of-breed templates.
MinuteProject 4 Primefaces is a lean process, and Minuteproject is looking forward to your feed-backs.

MP will be generated on top of your data model:
  • PF menu
  • Create xhtml
  • List xhtml
  • Controller beans
  • EJB3 bean handling with JPA2 layer
  • web.xml
  • beans.xml (empty but for CDI)
  • faces-config.xml (navigation flow, i18n resource declaration)
  • i18n.properties
  • pom.xml for Front-end with PF integration
  • pom.xml global for JPA2 module and PF module.


Step

One step is needed:
  1. The first 'Generation step' consists of configuring MP kernel either via a configuration file or via the console.

Prequisites

Have Java 6 setup.
Download MinuteProjectlast version.
Check that your database connection is available

Step: Generation

Via the console
  1. Start the MP console (<MP_HOME>/bin/start-console.(cmd/sh). How to use the console.
  2. Fill the connection information to the datamodel
  3. Fill the model general information (model, package names, version primary key policy, scope).
  4. Choose JSF-Primefaces target
  5. Click generate

Via the configuration file
An example can be found <MP_HOME>/demo/config/mp-config-JSF-EJB3.xml.
To run it: execute demo-JSF-primefaces.(cmd/sh)

Target Configuration used in mp-config-JSF-EJB3.xml

<!DOCTYPE root>
<generator-config xmlns="http://minuteproject.sf.net/xsd/mp-config"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:noNamespaceSchemaLocation="mp-config.xsd">
    <configuration>
        <conventions>
            <target-convention type="enable-updatable-code-feature" />
        </conventions>
        <model name="petshop" version="1.0" package-root="net.sf.mp.demo">
            <data-model>
                <driver groupId="org.apache.derby" artifactId="derby" version="10.8.1.2"/>
                <fileSource name="petshop" dir="c:/MinuteProject/data">
                </fileSource>
                <!--
                <dataSource>
                    <driverClassName>org.apache.derby.jdbc.ClientDriver</driverClassName>
                    <url>jdbc:derby://localhost:1527/sample</url>
                    <username>app</username>
                    <password>app</password>
                </dataSource>
                <schema>app</schema>
                -->
                <dataSource>
                    <driverClassName>org.hsqldb.jdbcDriver</driverClassName>
<!--                     <url>jdbc:hsqldb:hsql://127.0.0.1:9001/petshop</url> -->
                    <url>jdbc:hsqldb:file:../minuteSample/petstore-database/hsql/petshop</url>
                    <username>sa</username>
                    <password></password>
                </dataSource>
 
                <primaryKeyPolicy oneGlobal="true">
                    <primaryKeyPolicyPattern name="autoincrementPattern"/>
                </primaryKeyPolicy>
            </data-model>
            <business-model>
                <generation-condition>
                    <condition type="exclude" startsWith="DUAL"></condition>
                    <condition type="exclude" startsWith="ID_GEN"></condition>
                    <condition type="exclude" startsWith="SEQUENCE"></condition>
                </generation-condition>
                <business-package default="pet">
                    <condition type="package" startsWith="PRODUCT" result="product"></condition>
                    <condition type="package" startsWith="ITEM" result="product"></condition>
                </business-package>
                <enrichment>
                   <conventions>
                      <entity-naming-convention type="apply-strip-table-name-prefix" pattern-to-strip="SYS,FIN"/>
                      <reference-naming-convention type="apply-referenced-alias-when-no-ambiguity" is-to-plurialize="true"></reference-naming-convention>
                   </conventions>
                    <package name="product">
                        <entity-group entities="PRODUCT"></entity-group>
                        <entity-group entities="ITEM"></entity-group>
                    </package>
                    <entity name="PRODUCT" alias="MY_GOOD_PRODUCT">
                    </entity>
                    <entity name="ITEM" alias="MY_GOOD_ITEM" comment="my item table">
                        <field name="PRODUCTID" alias="THIS_IS_MY_PRODUCT" comment="my product field reference"></field>
                    </entity>
                    <entity name="CATEGORY" content-type="reference-data" >
                       <semantic-reference>
                         <sql-path path="NAME"/>
                       </semantic-reference>
                    </entity>
                </enrichment>
            </business-model>
        </model>
        <targets catalog-entry="Primefaces-JEE" />
        <!-- for the primefaces with spring version
                <target catalog-entry="Primefaces-Spring" />
                -->
    </configuration>
</generator-config>

Target Configuration explained
  • Node JPA2 means that MP will generate the associated JPA2 entities entities such as shipped in JPA2 track
  • Node LIB means that some reference are used (velocity lib) but there is nothing generated
  • Node JSF focuses on the core JSF presentation stack associated controller beans, maven integration
  • Node MavenMaster generates a master pom for JPA2 and JSF-primefaces tracks
  • Node documentation gives information relevant to the generation such as number of artifacts generated per template



The rest of the page will deal with the code generated from the demo application


Resulting artifacts

You can have the resulting source if you download demo-src-generated-0.5.6.zip

4 maven pom project structure are generated
  • One global for JPA2, BELA and JSF
  • One for JPA2 (see JPA2)
  • One for BELA
  • One for JSF (primefaces implementation) whose structure open as a maven eclipse project is the following

demo-petshop-JSF-mvn-structure.png

Trick

There is a little trick at this level which is only specific to this demo and may not be relevant for your generation.

Minuteproject is shipped with hsqldb sample db called petshop.
I have to use a JEE6 container (CDI working).
I've choosen glassfish.
Meanwhile I do not know how to configure correctly a connection pool for HSQLDB on glassfish.
So...
Since I know how to do with Derby DB, I have to:
  1. Pass the petshop sql script on a derby instance (available in <MP_HOME>/sample/hsql/petshop.sql)
  2. Overwrite the persistence xml in /output/JSF/petshop/JPA2/src-overwritten/main/resources/META-INF
  3. Configure the appropriate Datasource here jdbc/petshopDS

persistence.xml to copy in /output/petshop/JPA2/src-overwritten/main/resources/META-INF
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">
 
    <persistence-unit name="petshop" transaction-type="JTA">
        <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        <jta-data-source>jdbc/petshopDS</jta-data-source>
        <!-- pet -->
        <class>net.sf.mp.demo.petshop.pet.Address</class>
        <class>net.sf.mp.demo.petshop.pet.Category</class>
        <class>net.sf.mp.demo.petshop.pet.Sellercontactinfo</class>
        <class>net.sf.mp.demo.petshop.pet.Sequence</class>
        <class>net.sf.mp.demo.petshop.pet.Tag</class>
        <class>net.sf.mp.demo.petshop.pet.Ziplocation</class>
 
        <!-- product -->
        <class>net.sf.mp.demo.petshop.product.MyGoodItem</class>
        <class>net.sf.mp.demo.petshop.product.MyGoodProduct</class>
<!-- optional if you do not want to run the sql script
        <properties>
            <property name="eclipselink.ddl-generation" value="create-tables" />
        </properties>
-->
    </persistence-unit>
 
</persistence>
The maven build script will overwrite to default by this one.

Remark: since the database upon with to run the app is no more hsqldb but derby, the primary key policy is autoincrement.

Suggestions to solve this issues are welcomed.


Packaging-deployment


Packaging

On /output/JSF/petshop run:
mvn package
It will create the
  • JPA2 backend
  • JSF front end

The result app war petshopApp.war is in /output/JSF/petshop/JSF/target.

Deployment

Start glassfish
Check jdbc/petshopDS Datasource is configured.
Deploy App


Screens

Start your navigation at http://localhost:8080/petshopApp

Details screens here.




Main knowledge flows


Sources
http://www.primefaces.org/

http://primefaces-rocks.appspot.com

Excellent tutorial
http://www.hascode.com/2011/02/creating-a-sample-java-ee-6-blog-application-with-jpa-ejb-cdi-jsf-and-primefaces-on-glassfish/

Primefaces example with pagination
http://hrycan.com/2012/03/28/primefaces-lazy-loading-datatable-for-jsf2/