JSF Framework Services

Development Environments for JSF

You can produce the pages and configuration files for a simple JSF application with a text editor. However, as your applications become more complex, you will want to use more sophisticated tools. In the next three sections, we discuss JSF support in integrated development environments, visual builder tools, and build automation with Ant.

Integrated Development Environments

IDEs, such as Eclipse or NetBeans, are deservedly popular with programmers. Support for autocompletion, refactoring, debugging, and so on, can dramatically increase programmer productivity, particularly for large projects.

As this book is written, Eclipse has an experimental JSF plug-in that plainly needs more work. Several commercial Eclipse derivatives (such as MyEclipse, Exadel Studio, BEA Workshop Studio, and Rational Application Developer) have better JSF support, but some of them are expensive. They all have trial versions that you can download.

NetBeans, on the other hand, is free and has very good JSF support out of the box. If you are not satisfied with the JSF support in your favorite IDE, we suggest that you give NetBeans a try.

NetBeans gives you autocompletion in JSF pages and configuration files. With NetBeans, it is very easy to launch or debug JSF applications just by clicking toolbar buttons. Figure 1-7 shows the NetBeans debugger, stopped at a breakpoint in the UserBean class.

Figure 1-7. Using NetBeans for JSF debugging
 


Note

Since the user interfaces for IDEs can change quite a bit between versions, we put a guide for getting started with NetBeans on the web (http://corejsf.com) rather than in the printed book.


Visual Builder Tools

A visual builder tool displays a graphical representation of the components and allows a designer to drag and drop components from a palette. Builder tools can be standalone programs such as Sun Java Studio Creator, or they can be modules of integrated development environments.

Figure 1-8 shows Sun Java Studio Creator (http://www.sun.com/software/products/jscreator). The component palette is in the lower-left corner. You drag the components onto the center of the window and customize them with the property sheet in the upper-right corner. The environment produces the corresponding JSF tags automatically (see Figure 1-9).

Figure 1-8. Visual JSF development environment


Figure 1-9. Automatically generated JSF markup


Moreover, visual builders give you graphical interfaces for specifying the navigation rules and beans (see Figure 1-10). The faces-config.xml file is produced automatically.

Figure 1-10. Visually specifying navigation rules


Unfortunately, Java Studio Creator has a rather rigid page structure that is not optimal for learning about JSF. We recommend that you use another environment for working through the book examples. After studying the book examples, you will know enough about JSF to use Java Studio Creator effectively for your own projects.

Sun has announced that visual tools from Java Studio Creator will be integrated into future versions of NetBeans. Future versions of Eclipse are also expected to include visual builder features.

Automation of the Build Process with Ant

Many programmers prefer to stick with their favorite text editor or IDE, even if it has little support for JSF. The manual build process that we described earlier in this chapter can become tedious if you need to do it over and over. In this section, we describe how you can automate the process with Ant. The material in this section is not required for working with JSF feel free to skip it if your IDE has good JSF support or if the manual build process does not bother you.

Fortunately, you need not know much about Ant if you want to use the build script that we prepared. Start by downloading Ant from http://ant.apache.org and install it in a directory of your choice. Or, if you use GlassFish, use the asant tool that is included in the glassfish/bin directory.

Ant takes directions from a build file. By default, the build file is named build.xml. We provide a build.xml file for building JSF applications. This file is contained in the root of the corejsf-examples directory. The build.xml file contains the instructions for compiling, copying, zipping, and deploying to an application server, described in XML syntax (see Listing 1-7).

Listing 1-7. build.xml

  1. <project default="install">   2.   3.    <property environment="env"/>   4.    <property file="build.properties"/>   5.    <property name="appdir" value="${basedir}/${app}"/>   6.    <basename property="appname" file="${appdir}"/>   7.    <property name="builddir" value="${appdir}/build"/>   8.    <property name="warfile" value="${builddir}/${appname}.war"/>   9.  10.    <path >  11.       <pathelement location="${javaee.api.jar}"/>  12.       <fileset dir="${appdir}">  13.         <include name="web/WEB-INF/**/*.jar"/>  14.       </fileset>  15.    </path>  16.  17.    <target name="init">  18.       <fail unless="app" message="Run ant -Dapp=..."/>  19.    </target>  20.  21.    <target name="prepare" depends="init"  22.          description="Create build directory.">  23.       <mkdir dir="${builddir}"/>  24.       <mkdir dir="${builddir}/WEB-INF"/>  25.       <mkdir dir="${builddir}/WEB-INF/classes"/>  26.    </target>  27.  28.    <target name="copy" depends="prepare"  29.          description="Copy files to build directory.">  30.       <copy todir="${builddir}" failonerror="false" verbose="true">  31.          <fileset dir="${appdir}/web"/>  32.       </copy>  33.       <copy todir="${builddir}/WEB-INF/classes"  34.            failonerror="false" verbose="true">  35.          <fileset dir="${appdir}/src/java">  36.             <exclude name="**/*.java"/>  37.          </fileset>  38.       </copy>  39.       <copy todir="${builddir}/WEB-INF" failonerror="false" verbose="true">  40.          <fileset dir="${appdir}">  41.             <include name="lib/**"/>  42.          </fileset>  43.       </copy>  44.    </target>  45.  46.    <target name="compile" depends="copy"  47.          description="Compile source files.">  48.       <javac  49.          srcdir="${appdir}/src/java"  50.          destdir="${builddir}/WEB-INF/classes"  51.          debug="true"  52.          deprecation="true">  53.          <compilerarg value="-Xlint:unchecked"/>  54.          <include name="**/*.java"/>  55.          <classpath ref/>  56.       </javac>  57.    </target>  58.  59.    <target name="war" depends="compile"  60.          description="Build WAR file.">  61.       <delete file="${warfile}"/>  62.       <jar jarfile="${warfile}" basedir="${builddir}"/>  63.    </target>  64.  65.    <target name="install" depends="war"  66.          description="Deploy web application.">  67.       <copy file="${warfile}" todir="${deploy.dir}"/>  68.    </target>  69.  70.    <target name="clean" depends="init"  71.          description="Clean everything.">  72.       <delete dir="${builddir}"/>  73.    </target>  74. </project>

To use this build file, you must customize the build.properties file that is contained in the same directory. The default file looks like what is shown in Listing 1-8.

Listing 1-8. build.properties

  1. appserver.dir=${env.GLASSFISH_HOME}   2. javaee.api.jar=${appserver.dir}/lib/javaee.jar   3. deploy.dir=${appserver.dir}/domains/domain1/autodeploy

You need to change the directory for the application server to match your local installation. Edit the first line of build.properties.

Now you are ready to build the sample application (see Figure 1-11).

Figure 1-11. Installing a web application with Ant

4


1.

Open a command shell and change into the corejsf-examples directory.

2.

Run the command

apache-ant/bin/ant -Dapp=ch1/login

Here, apache-ant is the directory into which you installed Ant, such as c:\apache-ant-1.6.5. With GlassFish, you can also use

glassfish/bin/asant -Dapp=ch1/login

Note

Our Ant script is a bit different from the scripts that you often find with sample applications. We use a single script that can build all applications in the book. You use the -Dapp=... flag to specify the name of the application that you want to build. We think that approach is better than supplying lots of nearly identical scripts. Note that you call the script from the corejsf-examples directory, not the directory of the application.



Core JavaServerT Faces
Core JavaServer(TM) Faces (2nd Edition)
ISBN: 0131738860
EAN: 2147483647
Year: 2004
Pages: 84

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net