Customizing your application with Seam Plugin in 5 minutes
From Clickframes
Contents |
Overview
In the first tutorial, we saw how to create and launch a new application with the Seam Plugin. This tutorial explains how to customize the generated application.
Pre-requisite
Go to the root directory of the project you created in the previous tutorial.
cd myprojectname
Changing appspec.xml
You can make edits to your appspec file
Open your appspec.xml file. This file defines all the pages in the application and inputs, forms, links, etc. on each page. Note: where the command below specifies "vi", insert any appropriate text editor.
vi src/main/resources/appspec.xml
Add a global link
For fun, add a link to your favorite search engine to the global links. Find the following, at line 18, and add the Google link as follows:
<linkSet id="global" global="true">
<title>Global Navigation</title>
<link>
<title>Google search</title>
<href>http://www.google.com</href>
</link>
<link>
<title>Home</title>
<pageRef>login</pageRef>
</link>
Other changes to appspec.xml
You can modify page title, page description and other appspec elements. Please see the appspec reference documentation for a list of all the element definitions.
Re-generate the application
mvn org.clickframes:clickframes-maven-plugin:0.9.7:generate
Re-run the application
After making all the changes, simply re-run the application, it's that simple!
mvn glassfish:run
View the application
Point your browser to the following URL. You should see the new link and other changes.
http://localhost:8080/myprojectname/
Building a .war file
If you want to build a .war file to deploy to an external application server, just run:
mvn package
Java application servers can be a little bit picky about the libraries installed. Unfortunately a complex .war file that runs in Glassfish won't always run in JBoss (or vice versa). So we've built a set of Maven profiles for you to use. The default profile builds a .war that will run in Glassfish. To build a JBoss 4 compatible war, just use:
mvn -Pjboss package
Change the look and feel of the site
While the default application is generated with a simple user interface, you have complete control over the layout and css of your site.
Changing the header, footer and layout
Seam plugin uses facelets and xhtml for authoring web pages. You can edit the default layout file (src/main/webapp/WEB-INF/facelets/layout/layout.xhtml) to define your own base layout.
To change the format of particular pages, you edit the associated .xhtml page in the src/main/webapp directory. These XHTML files are based on the Facelets tool, and can be easily edited. You'll note that there are several custom tags referenced in each XHTML page. These are auto-generated facelets tags (you'll find the .XHTML source for each tag in the WEB-INF/facelets/tags directory), and you shouldn't have to modify them - they contain the validation logic for the application, and will be re-generated whenever you change the requirements in the appspec.
Changing CSS
Seam plugin ships with a default style.css file. Edit the file to take complete control of the look and feel.
- src/main/webapp/css/style.css
Adding your own Controller Code
A Seam tutorial is beyond the scope of this Quick Start tutorial. But when it comes time to start writing actual business logic, you can open the src/main/java/com/[your.package.name]/controller directory. For each page you'll see two controllers - a "generated" controller and a regular controller that inherits from it. You should try to avoid modifying the GeneratedXXXController.java files, since if you leave them alone Clickframes can update them for you when the application's requirements change. Your code goes into the regular XXXController.java files.

