SeamFramework.orgCommunity Documentation

Chapter 2. Generating a basic Java EE web-application

2.1. First steps with Scaffolding

For the most part, people interested in Forge are likely interested in creating web-applications. Thusly, this chapter will overview the basic steps to generate such an application using Forge.

Assuming you have already completed the steps to install Forge, the first thing you'll need to do is download and install JBoss Application Server 6.0 or 7.0. This server will host your application once it is built.

Next, follow these steps to create your skeleton web-application; be sure to replace any {ARGS} with your own personal values. Also keep in mind that while typing commands, you may press <TAB> at any time to see command completion options:

  1. Execute 'forge' from a command prompt.
  2. Create a new project:
    $ new-project --named {name} --topLevelPackage {com.package} --projectFolder {/directory/path}
  3. Set up scaffolding, and press ENTER to confirm installation of any required facet dependencies and/or packaging types:
    $ scaffold setup 
    Then set up default index files, a default template and home-page. This creates the page that users will first see when accessing your application.
    $ scaffold create-indexes --overwrite
  4. Set up persistence (JPA), and press ENTER to confirm installation of any required facet dependencies and/or packaging types, and remember to press TAB if you are not sure what comes next.
    $ persistence setup --provider {your JPA implementation} --container {your container}
    If you do not wish to use a Java EE container default data-source, you can also specify additional connection parameters such as JNDI data-source names, JDBC connection information, and data-source types. Note, however, that this means you will probably need configure your application server to provide this new data-source and/or database connection.
  5. Create some JPA entities:
    $ new-entity --named Customer
    At which point Forge should automatically pick-up the newly created entity, and will be ready to add fields.
    Customer.java $ new-field string --named firstName
    Customer.java $ new-field string --named lastName
    You may inspect the entity using 'ls'.
    Customer.java $ ls
    
    [fields]
    private::String::firstName;       private::String::lastName;
    private::int::version;               private::long::id;
    
    [methods]
    public::getFirstName()::String                                               public::getId()::long
    public::getLastName()::String                                                public::getVersion()::int
    public::setFirstName(final String firstName)::void                    public::setId(final long id)::void
    public::setLastName(final String lastName)::void                     public::setVersion(final int version)::void
    public::toString()::String                                                          
    
    Customer.java $
  6. Once you have created fields in the entity, it's time to generate some scaffolding. For now, use the Forge default scaffold; you'll also need to confirm installation of a few libraries/dependencies.
    Customer.java $ scaffold from-entity 
                   
    No scaffold type was provided, use Forge default? [Y/n] 
    Install which version of Metawidget?
    
      1 - [org.metawidget:metawidget:1.0.5]
      2 - [org.metawidget:metawidget:1.10]
    
    Choose an option by typing the number of the selection: 2
    Install which version of Seam Persistence?
    
      1 - [org.jboss.seam.persistence:seam-persistence:3.0.0-SNAPSHOT]
      2 - [org.jboss.seam.persistence:seam-persistence:3.0.0.Final]
    
    Choose an option by typing the number of the selection: 2
     
    Wrote /src/main/webapp/resources/forge-template.xhtml
    Wrote /src/main/webapp/resources/forge.css
    Wrote /src/main/webapp/resources/favicon.ico
    Wrote /src/main/java/com/scaffold/domain/Customer.java
    Wrote /src/main/java/com/scaffold/view/CustomerBean.java
    Wrote /src/main/webapp/scaffold/customer/view.xhtml
    Wrote /src/main/webapp/scaffold/customer/create.xhtml
    Wrote /src/main/webapp/scaffold/customer/list.xhtml
    ***SUCCESS*** Generated UI for [com.scaffold.domain.Customer]
    
    Customer.java $
  7. That's it! Now build your project and deploy it onto your JBoss Application Server instance:
    $ build
    Or, if you have installed Apache Maven 3.0+, and set your JBOSS_HOME environment variable to the location of your JBoss AS server installation folder, you can also build and deploy your application with the following commands.
    $ cd -
    $ mvn clean package
    $ mvn jboss:hard-deploy
    $ mvn jboss:start
    Your project can correspondingly be undeployed using:
    $ mvn jboss:hard-undeploy
    $ mvn jboss:stop
  8. Access your application at: http://localhost:8080/{name}-1.0.0-SNAPSHOT/
  9. Access scaffolded entities at: http://localhost:8080/{projectname}/faces/scaffold/{entity}/view.xhtml