Posts Tagged ‘JSF’

Creating And Running JSF Project

Sunday, August 2nd, 2009

These notes follow on from my previous posting regarding JavaServer Faces Technology – JSF. In this post, I’m going to quickly outline the necessary steps for getting a very simple JSF project running within Galileo.

First, you’ll need to download Mojarra and unpack it somewhere.

Go to the Java EE perspective and create a new project to get the “New Project” wizard to appear. Expand out “Web” and select “Dynamic Web Project”. Give the project a name.

The “Target Runtime” should be Apache Tomcat v6.0, The Dynamic web module version should be 2.5 and select JavaServer Faces v1.2 Project as your configuration option.

Choose “Next” for the Source folders option and “Next” for the Web Module settings.

For the JSF Implementation Library settings, click on the “Manage Libraries” link (it’s the icon on the right, just below the “Type” dropdown list), Select “New”, create a name (e.g. “Mojarra”) and check the System Library checkbox. Select OK and then highlight the library you just created and select “Add JARs”. Navigate to the folder where you unpacked Mojarra and go to its lib folder. Select both jsf-impl.jar and jsf-api.jar and then select “Open”.

Both JARs should be visible under the library you created. Select “OK” and now check the library you just created and select “Finish”. You should now be ready to start coding.

To create a simple JSF example project:

1. Right-click on your Java Resources:src folder and select New > Other. Expand out “General” and select “File” and select “Next”. If it asks you to select a “parent folder”, just select the src folder for the project you just created. The file should be called messages.properties. In that file, add a line: greeting=JSF is working and save the file.

2. in WebContent/WEB-INF/web.xml, find the <servlet-mapping> and make sure it looks like this:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>

3. Right-click on WebContent and select “New” and “JSP”. Name it “index.jsp”. You should have a basic html template page.
In the body of the template, paste in:
<jsp:forward page=”/faces/greeting.jsf” />

4. Create a folder called “faces” under “WebContent”

5. Create a New JSP file inside the “faces” folder. Call it greeting.jsp (note the file extension is jsp, *not* jsf)

6. And in between the body tags, paste in:
<f:view>
<f:loadBundle basename=”messages” var=”message”/>
<p><h:outputText value=”#{message.greeting}” /></p>
</f:view>

7. Run it!!

JavaServer Faces Technology – JSF

Saturday, June 27th, 2009

JavaServer Faces technology is a server-side user interface component framework for Java technology-based web applications, its includes

  • A set of APIs for representing UI components and managing their state, handling events and input validation, defining page navigation, supporting internationalization and accessibility and providing extensibility for all these features.
  • A JavaServer Pages (JSP) custom tag library for expressing JavaServer Faces UI components within a JSP page and for wiring components to server-side objects

The well-defined programming model and tag libraries significantly ease the burden of building and maintaining web applications with server-side UIs. Here is the model:

One of the greatest advantages of JavaServer Faces technology is that it offers a clean separation between behavior and presentation. Web applications built using JSP technology achieve this separation in part. However, a JSP application cannot map HTTP requests to component-specific event handling nor manage UI elements as stateful objects on the server, as a JavaServer Faces application can. JavaServer Faces technology allows you to build web applications that implement the finer-grained separation of behavior and presentation that is traditionally offered by client-side UI architectures. The separation of logic from presentation also allows each member of a web application development team to focus on his or her piece of the development process, and it provides a simple programming model to link the pieces.

Another important goal of JavaServer Faces technology is to leverage familiar UI-component and web-tier concepts without limiting you to a particular scripting technology or markup language. Although JavaServer Faces technology includes a JSP custom tag library for representing components on a JSP page, the JavaServer Faces technology APIs are layered directly on top of the Servlet API.

Most importantly, JavaServer Faces technology provides a rich architecture for managing component state, processing component data, validating user input, and handling events.

For the most part, a JavaServer Faces application is like any other Java web application. A typical JavaServer Faces application includes the following pieces:

  1. A set of JSP pages (although you are not limited to using JSP pages as your presentation technology)
  2. A set of backing beans, which are JavaBeans components that define properties and functions for UI components on a page
  3. An application configuration resource file, which defines page navigation rules and configures beans and other custom objects, such as custom components
  4. A deployment descriptor (a web.xml file)
  5. Possibly a set of custom objects created by the application developer. These objects might include custom components, validators, converters, or listeners
  6. A set of custom tags for representing custom objects on the page