Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PrimeFaces Cookbook

You're reading from   PrimeFaces Cookbook Here are over 100 recipes for PrimeFaces, the ultimate JSF framework. It's a great practical introduction to leading-edge Java web development, taking you from the basics right through to writing custom components.

Arrow left icon
Product type Paperback
Published in Jan 2013
Publisher Packt
ISBN-13 9781849519281
Length 328 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Mert Caliskan Mert Caliskan
Author Profile Icon Mert Caliskan
Mert Caliskan
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

PrimeFaces Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started with PrimeFaces FREE CHAPTER 2. Theming Concept 3. Enhanced Inputs and Selects 4. Grouping Content with Panels 5. Data Iteration Components 6. Endless Menu Variations 7. Working with Files and Images 8. Drag Me, Drop Me 9. Creating Charts and Maps 10. Miscellaneous, Advanced Use Cases Index

PrimeFaces scaffolding with Spring Roo


Spring Roo is a next-generation rapid application development tool that uses Convention over Configuration principles. It is a text-based open source tool that can be used for creating and managing Spring-based applications. It uses mature libraries such as Spring framework, Java Persistence API, Java Server Pages (JSP), Spring Security, Spring Web Flow, Log4J, and Maven. Spring Roo also provides scaffolding for web-based applications that are powered by PrimeFaces.

Getting ready

At the time of writing this book, the latest version of Spring Roo was version 1.2.2. It can be downloaded at http://www.springsource.com/download/community?project=Spring%20Roo. More information on Spring Roo, along with the list of commands, can be found at http://www.springsource.org/spring-roo.

Also, Maven—the Apache build manager for Java projects—needs to be installed as a prerequisite. At the time of writing this book, Maven v3.0.4 was used. For more information on this, please visit http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html.

How to do it...

For PrimeFaces scaffolding with Spring Roo, follow these steps:

  1. We will create the folder where the project will reside and then change directory to it.

    mkdir primefaces-cookbook-roo
    cd primefaces-cookbook-roo
    
  2. Now we can execute the roo command within the folder. Linux, Unix, or Mac OS users should execute roo.sh, and Windows users should execute the roo.bat file. Then, we should see the console output as shown in the following screenshot:

  3. Then, in the command line, we can create the sample roo project by specifying its name and its packaging structure as follows:

    roo> project --projectName primefaces-cookbook-roo --topLevelPackage org.primefaces.cookbook
    
  4. After that, we can add a persistency layer to the project structure as follows:

    roo> persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
    

    With the persistence command, we are specifying the provider as HIBERNATE and stating that an in-memory database will be used for testing purposes.

  5. Create enum for the type of manufacturer of the car.

    roo> enum type --class ~.domain.Manufacturer 
    roo> enum constant --name Volkswagen
    roo> enum constant --name Mercedes
    roo> enum constant --name BMW
    roo> enum constant --name Audi
    
  6. Then we can create the class for the car.

    roo> entity jpa --class ~.domain.Car
    roo> field number --fieldName yearOfManufacture --type java.lang.Integer --notNull
    roo> field string --fieldName name --notNull 
    roo> field enum --fieldName manufacturer --type ~.domain.Manufacturer –-notNull
    
  7. After that, we can create the project and package it as a .war file:

    roo> web jsf setup --implementation APACHE_MYFACES --library PRIMEFACES --theme EGGPLANT
    roo> web jsf all --package org.primefaces.cookbook
    
  8. Then, finally exit Spring Roo console with:

    roo> quit
    

When we list the directory for the files, we have two files and a source directory created as follows in the Linux, Unix, or Mac OS environment:

-rw-r--r--   1 primeuser staff    834 May 21 16:45 log.roo
-rw-r--r--   1 primeuser staff  17650 May 21 16:45 pom.xml
drwxr-xr-x   3 primeuser staff    102 May 21 16:45 src

Now our project is ready to run. From the command line, we can execute jetty to get the web application context up and running.

mvn jetty:run

Now we can request for the URL on local via browser (http://localhost:8080/primefaces-cookbook-roo), which will bring up the scaffold user interface of the web application, as shown in the following screenshot:

How it works...

With the commands provided, Spring Roo does all the scaffolding to create a web application powered by PrimeFaces. In the end, it will create the Car and Manufacturer domain classes, the converter for the Car class, and the web pages for providing the CRUD operations on the Car class.

You have been reading a chapter from
PrimeFaces Cookbook
Published in: Jan 2013
Publisher: Packt
ISBN-13: 9781849519281
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime