Chapter 2. JSF and Struts Tools

This section provides information on JSF and Struts tooling in JBoss Developer Studio which allows you to develop JSF and Struts applications much faster and with far fewer errors so sparing your time.

2.1. JavaServer Faces Support

JBoss Developer Studio is especially designed for supporting JSF and JSF-related technologies. JBDS provides extensible and exemplary tools for building JSF-based applications as well as adding JSF capabilities to existing web projects, importing JSF projects (created outside JBDS) and choosing any JSF implementation while developing JSF application.

2.1.1. Support for JSF Environments: JSF-RI, MyFaces, Facelets or any Custom

With Developer Studio, we don't lock you into any one JavaServer Faces implementation. Select the one you want to use for your project.

When you:

  • Create a new JSF project

  • Add JSF capability to any existing Eclipse project

  • Add JSF capability to any existing project (created outside JBDS)

You can always select which JSF implementation to use.

You can also create your own custom JSF environments.

Choosing JSF Environment

Figure 2.1. Choosing JSF Environment


JBoss Developer Studio will add all the required libraries for the selected version to your project.

2.1.2. Facelets Support

This section will perform you all concepts that JBDS involves to use the Facelets.

The Facelets extends JavaServer Faces by providing a lightweight framework that radically simplifies the design of presentation pages for JSF. JBoss Developer Studio provides support for Facelets in a variety of ways:

  • The New JSF Project wizard contains templates for creating Facelets projects based on version 1.2 of the JSF Reference Implementation. Select the JSF 1.2 with Facelets in JSF Environment section.

Choosing Facelets Environment

Figure 2.2. Choosing Facelets Environment


Once you select the environment, you can specify the one of three available templates:

Choosing Facelets Template

Figure 2.3. Choosing Facelets Template


The fallowing table lists possible Facelets templates for any JSF project and gives a proper description for each one.

Table 2.1. Facelets Templates

Template

Description

FaceletsBlankWithoutLibs

Some servers already provide jsf libs and you take risk of getting conflicting libraries while deploying your project. To 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


  • The JBoss Tools Palette comes with the Facelets components ready to use. A useful tip appears when you hover the mouse cursor over the tag, the tip includes a detailed description of the tag component, the syntax and available attributes.

Facelets Components

Figure 2.4. Facelets Components


  • Code assist (Ctrl + Space) for Facelets tags is available when editing .xhtml files.

XHTML File Code Assist

Figure 2.5. XHTML File Code Assist


What's more, code assist is also available for "jsfc" attribute in any HTML tag.

Code Assist for Jsfc Attribute

Figure 2.6. Code Assist for Jsfc Attribute


After selecting "jsfc" you get the code assist for JSF components available on a page.

Code Assist for JSF Components

Figure 2.7. Code Assist for JSF Components


When a component is chosen you will see all available attributes for it.

Available Attributes for the Component

Figure 2.8. Available Attributes for the Component


  • JBDS provides Eclipse's OpenOn feature for editing Facelets files. Using this feature, you can easily navigate between the Facelets templates and other parts of your projects. Just by holding down the Control key while hovering the mouse cursor over a reference to a template, the reference becomes a hyperlink to open that template.

Template Hyperlink

Figure 2.9. Template Hyperlink


2.1.2.1. Relevant Resources Links

Necessary information and support for Facelets find out here.

2.1.3. Working with Projects

To take an advantage of JSF support in JBoss Developer Studio firstly you should 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.

In this section we're going to stop on each of them in detail.

2.1.3.1. Creating a New JSF Project

If you want your project has already contained all JSF libraries, tag libraries and JSF configuration file, just organize a new brand JSF project. JBoss Developer Studio allows to do this easily with the help of the special wizard. To get it, select File > New > Project > JBoos Tools Web > JSF > JSF Project and click Next.

Choosing a JSF Project

Figure 2.10. Choosing a JSF Project


On the next form you'll be prompted to enter Project Name and select a location for the project or just leave a default path.

Here, JSF Version also allows you to select which JSF implementation to use.

Creating a New JSF Project

Figure 2.11. Creating a New JSF Project


JBoss Developer Studio comes with a number of predefined project templates that are flexible and easily customizable. Thus you can pick a different template on which the project should be based to. Almost all templates come in two variations: with jsf libraries and without ones.

Choosing JSF Templates

Figure 2.12. Choosing JSF Templates


The table below provides description for each possible JSF template.

Table 2.2. JSF Project Templates

Template

Description

JSFBlankWithLibs

This template will create a standard Web project structure with all JSF capabilities

JSFKickStartWithLibs

This template will create a standard Web project structure but will also include a sample application that is ready to run

JSFKickStartWithoutLibs

Some servers already provide jsf libs and you take risk of getting conflicting libraries while deploying your project. To avoid such conflicts, use a template without libs if you have a server with its own jsf libraries


On the next screen select what Servlet version to use and whether to register this application with JBoss AS (or other server) for running and testing of your application.

The Context Path is the name under which the application will be deployed.

The Runtime value tells Eclipse where to find Web libraries in order to build (compile) the project. It is not possible to finish project creation without selecting Runtime. If you don't have any values, select New... to add new Runtime.

The Target Server allows you specifying whether to deploy the application. The Target Server corresponds to the Runtime value selected above. If you don't want to deploy the application, uncheck this value.

Registering the Project on Server

Figure 2.13. Registering the Project on Server


When you are all done, you should have the project that has been appeared in the Package Explorer view:

A New Project in the Package Explorer

Figure 2.14. A New Project in the Package Explorer


At this point you can open faces-config.xml and start working on your application. JBDS provides a lot of features to develop JSF applications. We will describe the features further.

2.1.3.2. Importing Existing JSF Projects with Any Structure

For detailed information on migration projects to JBoss Developer Studio see Migration Guide.

2.1.3.3. Adding JSF Capability to Any Existing Eclipse Project

With JBoss Developer Studio it's also possible to add JSF capability (JSF libraries, tag libraries) to any existing Eclipse project in your workspace. After that you'll be able to make use of such JBoss Developer Studio editors as JSF configuration editor, JBoss Tools JSP editor and any others.

Right click the project and select JBoss Tools > Add JSF Capabilities. This will start the process of adding all necessary libraries, files to make this a Web JSF project.

Adding JSF Capabilities

Figure 2.15. Adding JSF Capabilities


The wizard will first ask you to show the web.xml file location and the project name.

Project Location

Figure 2.16. Project Location


On the last form you can set the different folders for your project as well as register this application with a servlet container.

Make sure to select Add Libraries for JBoss Developer Studio to add all required JSF related libraries to this project.

The Context Path is the name under which the application will be deployed.

The Runtime value tells Eclipse where to find Web libraries in order to build (compile) the project. It is not possible to finish project import without selecting Runtime. If you don't have any values, select New... to add new Runtime.

The Target Server allows you to specify whether to deploy the application. The Target Server corresponds to the Runtime value selected above. If you don't want to deploy the application, uncheck this value.

Project Folders

Figure 2.17. Project Folders


Once your project is imported you can see that JSF related libraries have been added to your project: jsf-api.jar and jsf-impl.jar .

Note:

Some application servers provide their own jsf implementation libraries. So, to 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:

Creating a New JSF Configuration File

Figure 2.18. Creating a New JSF Configuration File


2.1.3.4. Adding Your Own Project Templates

Template is a set of files that serve as a basis to facilitate the creation of a new project. Project templates provide content and structure for a project.

JBoss Developer Studio has a powerful templating capability for creating new and importing existing Struts and JSF projects. This templating facility has a variety of aspects to consider. But, 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. Follow these steps to make a template out of it:

  • In the Web Projects view, right-click the project and select JBoss Tools JSF > Save As Template as template

Saving Your Project as Template

Figure 2.19. Saving Your Project as Template


  • In the first dialog box, you can choose a name for the template (defaults to the project name) and confirm what run-time implementation of the project's technology will be used

Define Template Properties

Figure 2.20. Define Template Properties


  • Select Next and you will be sent to a dialog box with your project structure displayed with check boxes. Here you can check only those parts and files in your project directory that should be part of the template

Define Template Properties

Figure 2.21. Define Template Properties


  • At this point, unless you want to designate some extra files as having Velocity template coding inside them, you should click Finish .

That's it. Now, you can use this template with any new or imported project that uses the same run-time implementation as the project you turned into a template.

2.1.4. Graphical Editor and Viewing for JSF Configuration Files

JBDS provides a graphical editor for working with JSF configuration file ( faces-config.xml ). The editor has three main viewers (modes):

  • Diagram

  • Tree

  • Source

The modes can be selected via the tabs at the bottom of the editor.

The JSF configuration editor also comes with a very useful OpenOn selection feature. Now let's dwell on each mode and all specific functionality which they provide for work with JSF configuration file.

2.1.4.1. Diagram

The Diagram view displays the navigation rules in the JSF configuration file:

Diagram View

Figure 2.22. Diagram View


2.1.4.2. Creating New View (Page)

To create a new page (view), you can click the page icon on this toolbar and then click anywhere on the diagram. A New Page Wizard will appear.

To create a transition (rule) connecting pages:

  • Select the transition icon from the toolbar (2nd from the bottom).

  • Click the source page.

  • Click the target page.

A transition will appear between the two pages:

Transition Between JSP Pages

Figure 2.23. Transition Between JSP Pages


It is also possible to create a new page with context menu by right-clicking anywhere on the diagram and selecting New View.

Creating a New View

Figure 2.24. Creating a New View


To edit an existing transition, first select the transition line. Then, place the mouse cursor over the last black dot (on the target page). The mouse cursor will change to a big +. At this point, drag the line to a new target page:

Editing Transition Between Views

Figure 2.25. Editing Transition Between Views


2.1.4.3. Tree View

The Tree mode for the editor displays all JSF application artifacts referenced in the configuration file in a tree format. By selecting any node you can see and edit its properties which will appear in the right-hand area. For example, a Managed Bean:

Tree View

Figure 2.26. Tree View


To edit some artifact, right-click any node and select one of the available actions in the context menu. You can also edit in the properties window to the right:

Editing in Tree View

Figure 2.27. Editing in Tree View


The same way you can create a new artifact:

Creating a New Artifact in Tree View

Figure 2.28. Creating a New Artifact in Tree View


2.1.4.4. Source View

The Source mode for the editor displays a text view of the JSF configuration file. All three viewers are always synchronized, so any changes made in one of the viewers will immediately appear in the others:

Source View

Figure 2.29. Source View


2.1.4.5. Code Assist

Code Assist provides 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:

Code Assist in Source View

Figure 2.30. Code Assist in Source View


2.1.4.6. Error Reporting

When you are developing your project, JBoss Developer Studio constantly provides error checking. This greatly reduces your development time as it allows you to catch many of the errors during development.

Errors will be reported by JBoss Developer Studio's verification facility:

Error Reporting in Source View

Figure 2.31. Error Reporting in Source View


Other errors are also reported.

Other Errors Reporting

Figure 2.32. Other Errors Reporting


You can also work in the Source editor with the help of the Outline view. The Outline views show 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.

Outline View

Figure 2.33. Outline View


If your diagram is large, within Outline view you can switch to a Diagram Navigator mode by selecting the middle icon at the top of the view window. It 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:

Outline View for Diagram

Figure 2.34. Outline View for Diagram


You can also edit the properties of the selected element in the Tree mode with the help of the Properties view as shown below:

Properties View

Figure 2.35. Properties View


2.1.5. Managed Beans

JBoss Developer Studio gives you lots of power to work with managed beans.

  • Add and generate code for new managed beans

    • Generate code for attributes and getter/setter methods

  • Add existing managed beans to JSF configuration file

2.1.5.1. Code Generation for Managed Beans

To start, create a new managed bean in JSF configuration file editor, in the Tree view.

Creation of New Managed Bean

Figure 2.36. Creation of New Managed Bean


Note:

When you define a new managed bean, make sure that Generate Source Code is checked as shown in the figure below.

New Managed Bean

Figure 2.37. New Managed Bean


After the "Java" class has been generated you can open it for additional editing. There are two ways to open the "Java" class:

  • click on Managed-Bean-Class link in the editor

or

  • right click the managed bean and select Open Source

Opening of Created Managed Bean

Figure 2.38. Opening of Created Managed Bean


The generated Java source:

Java Source Code

Figure 2.39. 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 see Add Property dialog.

Generation of Source Code for Properties

Figure 2.40. 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

"Add Property" Form

Figure 2.41. "Add Property" Form


Once the generation is complete, you can open the file and see the added property with "getter" and "setter" methods:

Generated Java Source Code for Property

Figure 2.42. Generated Java Source Code for Property


Thus, we've discussed everything which comes to creating a new Managed Bean. Further we will show you how to add an existing Bean into a JSF configuration file.

2.1.5.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.

New Managed Bean Form

Figure 2.43. New Managed Bean Form


Once the class is set, it's Name 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 Next button will be activated. Pressing it you'll get Managed Properties dialog where all corresponding properties are displayed. Check the necessary ones to add them into your JSF Configuration File.

Selection of Bean's Properties.

Figure 2.44. Selection of Bean's Properties.


If you don't want to add any, just click Finish.

Above-listed steps have demonstrated specifying an existing Bean in the JSF configuration file, i.e. faces-config.xml. In the next section you'll know how to organize and register a custom Converter to specify your own converting rules.

2.1.6. Create and Register a Custom Converter

To create and register a custom converter it's necessary to go through the following steps:

  • In the Project Explorer view open faces-config.xml and select Tree tab.

Converters

Figure 2.45. Converters


  • Select Converters and click on 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.

Add Converter Form

Figure 2.46. Add Converter Form


  • Now you can create "converter" class. In the Converter section you should see your Converter-id and Converter-class. Click on Converter-class to generate the source code.

Generation of Source Code for Converter Class

Figure 2.47. Generation of Source Code for Converter Class


  • 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 Finish.

New Java Class Form

Figure 2.48. New Java Class Form


  • To open a converter class click again on Converter-class link in the Converter section. Now you are able to add a business logic of converter in the Java editor.

Converter Class

Figure 2.49. Converter Class


2.1.7. Create and Register a Custom Validator

With the help of JBDS it's also quite easy to develop your own custom Validators. You should perform the actions similar to previous. Go through the following steps:

  • In the Project Explorer view open faces-config.xml and select Tree tab.

Validator in Faces Config Editor

Figure 2.50. Validator in Faces Config Editor


  • Select Validators and click on Add button.

  • Type the name of your validator in the Validator-id field and name of the class for validators. After clicking Finish button your custom validator is registered under the entered name.

Adding Validator

Figure 2.51. Adding Validator


Now you can create the "validator" class.

  • In the Validator section you can see your Validator-id and Validator-class . To generate the source code click on Validator-class.

Creating Validator Class

Figure 2.52. Creating Validator Class


  • Java class will be created automatically. Leave everything without changes and click Finish.

New Java Class Form

Figure 2.53. New Java Class Form


  • To open validator class click again on Validator-Class link in the Validator section. Now you are able to write a business logic of validator in the Java editor.

Converter Class Editing

Figure 2.54. Converter Class Editing


2.1.8. Create and Register Referenced Beans

Creation of Referenced Beans is similar to creation of Custom Validator.

  • In the Project Explorer view open faces-config.xml and select Tree tab.

Referenced Beans in Faces Config Editor

Figure 2.55. Referenced Beans in Faces Config Editor


  • Select Referenced Beans and click on Add button.

  • Type in the name of your Referenced Bean and type in or select Referenced-Bean-Class by using Browse button.

Add Referenced Bean

Figure 2.56. Add Referenced Bean


  • In the Referenced Bean section you should see your Referenced-Bean-Name and Referenced-Bean-Class. Click on the link to open the Java creation wizard.

Create Referenced Bean Class

Figure 2.57. Create Referenced Bean Class


  • Java class will be created automatically. Leave everything without changes and click Finish.

New Java Class Form

Figure 2.58. New Java Class Form


  • To open Referenced Bean class click again on Referenced-Bean-Class in the Referenced Bean section. Now you are able to write business logic of Referenced Bean in the Java editor.

Referenced Bean Class Editing

Figure 2.59. Referenced Bean Class Editing


2.1.9. Relevant Resources Links

If you don't familiar with JSF technology, we suggest that you walk through the information on the topic.

2.2. Struts support

If you prefer develop web applications using Struts technology JBoss Developer Studio also meets your needs.

JBDS supports the Struts 1.1, 1.2.x versions.

2.2.1. Working with Projects

JBoss Developer Studio provides the following functionality when working with Struts:

  • Create new Struts projects

  • Import (open) existing Struts projects. You can import any project structure

  • Add Struts capabilities to any existing Eclipse project

  • Import and add Struts capabilities to any existing project created outside Eclipse.

2.2.1.1. Creating a New Struts Project

JBoss Developer Studio includes a New Struts Project Wizard that radically simplifies the process for getting started with a new Struts project. You just need to follow these steps:

  • Select File > New > Project... from the menu bar. Then, select JBoss Tools Web > Struts > Struts Project in this dialog box. Click Next:

Selecting Struts Wizard

Figure 2.60. Selecting Struts Wizard


  • On this form, provide the Project Name. You can also select where to create the project or use the default path.

    Next to Struts Environment set which Struts version to use.

Creating Struts Project

Figure 2.61. Creating Struts Project


Tip:

Don't put spaces in project names since some OS could experience problems with their processing and searching these files.

You can select the KickStart template, then the project created will include a simple Hello World type application that is ready to run.

Choosing Struts Template

Figure 2.62. Choosing Struts Template


  • Next, you register this application with the current servlet container defined for your workspace (JBoss AS, by default) in order to allow you to test your application more easily while still developing it. A new entry will be added in the servlet container configuration file to enable running the application in-place (called null deployment or link deployment). Uncheck the "Target Server" check box if for some reason you don't want to register your application at this point.

Registering The Project at Server

Figure 2.63. Registering The Project at Server


  • On the next form, you can select the TLD files to include in this project:

Selecting Tag Libraries

Figure 2.64. Selecting Tag Libraries


After the project is created, you should have the following project structure (if you used the KickStart template):

Project Structure

Figure 2.65. Project Structure


Tip:

If you want to hide the jar files from Web App Libraries in view, select the down-pointing arrow in the upper right corner, select Filters..., check the box next to Name filter patterns (matching names will be hidden), and type *.jar into the field. Then, click OK.

2.2.1.2. Importing an Existing Struts Project with Any Structure

For detailed information on migration projects to JBoss Developer Studio see Migration Guide.

2.2.1.3. Adding Struts Capability to an Existing Web Application

With JBoss Developer Studio you can add Struts capabilities (including Struts libraries, tag libraries and a Struts configuration file) to any existing Web application project in your Eclipse workspace. By adding a Struts Nature to your project, you can now edit files using JBoss Developer Studio editors, such as the Struts configuration editor and the JBoss Tools JSP editor.

To add Struts Nature to your existing Project right-click the project and select JBoss Tools > Add Struts Capabilities from the context menu. This will start the process of adding all necessary libraries and files to make this a Web Struts project.

Adding Struts Capabilities

Figure 2.66. Adding Struts Capabilities


In the wizard you should point to location of your deployment descriptor file web.xml and name of the project.

Choosing Project Location

Figure 2.67. Choosing Project Location


After hitting Next, you will see the following screen. This screen simply means that you need to add at least one Struts module to your project to make this project a Struts project. Adding a Struts module means that a new struts-config.xml will be added to your project and registered in the web.xml file. In addition, all required Struts libraries will be added. To add a Struts module, select the Add Struts Support button.

Project Modules

Figure 2.68. Project Modules


Here you can select what Struts Version, Servlet Class, URL Pattern and TLDs to add to this project.

Selecting Struts Support Options

Figure 2.69. Selecting Struts Support Options


When done, you will see the default Struts module configuration information. See how to Edit Struts modules.

Project Configuration Information

Figure 2.70. Project Configuration Information


On the last screen you can set the different folders for your project as well as register this application with a servlet container. If you want the libraries (.jar files) will be automatically added to your project, click on the checkbox Add Libraries.

Registering the Project at Server

Figure 2.71. Registering the Project at Server


When done, you can open end edit the struts-config.xml file using usefull Struts configuration file editor provided by JBDS. (The Struts configuration is shown below in the Tree viewer).

Struts-config.xml File

Figure 2.72. Struts-config.xml File


2.2.2. Graphical Editor for Struts Configuration Files

The Struts configuration file editor has three modes with different representation of struts-config.xml: Diagram, Tree and Source. The modes can be selected via the tabs at the bottom of the editor. Any changes made in one mode are immediately visible when you switch to any other mode.

When working in Source view, you always have all the following features available:

  • Content Assist

  • Open On Selection

  • File Folding

2.2.2.1. Diagram Mode

The Diagram mode graphically displays the Web flow of the application defined in the Struts configuration file.

Diagram Mode

Figure 2.73. Diagram Mode


The Diagram mode allows to edit navigation in your Struts application. Just by right-clicking anywhere on the diagram, you can use a context menu to create the building blocks of a Struts application:

  • Actions

  • Global forwards

  • Global exceptions

  • JSP Pages

Diagram Context Menu

Figure 2.74. Diagram Context Menu


Along the upper-left side of the editor is a stack of seven icons for changing the behavior of the cursor in the diagram.

Editor Icons

Figure 2.75. Editor Icons


The first icon switches to the default regular selection cursor, the second to the marquee selection cursor and the third to the new connection cursor. The last four icons switch the cursor to an insert cursor for each type of Struts build block listed above (and in the order listed).

For instance, clicking on the first of these four icons (the one with the gears) will switch the cursor to insert actions. Clicking anywhere in the diagram with this cursor has the same effect as right-click and selecting Add > Action... from the context menu with the regular cursor active. It's just more efficient to use this cursor if you're adding more than one action at once.

2.2.2.2. Tree Mode

The Tree mode represents the different elements of the Struts application that are organized into functional categories on the left-hand side and a form for editing the properties of currently selected items on the right-hand side.

Tree Mode

Figure 2.76. Tree Mode


You can also right-click on any node in the category tree and perform appropriate operations through a context menu. For instance, by right-clicking on the action-mappings category node, you can add new actions to the application.

Tree Context Menu

Figure 2.77. Tree Context Menu


2.2.2.3. Source Mode

In the Source mode, you have complete editing control of the underlying XML coding.

Source Mode

Figure 2.78. Source Mode


You can take advantage of code assist.

Code Assist

Figure 2.79. Code Assist


The editor will also immediately flag any errors.

Errors in Source Mode

Figure 2.80. Errors in Source Mode


Finally, you can use the Outline view with the editor to easily navigate through the file.

Outline View

Figure 2.81. Outline View


Find more information about editor features here.

2.2.3. Graphical Editor for Tiles Files

The Tiles configuration file editor has three main modes: Tree, Diagram and Source. The modes can be selected via the tabs at the bottom of the editor. Any changes made in one mode are immediately visible when you switch to any other mode.

When working in Source view, you always have all following features available:

  • Content Assist

  • Open On Selection

2.2.3.1. Create New Tiles File

To create new Tiles files, right click any folder and select New > Tiles File.

Creating a New Tiles File

Figure 2.82. Creating a New Tiles File


2.2.3.2. Tree Mode

The Tree mode represents the different elements of the Tiles file that are organized into functional categories on the left-hand side and a form for editing the properties of currently selected items on the right-hand side.

Tree Mode

Figure 2.83. Tree Mode


To edit the file, simply right click any node and select among the available actions.

Editing in Tiles Editor

Figure 2.84. Editing in Tiles Editor


2.2.3.3. Diagram Mode

The Diagram mode allows you to create complex Tiles files in the form of a diagram.

Diagram Mode

Figure 2.85. Diagram Mode


To create new definitions, simply right click anywhere in the diagram.

Creating New Definition

Figure 2.86. Creating New Definition


You can also use the Diagram toolbar to make editing easier.

Diagram Toolbar

Figure 2.87. Diagram Toolbar


It contains four icons for changing the cursor state. The first one is the default cursor state for selecting existing nodes. The second icon is marquee selector. The third is used for creating new connections and the last one is for adding definition template to the content.

2.2.3.4. Source

The other mode of the Tiles editor is the Source mode that gives you full control over the source. Any changes here will immediately appear in other modes when you switch to them.

Source Mode

Figure 2.88. Source Mode


Code assist is available in the Source mode.

Code Assist

Figure 2.89. Code Assist


Any errors are immediately reported as shown below:

Errors Reporting

Figure 2.90. Errors Reporting


You can also use the Outline view together with the editor's Source mode. It provides an easier navigation through the file.

Outline View

Figure 2.91. Outline View


2.2.4. Graphical Editor for Struts Validation Files

Providing full support for development Struts applications JBoss Developer Studio comes with a visual validation editor. To create a new validation file, right click any folder in Project Explorer and select File > New > Other... from the context menu and then JBoss Tools Web > Struts > Validation File.

Creating New Validation File

Figure 2.92. Creating New Validation File


The validation editor works with five modes: Formsets, Validators, Constants and standard Tree and Source that you can easily switch over using tabs at the bottom of the editor.

The Formsets mode shows forms and their elements on the left side and the dialogue for defining their validation rules on the right side.

Formsets Mode

Figure 2.93. Formsets Mode


The Constants mode let you set constant values for your validation rules.

Constansts Mode

Figure 2.94. Constansts Mode


The validation file can also be viewed in a Tree mode.

Tree Mode

Figure 2.95. Tree Mode


At any point you have full control over the source by switching to the Source mode. Any editing in this mode will immediately be available in other modes of the editor.

Source Mode

Figure 2.96. Source Mode


You can also open your own custom or Struts-standard validation-rules.xml file.

The Validators mode shows the validation rules for a selected validator. You can of course add your own rules.

Validators Mode

Figure 2.97. Validators Mode


Here are the validation rules shown in the Source mode.

Validation Rules

Figure 2.98. Validation Rules


2.2.5. Support for Multiple Struts Modules

JBoss Developer Studio supports working with Struts projects that have multiple modules. You can easily do the following:

  • Add new modules

  • Edit modules for an existing project or during Struts project import

2.2.5.1. When Importing a Struts Project

During Struts project import, if the project has multiple modules, you will see a screen with all existing modules. You can select each module and edit its details.

Configuring Project Modules

Figure 2.99. Configuring Project Modules


2.2.5.2. Editing Modules in an Existing Project

To edit modules in an existing project, right click the project and select JBoss Tools > Modules Configuration.

Choosing Modules Configuration

Figure 2.100. Choosing Modules Configuration


You will see the same screen as above where you will be able to select a module and edit its details.

Modules Configuration

Figure 2.101. Modules Configuration


2.2.5.3. Adding New Modules

Adding a new module is very simple. First switch to Web Project view. Expand your project to the Configuration folder. Under that folder you should see the current modules. Right click on Configuration and select New > Struts Config.

Adding New Modules

Figure 2.102. Adding New Modules


You will see the screen below. You can specify a new module name and also add the new Struts configuration file to web.xml file.

Adding New Modules

Figure 2.103. Adding New Modules


2.2.6. Code Generation for Action, FormBean, Forward and Exception Classes

JBoss Developer Studio comes with a code generation feature. You can generate stub code for Struts Actions, FormBeans, Forwards and Exceptions.

The code generation in JBoss Developer Studio is based on Velocity templates which can be modified for your use. The templates are located at {RedHatDeveloperStudioHome} > templates > codegeneration.

There are a number of ways to invoke code generation. One is simply right-clicking the Struts diagram and selecting Generate Java Code....

Selecting Generate Java Code

Figure 2.104. Selecting Generate Java Code


On this screen you can select for which elements to generate code. If you select Next you will be able to specify more options for each of the categories you selected.

Generate - Step 1

Figure 2.105. Generate - Step 1


Tip:

please be careful not to override your existing files.

When generation is complete, a result window will appear letting you know how many classes were generated:

Generation Finished

Figure 2.106. Generation Finished


You don't always have to generate code for all elements at once. You can invoke generation for just an individual Struts artifact as well. Right-click an element on the diagram of the Struts configuration file and select Generate Java Code... from the context menu.

Generation For Individual Struts Artifact

Figure 2.107. Generation For Individual Struts Artifact


The same can be done from within the Tree viewer for the editor of the Struts configuration file.

Generation in Struts Config Editor

Figure 2.108. Generation in Struts Config Editor


2.2.7. Struts Configuration File Debugger

JBoss Developer Studio comes with Struts configuration file debugger. It allows you to set break points on Struts diagram and then simply launch the server in debug mode.

Simply right click an Action or a page and select Add Breakpoint.

Adding Breakpoint

Figure 2.109. Adding Breakpoint


2.2.8. Customizable Page Links Recognizer

Custom page links allow you to define custom Struts page links that will be recognizable in the Struts application diagram. You can define these links by selecting Window > Preferences from the menu bar and then selecting JBoss Tools > Web > Struts > Customization from the Preferences dialog box.

Customization Panel

Figure 2.110. Customization Panel


2.2.9. Relevant Resources Links

Find out necessary information on Struts technology if you don't know enough.

2.3. Verification and Validation

As you are developing your project, JBoss Developer Studio Verification constantly provides dynamic validation, consistency checking and error checking. This greatly reduces your development time as it allows you to catch many of the errors during development. JBoss Developer Studio provides dynamic verification for both JSF and Struts projects.

2.3.1. JSF Project Verification

JBoss Developer Studio checks for many different rules for a JSF project that can be configured by selecting Window > Preferences from the menu bar, selecting JBoss Tools > Web > Verification from the Preferences dialog box and then expanding the JSF Rules node.

JSF Rules

Figure 2.111. JSF Rules


Suppose you are working in the Source viewer for a JSF configuration file as shown below:

Faces-config.xml File

Figure 2.112. Faces-config.xml File


While typing a class name, you might make a minor typo (like "jsfHello.PersonBean9" instead of "jsfHello.PersonBean" ). After saving the file, verification checks to make sure everything is correct and finds the error below:

Error in Source View

Figure 2.113. 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:

Error Message

Figure 2.114. Error Message


Verification also checks navigation rules:

Checking Navigation Rules

Figure 2.115. Checking Navigation Rules


If you provide a page name that does not exist, verification will let you know about that:

Page Name Verification

Figure 2.116. 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. This works from both the Tree 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.

Verify Command

Figure 2.117. Verify Command


2.3.2. Struts Project Verification

JBoss Developer Studio provides the same functionality for Struts projects. To configure Struts project verification select Window > Preferences from the menu bar, select JBoss Tools > Web > Verification from the Preferences dialog box and then expand the Struts Rules node.

Struts Rules

Figure 2.118. Struts Rules


Suppose you are working in the Source viewer for a Struts configuration file as shown below:

Struts Configuration File

Figure 2.119. Struts Configuration File


While typing a class name or entering it from the graphical editor, you might make a minor typo (like "sample.GreetingAction1" instead of "sample.GreetingAction" ). After saving the file, verification checks to make sure everything is correct and finds the error below:

Error Reporting

Figure 2.120. Error Reporting


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 the error to view a detailed error message:

Error Message

Figure 2.121. Error Message


The verification also checks to make sure you have specified the correct JSP page for the forward:

JSP Page Verification

Figure 2.122. JSP Page Verification


Once you place the cursor over the line, you can see the error message:

Error Message

Figure 2.123. Error Message


You can always invoke the verification by switching to the Diagram viewer, right-clicking and selecting Verify from the context menu:

Verify Command

Figure 2.124. Verify Command