Chapter 5. Adding Custom Capability, Features and Templates

5.1. Creating and Using With Library Sets

5.1.1. What is a library set?

A library set is just a collection of any Jar files. You can create as many library sets as you need. Library sets are used to create Custom Capabilities and new JSF or Struts environments.

A Custom Capability is just a collection of one or more Library Sets. When you add a Custom Capability to your project, the Jar files from Library Sets included in this Capability will be copied to project lib folder.

A new JSF or Struts environment is also just a collection of one or more Library Sets. When you create a new project based on this environment, all Jar files form Library Sets included in this environment will be copied to project lib folder. This also works during project import.

To create a new library set (or edit an existing), select Window/Preferences/Red Hat/Library Sets.

The top window shows all existing library sets. The lower window shows what Jar files are included in for a selected library set.

Library Sets

Figure 5.1. Library Sets

To add a new library set, click Add for the top window.

To add new Jar files (libraries) to a library set, first select a library set and click Add for the lower window. Browse to the location of the Jar file you want to add. The file can be anywhere on your machine and will be copied to your Eclipse workspace. If you upgrade to a new Red Hat Developer Studio version, you will not lose your library sets.

5.2. Creating and Working With Custom Capability

What is a custom capability? A custom capability is just a collection of Jars (libraries) that add some capability to a project. When you add a custom capability to a project, the Jar files will be added to project WEB-INF/lib directory.

A custom capability consists of one or more library sets. See how to create library sets.

Steps to create a new capability:

  1. Open Window/Preferences/Red Hat/Custom Capabilities.

Custom Capabilities Window

Figure 5.2. Custom Capabilities Window

In the upper window you will see existing capabilities. In the lower window, under Library Sets tab you will see the library sets of which this capability consists. A capability can consist of any number of libraries.

The Configuration File Additions lets you add configuration information that is related to this capability.

  1. Click Add in the upper window and enter capability name. The capability will now appear in the list.

  2. Select the capability just created and click Add in the lower window.

  3. Select library set to add to this capability. Repeat the process to add as many library sets as you need.

To add capability to a project:

  • From Package Explorer: right click a project and select Red Hat Developer Studio/Add Custom Capability... or

  • From Web Projects: right click the project and select Red Hat Developer Studio/Add Custom Capability....

  1. Use check boxes to select Custom Capabilities

  2. Click on Finish button.

Select Custom Capabilities

Figure 5.3. Select Custom Capabilities

  1. The following updates have been made to the project.

Added Custom Capabilities

Figure 5.4. Added Custom Capabilities

When you add a custom capability it is possible to modify application configuration files with parameters related to the added capability.

Configuration File Addition

Figure 5.5. Configuration File Addition

  1. Select Configuration File Additions tab. You will see an existing list of configuration file additions.

  2. Click Add or Edit and enter or edit the following values:

    • Label - the name of configuration value

    • File Name - to which file to add this configuration

    • X-Path

    • Text - the text to add to the configuration file

When you add a capability and have defined configuration files additions values, these values will be added to the configuration files.

5.3. How To Add Any Custom Capability Including Oracle ADF, any custom component library or any custom support

5.4. Create Custom Page Templates

5.4.1. Creating Custom JSP Templates

When creating a new JSP page, you can base the new page on a pre-existing template instead of a blank page. The template can contain common header/footer information for the page or really anything you want.

Separate sets of JSP page templates are associated with the different types of project you work on. The types of projects are:

  • JSF

  • Struts

5.4.2. Saving JSP Page as a Template

Switch to WebProjects view and right click any JSP page. Select Save as Template....

Adding Page Template

Figure 5.6. Adding Page Template

Click Ok to create a template based on this page.

5.4.3. Using Preference Settings to Create a Template

Creating your own template based on a page that you have created within one of your projects in your Eclipse workspace is pretty easy.

  1. Open the Preferences panel by selecting Windows/Preferences from the menu bar.

  2. Navigate to the Red Hat/JSF/JSF Pages or Red Hat/Struts/Struts Pages section.

  3. Click on the Add button to the right of the template list.

  4. In the dialog box that appears, type in a name for the template and then use the Browse... button to select the location of the page you want to make into a template.

The location should be located within a project. (Once this is done it doesn't matter if you delete the original JSP page or the project containing it.)

Editing Page Path

Figure 5.7. Editing Page Path

5.4.4. Creating a JSP Page with a Template

5.4.4.1. JSF

  1. In the Project Explorer view select the folder where you want to create JSP file.

  2. Right click > New > JSP File (or in the Web Projects view, right click the project folder > New > File > JSP File)

  3. Expand Template field and select the template.

File JSP

Figure 5.8. File JSP

5.4.4.1.1. JSFBasePage
JSFBasePage

Figure 5.9. JSFBasePage

5.4.4.1.2. JSPRedirect
JSPRedirect

Figure 5.10. JSPRedirect

5.4.4.1.3. Struts
5.4.4.1.3.1. StrutsForm
StrutsForm

Figure 5.11. StrutsForm

5.5. Using the File System to Create a Template

Alternatively, you can create the template outside of Eclipse. Just open this folder:

<redhat>\eclipse\plugins\org.jboss.tools.common.projecttemplates_X.X.X\templates

Create a text file with the coding you want for the template. Name the file exactly as you want the template name to appear. Then, place the file inside the appropriate folder for the project type (jsf or struts). Or, place the file at the same level as the Blank file for the template to be available to either project type.

After you restart Eclipse, your template will be available.

5.6. Adding Your Own Project Templates

Red Hat 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.

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:

  1. In the Project Explorer, right-click the project and select Red Hat Developer Studio/Save as Template.

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

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

  4. At this point, unless you want to designate some extra files as having Velocity template coding inside them, you should select 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.

5.7. Adding a Custom Project Environment

Any environment simply consists of a collection of Jar files. You can create any number of custom environments which consists of any number of Jar files.

Here is how you can do it for JSF.

  1. Select Window/Preferences/Red Hat/JSF/JSF Environment. You will see all existing environments for creating JSF projects.

  2. Click Add to add a new environment.

JSF Environment

Figure 5.12. JSF Environment

  1. When you click Add, enter the following information:

    • Name - enter the name of the new environment

    • Template Location - leave the default value. This environment will be saved under your workspace. If you upgrade Red Hat Developer Studio plug-in, you will keep all custom settings

    • Core Library - Select one core library (See Library Sets for more information)

Adding JSF Project Version

Figure 5.13. Adding JSF Project Version

  1. Once you have that in place, just add as many library sets to this project as you need. When you create a project based on this environment, all Jar files from the library sets will be copied to project WEB-INF\lib directory.

Adding Library Reference

Figure 5.14. Adding Library Reference

  1. Switch to Project Templates tab and click Add. Before you can use the new environment, you need to add at least one project template to it. You can use any existing project as a template or create a new one.

Defining Common Template Properties

Figure 5.15. Defining Common Template Properties

  1. You can click Next to configure the template further or just Finish. In this step, you can select what directories to include in the template

Selecting Folders and Files

Figure 5.16. Selecting Folders and Files

  1. Go back to create a new JSF project. When you select the new environment, you will also be able to select the template.

Selecting New Enviroment

Figure 5.17. Selecting New Enviroment