Red Hat JBoss Developer Studio 4.1 JSF Tools Reference Guide

Red Hat JBoss Developer Studio 4.1 JSF Tools Reference Guide
Red Hat JBoss Developer Studio
4.1
JSF Tools Reference Guide
Provides information relating to the JSF Tools module.
Edition 4.1.0
Anatoly Fedosik
Olga Chikvina
Svetlana Mukhina
Red Hat JBoss Developer Studio 4.1 JSF Tools Reference Guide
Provides information relating to the JSF Tools module.
Edition 4.1.0
Anato ly Fedo sik
Olga Chikvina
Svetlana Mukhina
[email protected] m
Legal Notice
Copyright © 2011 Red Hat.
T his document is licensed by Red Hat under the Creative Commons Attribution-ShareAlike 3.0 Unported
License. If you distribute this document, or a modified version of it, you must provide attribution to Red
Hat, Inc. and provide a link to the original. If the document is modified, all Red Hat trademarks must be
removed.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section
4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, MetaMatrix, Fedora, the Infinity Logo,
and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux ® is the registered trademark of Linus T orvalds in the United States and other countries.
Java ® is a registered trademark of Oracle and/or its affiliates.
XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States
and/or other countries.
MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and other
countries.
Node.js ® is an official trademark of Joyent. Red Hat Software Collections is not formally related to or
endorsed by the official Joyent Node.js open source or commercial project.
T he OpenStack ® Word Mark and OpenStack Logo are either registered trademarks/service marks or
trademarks/service marks of the OpenStack Foundation, in the United States and other countries and
are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or
sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
Abstract
T he JSF T ools Reference Guide explains how to use the JSF T ools module to develop JSF applications.
Table of Contents
Table of Contents
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3. . . . . . . . . .
Preface
.Chapter
. . . . . . . . 1.
. . .Introduction
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . .
1.1. Key Features of JSF T ools
4
1.2. Other relevant resources on the topic
4
.Chapter
. . . . . . . . 2.
. . .JavaServer
. . . . . . . . . . . . Faces
. . . . . . .Support
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5. . . . . . . . . .
2.1. Facelets Support
5
2.1.1. Facelets templates
6
2.1.2. Facelets components
7
2.1.3. Code assist for Facelets
8
2.1.4. Open On feature
10
.Chapter
. . . . . . . . 3.
. . .Projects
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
............
3.1. Creating a New JSF Project
11
3.2. Importing Existing JSF Projects with Any Structure
15
3.3. Adding JSF Capability to Any Existing Eclipse Project
15
3.4. Adding Your Own Project T emplates
20
3.5. Relevant Resources Links
22
.........4
Chapter
. ...Web.xml
. . . . . . . . .Editor
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23
...........
.Chapter
. . . . . . . . 5.
. . .JSF
. . . . Configuration
. . . . . . . . . . . . . . .File
. . . . Editor
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
............
5.1. Diagram view
24
5.2. T ree View
28
5.3. Source View
38
5.4. Editor Features
39
5.4.1. Open On
40
5.4.2. Code Assist
40
5.4.3. Error Reporting
40
.Chapter
. . . . . . . . 6.
. . .Managed
. . . . . . . . . .Beans
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4. .2. . . . . . . . . .
6.1. Code Generation for Managed Beans
42
6.2. Add Existing Java Beans to a JSF Configuration File
47
.Chapter
. . . . . . . . 7.
. . .Creation
. . . . . . . . . and
. . . . .Registration
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4. .9. . . . . . . . . .
7.1. Create and Register a Custom Converter
49
7.2. Create and Register a Custom Validator
52
7.3. Create and Register Referenced Beans
57
. . . . . . . . . 8.
Chapter
. . .JSF
. . . . Project
. . . . . . . . Verification
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .63
...........
.Getting
. . . . . . . .Help
. . . . .and
. . . . Giving
. . . . . . . .Feedback
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
............
A.1. Do You Need Help?
68
A.2. Give us Feedback
68
. . . . . . . . . .History
Revision
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
............
1
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
2
Preface
Preface
T his manual uses several conventions to highlight certain words and phrases and draw attention to
specific pieces of information. T o get more information on these conventions please refer to the
Docum ent Conventions manual, which can be found on the Red Hat Documentation website under
the JBoss Developer Studio section.
3
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Chapter 1. Introduction
JSF T ools are especially designed to support JSF and JSF-related technologies. JSF T ools provide
extensible tools for building JSF-based applications as well as adding JSF capabilities to existing web
projects, importing JSF projects and choosing any JSF implementation while developing JSF application.
T his guide provides the information on JSF tooling you need to allow you to quickly develop JSF
applications with far fewer errors.
1.1. Key Features of JSF Tools
T he table below lists the functionality provided by the JSF T ools.
T able 1.1. Key Functionality for JSF T ools
Feature
Benefit
Chapter
JSF and Facelets
support
Step-by-step wizards for creating new JSF and
Facelets projects with a number of predefined
templates, importing existing ones and adding
JSF capabilities to non-JSF web projects.
Chapter 2, JavaServer
Faces Support
Flexible and
customizable project
template management
Jump-start development with the supplied
templates or easily create customized templates
for re-use.
Chapter 3, Projects
Support for JSF
Configuration File
Work on a file using three modes: diagram, tree
and source. Automatic synchronization between
the modes and full control over the code. Easily
move around the diagram using the Diagram
Navigator.
Chapter 5, JSF
Configuration File
Editor
Support for Managed
Beans
Adding new managed beans, generating code for
attributes, properties and getter/setter methods.
Chapter 6, Managed
Beans
Support for Custom
Converters and
Validators
Fast creation of custom converters and validators
with a tree view of the faces-config.xm l file.
Chapter 7, Creation
and Registration
Verification and
Validation
All errors will be immediately reported by
verification feature, no matter in what view you are
working. Constant validation and error checking
allows you to catch many of the errors during
development process that significantly reduces
development time.
Chapter 8, JSF Project
Verification
1.2. Other relevant resources on the topic
All JBoss Developer Studio and JBoss T ools release documentation can be found on the RedHat
Documentation website.
Nightly documentation builds are available at http://download.jboss.org/jbosstools/nightly-docs.
4
Chapter 2. JavaServer Faces Support
Chapter 2. JavaServer Faces Support
JSF T ools does not lock you into any one JavaServer Faces implementation. You can always specify the
desired JavaServer Faces implementation while creating a new JSF project (see Section 3.1, “Creating a
New JSF Project”), adding JSF capability to any existing Eclipse project (see Section 3.3, “Adding JSF
Capability to Any Existing Eclipse Project”), or importing existing JSF projects (see Section 3.2, “Importing
Existing JSF Projects with Any Structure”).
At this point the special wizard will prompt you to specify an appropriate JSF environment. It may be JSF
1.1.02 RI, JSF 1.2 or JSF 2.0. T he wizard also lets you select JSF implementation with a component
orientation such as JSF 1.2 with Facelets or MyFaces 1.1.4.
Figure 2.1. Choosing JSF Environment
After specifying an appropriate JSF environment, all the required libraries associated with the selected
version will be added to your project.
2.1. Facelets Support
In this section we will focus all the concepts that relate to working with Facelets.
Facelets extend JavaServer Faces by providing a lightweight framework that radically simplifies the
design of JSF presentation pages. Facelets can be used in a variety of ways that we will consider further
in this section.
5
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
2.1.1. Facelets templates
If you want to build an application using Facelets, create a project with Facelets based on version 1.2 of
the JSF Reference Implementation, i. e. select the JSF 1.2 with Facelets option in the JSF
Environm ent section of the New JSF Project wizard.
Figure 2.2. Choosing Facelets Environment
Once you have selected the environment, it is possible to specify one of three available templates:
6
Chapter 2. JavaServer Faces Support
Figure 2.3. Choosing Facelets T emplate
T he following table lists the templates that can be used with Facelets for any JSF project, and gives a
detailed description for each one.
T able 2.1. Facelets T emplates
T emplate
Description
FaceletsBlankWithoutLibs
Some servers already provide JSF libs and you risk library
conflicts while deploying your project. T o avoid such
conflicts, use a template without libs if you have a server
with its own JSF libraries.
FaceletsKickStartWithRILibs
A sample application with Facelets that is ready to run.
FaceletsKickStartWithoutLibs
A sample application without libraries.
2.1.2. Facelets components
T he JBoss T ools Palette comes with the Facelets components ready to use. A useful tip appears when
you hover the mouse cursor over the tag; this tip includes a detailed description of the tag component,
the syntax and available attributes.
7
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 2.4 . Facelets Components
2.1.3. Code assist for Facelets
JSF T ools provides Facelets code assistance, which can be accessed by pressing Ctrl+Space. It is
available for Facelets tags while editing .xhtm l files.
Figure 2.5. XHT ML File Code Assist
Code assist is also available for jsfc attributes in any HT ML tag.
8
Chapter 2. JavaServer Faces Support
Figure 2.6. Code Assist for JSFC Attribute
After selecting an jsfc attribute, the code assist feature will list the JSF components available on a
page.
Figure 2.7. Code Assist for JSF Components
When a component is selected you will see all available attributes for it.
9
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 2.8. Available Attributes for the Component
2.1.4. Open On feature
Finally, JSF T ools supports Eclipse's OpenOn feature while editing Facelets files. Using this feature, you
can easily navigate between the Facelets templates and other parts of your projects. By holding down
the Ctrl key while hovering the mouse cursor over a reference to a template, the reference becomes a
hyperlink to navigate to that template.
Figure 2.9. T emplate Hyperlink
10
Chapter 3. Projects
Chapter 3. Projects
T o take an advantage of JSF you will need to perform one of the next steps:
Create new JSF projects
Import (open) existing JSF projects
Add JSF capability to any existing Eclipse project
Import and add JSF capability to any existing project created outside Eclipse.
T his section will go into more detail for each step.
3.1. Creating a New JSF Project
It is easy to create a new project that contains all the JSF libraries, tag libraries and JSF configuration file
with the aid of a special wizard. T o get it, select File → New → Other → JBoos T ools Web → JSF →
JSF Project and click the Next button.
Figure 3.1. Choosing a JSF Project
On the next page you will be prompted to enter the Project Nam e and select a location for the project
(or just leave a default path).
T he JSF Version option also allows you to specify the JSF implementation to use.
11
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 3.2. Creating a New JSF Project
T here are a number of predefined project templates that are both flexible and easily customizable. You
can pick a different template on which the projects Importing Existing should be based on. Almost all
templates come in two variations: with and without JSF libraries.
12
Chapter 3. Projects
Figure 3.3. Choosing JSF T emplates
T he table below provides description for each possible JSF template.
T able 3.1. JSF Project T emplates
T emplate
Description
JSFBlankWithoutLibs
T his template will create a standard Web project structure with all the JSF
capabilities.
Use a template without libs to avoid library conflicts when your server
already has JSF libraries installed.
JSFKickStartWithoutLib
s
T his template will create a standard Web project structure, and also include
a sample application that is ready to run.
Use a template without libs to avoid library conflicts when your server
already has JSF libraries installed.
On the next page you need to select which Servlet version to use, and specify whether or not to
register this application with JBoss AS (or other server) in order to run and test your application.
T he Context Path option defines the name under which the application will be deployed.
13
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
T he Runtim e value tells Eclipse where to find the Web libraries necessary to build (compile) the
project. It is not possible to finish the project creation without selecting a Runtime. If you do not have any
values, click the New... button to add new Runtime.
T he T arget Server option allows you specifying whether or not to deploy the application. T he T arget
Server corresponds to the Runtime value selected above. If you do not want to deploy the application,
uncheck this option.
Figure 3.4 . Registering the Project on Server
When you are all done, you should see that the project has appeared in the Package Explorer view:
14
Chapter 3. Projects
Figure 3.5. A New Project in the Package Explorer
At this point you can open the faces-config.xm l file and start working on your application. T here
are a lot of features available when developing JSF applications. T hese features will be discussed in
more detail later in this document.
3.2. Importing Existing JSF Projects with Any Structure
For detailed information on migration of JSF projects into a workspace see the Migration Guide.
3.3. Adding JSF Capability to Any Existing Eclipse Project
It is also possible to add JSF capabilities (JSF libraries, tag libraries) to any existing Eclipse project in
your workspace. After that you will be able to make use of features such as the JSF configuration editor,
JBoss T ools JSP editor and any others.
Right click the project and select JBoss T ools → Add JSF Capabilities from the context menu. T his
will start the process of adding the necessary libraries and files to convert the project into a Web JSF
project.
15
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 3.6. Adding JSF Capabilities
T he wizard will first ask you to define location of the web.xm l file and the project name.
16
Chapter 3. Projects
Figure 3.7. Project Location
On the last page you can specify the different folders for your project as well as register this application
with a servlet container.
Make sure to select the Add Libraries option to add all required JSF related libraries into your
project.
T he Context Path option defines the name under which the application will be deployed.
T he Runtim e value tells Eclipse where to find Web libraries necessary to build (compile) the project. It
is not possible to finish project import without selecting the Runtime. If you don not have any values, click
the New... button to add a new Runtime.
T he T arget Server option allows you to specify whether or not to deploy the application. T he T arget
Server corresponds to the Runtime value selected above. If you do not want to deploy the application,
uncheck this value.
17
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 3.8. Project Folders
Once your project is imported you can see that JSF related libraries jsf-api.jar and jsfim pl.jar have been added to your project.
Note:
Some application servers provide their own JSF implementation libraries. T o avoid conflicts you
should not add JSF libraries while adding JSF capabilities.
You are now ready to work with JSF by creating a new JSF configuration file:
18
Chapter 3. Projects
Figure 3.9. Creating a New JSF Configuration File
19
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Once the file has been created, it should be opened in a special editor (see Chapter 5, JSF
Configuration File Editor).
3.4. Adding Your Own Project Templates
A template is a set of files that is provided as a basis when creating a new project. Project templates
provide content and structure for a project.
JSF T ools provides powerful template capabilities which allow you to create new templates and import
existing Struts and JSF projects. T his templating facility has a variety of aspects to consider. Let's start
with the most straightforward case and consider the process of creating a template from your existing
JSF project.
Let's say you have a project that you want to use as the basis for a new template. T he following steps
will show you how to achieve this:
In the Web Projects view, right-click the project and select JBoss T ools JS → Save As T emplate
Figure 3.10. Saving Your Project as T emplate
In the first dialog box, you can specify a name for the template (it will default to the project name) and
confirm what run-time implementation of the project technology will be used.
20
Chapter 3. Projects
Figure 3.11. Define T emplate Properties
When you click the Next button a dialog box will be presented with your project structure displayed,
along with a number of check boxes. Here you can select only those parts and files in your project
directory that should be part of the template.
21
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 3.12. Define T emplate Properties
At this point, unless you want to designate some extra files as having Velocity template coding inside
them, you should click the Finish button.
T hat's it. T his template can be used with any new or imported project that uses the same run-time
implementation as the project you turned into a template.
At this point you have a fully configured project. Now you can add some additional logic to it starting with
the JSF configuration file.
3.5. Relevant Resources Links
You can find a more in-depth explanation on how to work with the special wizards, editors and views that
can be used while developing JSF applications in our Visual Web T ools Guide.
22
Chapter 4. Web.xml Editor
Chapter 4. Web.xml Editor
T he web.xm l file inside the WEB-INF folder is a deployment descriptor file for a Web Application. It
describes the servlets and other components and deployment properties that make up your application.
JBoss T ools add the web.xm l file to created JSF project automatically and provides a special editor for
its editing. See the Visual Web T ools guide for more information on the web.xm l editor.
23
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Chapter 5. JSF Configuration File Editor
First, we should mention that JSF configuration file (faces-config.xm l) is intended for registering
JSF application resources such as Converters, Validators, Managed Beans and page-to-page navigation
rules.
Now, let's look at how you can easily configure this file by means of a special graphical editor for the JSF
configuration file. T he editor has three main views:
Diagram
T ree
Source
T hey can be selected via the tabs at the bottom of the editor.
5.1. Diagram view
Here, we will show you how to work with JSF configuration file through the Diagram view of the editor.
As you can see on the figure below, the Diagram view displays the navigation rules container in the
faces-config.xm l file:
24
Chapter 5. JSF Configuration File Editor
Figure 5.1. Diagram View
If you have a large diagram, make use of the Outline view. Within it you can switch to a Diagram
Navigator mode by selecting the middle icon at the top of the view window. T his allows you to easily
move around the diagram. Just move the blue area in any direction, and the diagram on the left will also
move:
Figure 5.2. Outline View for Diagram
25
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
T o create a new page here, you should click the page icon (View T emplate) on the toolbar from the left
and then click anywhere on the diagram. A New Page Wizard will appear.
T o create a transition for connecting pages:
Select the transition icon from the toolbar (New Connection).
Click the source page.
Click the target page.
A transition will appear between the two pages:
Figure 5.3. T ransition between JSP Pages
It is also possible to create a new page with context menu by right-clicking anywhere on the diagram and
selecting the New View... option.
26
Chapter 5. JSF Configuration File Editor
Figure 5.4 . Creating a New View
T o edit an existing transition, first select the transition line. T hen, place the mouse cursor over the last
black dot (on the target page). T he mouse cursor will change to a big +. At this point, drag the line to a
new target page:
27
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 5.5. Editing T ransition between Views
5.2. Tree View
You can find it more convenient to edit your JSF Configuration file in the T ree view of the VPE.
T he view displays all JSF application artifacts referenced in the configuration file in a tree format. By
selecting any node on the left, you can view and edit its properties which will appear in the right-hand
area. Let's look at the structure of this tree more closely.
Under the Application node you can adjust JSF application specific settings such as
internationalization, extensions, adding property and variable resolvers, etc.
28
Chapter 5. JSF Configuration File Editor
Figure 5.6. JSF Application Specific Settings
T he Com ponents node is for registering custom JSF components. Right-click and select New →
Component or just click the Add button in the right-hand area to add a new component to the JSF
Configuration file.
29
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 5.7. Registering a New JSF Component
In the Add Com ponent wizard you should set a component type and point to a component class by
using the Browse button or create a new class for this component by using the Com ponent-Class
link.
30
Chapter 5. JSF Configuration File Editor
Figure 5.8. Adding a New JSF Component to the JSF Configuration File
Use the Render Kit node to create and register a set of related renderers for custom JSF
components.
31
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 5.9. Adding a New JSF Renderer Kit to the JSF Configuration File
Under the Converters node you can create a converter class for your JSF application either with
an id or for a proper class. For more information on this procedure see Section 7.1, “Create and
Register a Custom Converter”.
32
Chapter 5. JSF Configuration File Editor
Figure 5.10. Creating a New Custom Converter
T he Managed Bean node allows you to create and register Bean classes in your JSF application.
Read more on the topic in Chapter 6, Managed Beans.
33
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 5.11. Managed Beans
Use the Navigation Rules node to configure a navigation between the pages in your application.
Here you can create a new navigation rule and adjust necessary properties for it in the right-hand
area.
Tip:
T he same you can do in the Diagram view of the JSF Configuration file editor (see Section 5.1,
“Diagram view”).
34
Chapter 5. JSF Configuration File Editor
Figure 5.12. Configuring Navigation Rules
Under the Referenced Beans node you can add a new Referenced Bean and configure various
properties for it. T o learn more on this refer to Section 7.3, “Create and Register Referenced Beans”.
35
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 5.13. Referenced Beans
T he Validators node is needed to create validator classes for organizing the validation of your
application data. You can read more on the topic in Section 7.2, “Create and Register a Custom
Validator”.
36
Chapter 5. JSF Configuration File Editor
Figure 5.14 . Validators
T he Extensions node is for setting extensions in your faces-config.xm l file.
37
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 5.15. Adding Extensions
In the T ree view you can also edit the properties of the selected element with the help of the
Properties view as shown below:
Figure 5.16. Properties View
5.3. Source View
Here, we'll discuss how you can configure your faces-config.xm l file with the help of the Source
View.
T he Source View for the editor displays the text content of the JSF configuration file. It is always
synchronized with other two views, so any changes made in one of the views will immediately appear in
38
Chapter 5. JSF Configuration File Editor
the other:
Figure 5.17. Source View
You can also work in the Source View with the help of the Outline View. T he Outline view shows
a tree structure of the JSF configuration file. Simply select any element in the Outline View, and it will
jump to the same place in the Source editor, so you can navigate through the source code with Outline
View.
Figure 5.18. Outline View
5.4. Editor Features
Here we'll discuss a very important features that JSF configuration file editor provides when working with
JSF resources.
39
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
5.4.1. Open On
T he JSF configuration file editor comes with the very useful OpenOn navigation feature. You can find
more information on this feature in the Visual Web T ools Guide.
5.4.2. Code Assist
Code Assist provides a pop-up tip to help you complete your code statements. It allows you to write your
code faster and with more accuracy.
Code assist is always available in the Source mode:
Figure 5.19. Code Assist in Source View
5.4.3. Error Reporting
Constant error checking is provided while you are developing your project. T his greatly reduces your
development time as it allows you to catch many errors during the development process.
Errors will be reported by Chapter 8, JSF Project Verification facility:
Figure 5.20. Error Reporting in Source View
40
Chapter 5. JSF Configuration File Editor
Other errors are also reported.
Figure 5.21. Other Errors Reporting
41
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Chapter 6. Managed Beans
JSF T ools provides a number of useful features when working with managed beans, such as:
Adding and generating code for new managed beans
Generating code for attributes and getter/setter methods
Adding existing managed beans to a JSF configuration file
T his guide will look at each of these features in more detail.
6.1. Code Generation for Managed Beans
T o begin, create a new managed bean in JSF configuration file editor using the T ree view.
Figure 6.1. Creation of New Managed Bean
Note:
When you define a new managed bean, make sure that Generate Source Code option is
checked as shown in the figure below.
42
Chapter 6. Managed Beans
Figure 6.2. New Managed Bean
After the Java class has been generated you can open it for additional editing. T here are two ways to
open a Java class:
Click on the Managed-Bean-Class link in the editor.
Right click the managed bean and select the Open Declaration option.
Figure 6.3. Opening of Created Managed Bean
43
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
T he generated Java source should look as follows:
Figure 6.4 . Java Source Code
You can also generate source code for properties, also includes getter and setter methods. Right click
on the bean and select New → Property. You will then see the Add Property dialog.
44
Chapter 6. Managed Beans
Figure 6.5. Generation of Source Code for Properties
When the form is open make sure that all the check boxes are selected:
Add Java property
Generate Getter
Generate Setter
45
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 6.6. "Add Property" Form
Once the generation is complete, you can open the file and see the newly added property with
accompanying "get" and "set" methods:
Figure 6.7. Generated Java Source Code for Property
T his covers the options available when creating a new Managed Bean. T he next section will show you
how to add an existing Bean into a JSF configuration file.
46
Chapter 6. Managed Beans
6.2. Add Existing Java Beans to a JSF Configuration File
If you already have a Java bean you can easily add it to a JSF configuration file.
You should start the same way you create a new managed bean. Use the Browse... button to add
your existing Java class.
Figure 6.8. New Managed Bean Form
Once the class is set, its Nam e will be set as well. But you can easily substitute it for the other one.
Notice that Generate Source Code option is not available as the Java class already exists.
After adding your class the Next button will be activated. When you click it you will be presented with the
Managed Properties dialog where all corresponding properties are displayed. Checking the
appropriate ones will add them into your JSF Configuration File.
47
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 6.9. Selection of Bean's Properties.
If you don't want to add any, just click the Finish button.
T he steps above have demonstrated how you can add an existing Bean to the JSF configuration file, i.e.
faces-config.xm l. T he next chapter will demonstrate how to organize and register other kinds of
artifacts.
48
Chapter 7. Creation and Registration
Chapter 7. Creation and Registration
7.1. Create and Register a Custom Converter
It's also possible to create a custom Converter in order to specify your own converting rules. Let's look
at how you can do this.
T o create and register a custom converter it is necessary perform the following steps:
In the Project Explorer view open the faces-config.xm l file and select T ree tab.
Figure 7.1. Converters
Select Converters and click the Add button.
On the form type the name of your converter in the Converter-id field and name of the class for
converters. After clicking Finish button your custom converter is registered under the entered
name.
49
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 7.2. Add Converter Form
Now you can create a "converter" class. In the Converter section you should see your Converterid and Converter-class. Click on the Converter-Class link to generate the source code.
Figure 7.3. Generation of Source Code for Converter Class
50
Chapter 7. Creation and Registration
A usual wizard for creating a Java class will appear. All needed fields here will be adjusted
automatically. Just leave everything without changes and click the Finish button.
Figure 7.4 . New Java Class Form
T o open a converter class click again on the Converter-Class link in the Converter section.
51
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 7.5. Converter Class
Now you are able to add a business logic of converter in the Java editor.
7.2. Create and Register a Custom Validator
It is also quite easy to develop your own custom Validators. T he required steps are similar to those
shown previously:
In the Project Explorer view open the faces-config.xm l and select the T ree tab.
52
Chapter 7. Creation and Registration
Figure 7.6. Validator in Faces Config Editor
Select the Validators option and click the Addbutton.
T ype the name of your validator in the Validator-id field and name of the class for validators.
After clicking the Finish button your custom validator is registered under the entered name.
53
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 7.7. Adding Validator
Now you can create the "validator" class.
In the Validator section you can see your Validator-id and Validator-class. T o generate the
source code click on Validator-class.
54
Chapter 7. Creation and Registration
Figure 7.8. Creating Validator Class
Java class will be created automatically. Leave everything without changes and click the Finish.
55
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 7.9. New Java Class Form
T o open the validator class click on the Validator-Class link in the Validator section. Now you
are able to write a business logic of validator in the Java editor.
56
Chapter 7. Creation and Registration
Figure 7.10. Converter Class Editing
7.3. Create and Register Referenced Beans
T he creation of Referenced Beans is similar to the creation of Custom Validators. T he steps below show
you the steps required to create Referenced Beans.
In the Project Explorer view open the faces-config.xm l and select the T ree tab.
57
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 7.11. Referenced Beans in Faces Config Editor
Select the Referenced Beans option and click on the Add button.
T ype in the name of your Referenced Bean and type in or select the Referenced-Bean-Class
value by clicking the Browse button.
58
Chapter 7. Creation and Registration
Figure 7.12. Add Referenced Bean
In the Referenced Bean section you should see your Referenced-Bean-Nam e and
Referenced-Bean-Class. Click on the link to open the Java creation wizard.
59
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 7.13. Create Referenced Bean Class
T he Java class will be created automatically. Leave everything with their default values and click the
Finish button.
60
Chapter 7. Creation and Registration
Figure 7.14 . New Java Class Form
T o open a Referenced Bean class click the Referenced-Bean-Class in the Referenced Bean
section. Now you are able to write business logic of Referenced Bean in the Java editor.
61
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 7.15. Referenced Bean Class Editing
62
Chapter 8. JSF Project Verification
Chapter 8. JSF Project Verification
In this chapter we'll discuss a possible verification that you can take advantage of.
Many different rules are checked for a JSF project that can be configured by selecting Window →
Preferences from the menu bar, selecting JBoss T ools → Web → Verification from the Preferences
dialog box and then expanding the JSF Rules node.
Figure 8.1. JSF Rules
Suppose you are working in the Source viewer for a JSF configuration file as shown below:
63
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Figure 8.2. Faces-config.xml File
While typing a class name, you might make a minor typo (like "demo.Person9" instead of "demo.Person"
). After saving the file, verification checks to make sure everything is correct and finds the error below:
Figure 8.3. Error in Source View
Notice that the Package Explorer View shows a marked folder and a marked file where the error is.
You can place the cursor over the line with an error message and get a detailed error message:
64
Chapter 8. JSF Project Verification
Figure 8.4 . Error Message
Verification also checks navigation rules:
Figure 8.5. Checking Navigation Rules
65
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
If you provide a page name that does not exist, verification will let you know about that:
Figure 8.6. Page Name Verification
You can always call up verification explicitly by right-clicking any element in the tree and selecting Verify
from the context menu. T his works from both the T ree and Diagram viewers for the JSF configuration file
editor. You can also invoke verification from the Web Projects view. Below we are checking all of the
elements in the configuration file.
Figure 8.7. Verify Command
In summary, this document highlights all the JSF-specific features of JBoss T ools meant for enhancing
the development of rich Web applications based on JSF technology. T he reference introduces you to
wizards for creating and importing JSF projects, JSF Configuration File editor features, functionality for
66
Chapter 8. JSF Project Verification
enabling JSF capabilities and etc.
If you have questions or good suggestions, please refer to JBoss T ools Forum.
67
Red Hat JBoss D eveloper Studio 4.1 JSF Tools Reference Guide
Getting Help and Giving Feedback
A.1. Do You Need Help?
If you experience difficulty with a procedure described in this documentation, visit the Red Hat Customer
Portal at http://access.redhat.com. T hrough the customer portal, you can:
search or browse through a knowledgebase of technical support articles about Red Hat products.
submit a support case to Red Hat Global Support Services (GSS).
access other product documentation.
Red Hat also hosts a large number of electronic mailing lists for discussion of Red Hat software and
technology. You can find a list of publicly available mailing lists at https://www.redhat.com/mailman/listinfo.
Click on the name of any mailing list to subscribe to that list or to access the list archives.
A.2. Give us Feedback
If you find a typographical error, or know how this guide can be improved, we would love to hear from
you. Submit a report in Bugzilla against the product JBoss Developer Studio and the component
JSF T ools Reference Guide. T he following link will take you to a pre-filled bug report for this
product: http://bugzilla.redhat.com/.
Fill out the following template in Bugzilla's Description field. Be as specific as possible when
describing the issue; this will help ensure that we can fix it quickly.
Document URL:
Section Number and Name:
Describe the issue:
Suggestions for improvement:
Additional information:
Be sure to give us your name so that you can receive full credit for reporting the issue.
68
Revision History
Revision History
Revision 4 .1.2-1.4 06
Rebuild with Publican 4.0.0
T ue Jan 7 2014
Rüdiger Landmann
Revision 4 .1.2-1
T hu Aug 29 2013
Michelle Murray
T OOLSDOC-387: Rebuilt for Customer Portal, content unchanged
Revision 1-1
Screenshot refresh
T ue Mar 15 2011
Matthew Casperson
Revision 1-0
Wed Jun 09 2010
JBoss T ools Documentation
T eam
General updates
Revision 0-0
Fri Nov 20 2009
Initial creation of book by publican
Isaac Rooskov
69
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement