JBoss.orgCommunity Documentation

Getting Started Guide

Version: 3.2.1.GA


1. Installation Instructions
1.1. Installing JBoss Tools Plugins
1.2. Usage Reporting
1.2.1. Collected usage information guide
2. Manage JBoss AS with JBoss Tools
2.1. How to Manage JBoss AS with JBoss Tools
2.1.1. Starting JBoss Server
2.1.2. Stopping JBoss Server
2.1.3. Server Container Preferences
2.2. How to Use Your Own JBoss AS Instance with JBoss Developer Studio
2.2.1. JBoss AS Installation
2.2.2. Adding and Configuring JBoss Server
3. Write Your First Project with JBoss Developer Studio
3.1. Create a Seam Application
3.1.1. Start Development Database
3.1.2. Create and deploy Seam Web Project
3.1.3. Start JBoss Application Server
3.1.4. Workshop Project Code Overview
3.2. Seam Action Development
3.2.1. Create a New Seam Action
3.2.2. Test Seam Action
3.2.3. Modify Seam Action User Interface
3.3. Declarative Security
3.3.1. Edit Login Authentication Logic
3.3.2. Secure Seam Page Component
3.4. Browsing Workshop Database
3.4.1. Database Connectivity Setup
3.4.2. Browse Workshop Database
3.5. Database Programming
3.5.1. Reverse Engineer CRUD from a Running Database
3.5.2. Use Hibernate Tools to Query Data via JPA
3.5.3. Use Hibernate Tools to visualize the Data Model
3.6. Rich Components
3.6.1. Add a Richfaces component to the CRUD Application
4. Developing a simple JSP web application
4.1. Setting Up the Project
4.2. Creating JSP Page
4.2.1. Editing a JSP Page
4.2.2. web.xml file
4.2.3. Deploying the project
4.2.4. JSP Page Preview
4.2.5. Launch JSP Project
5. RAD development of a simple JSF application
5.1. Setting up the project
5.2. Creating JSP Pages
5.3. Creating Transition between two views
5.4. Creating Resource File
5.5. Creating Java Bean
5.6. Editing faces-config.xml File
5.7. Editing the JSP View Files
5.7.1. Editing inputnumber.jsp page
5.7.2. Editing success.jsp page
5.8. Creating index.jsp page
5.9. Running the Application
6. Project Examples
6.1. User Sites
6.2. Downloading a Project Example
6.3. Quick Fixes
7. FAQ
7.1. What should I do if the Visual Page Editor does not start under Linux
7.2. Visual Editor starts OK, but the Missing Natures dialog appears
7.3. Do I need to have JBoss Server installed to run JBoss Developer Studio?
7.4. I have an existing Seam 1.2.1 project. Can I migrate or import the project into a JBoss Developer Studio Seam project?
7.5. I have an existing Struts or JSF project. Can I open the project in JBoss Developer Studio?
7.6. Can I import a WAR file?
7.7. Is it possible to increase the performance of Eclipse after installing your product?
7.8. How can I add my own tag library to the JBoss Tools Palette?
7.9. How to get Code Assist for Seam specific resources in an externally generated project?
7.10. How to import an example Seam project from jboss-eap directory?
7.11. Is a cross-platform project import possible for JBoss Developer Studio?
8. Further Reading

The JBoss Tools plugins can be installed in Eclipse from the JBoss.org update site. JBoss Tools 3.2 requires Eclipse 3.6, which can be downloaded from the Eclipse web site.

To install the JBoss Tools plugins start Eclipse and select HelpInstall New Software...


Click the Add... button.


This will display the Add Repository dialog. Enter JBoss.org Tools in the Name field, and http://download.jboss.org/jbosstools/updates/JBossTools-3.2.0.GA/ in the Location field. Click the OK button to save the changes and close the dialog.


The JBoss.org Tools site will be selected in the Work with drop down list, and after a moment the list of plugins that are included in the JBoss Tools package will be listed. From this list you can individually select the desired plugin, or select the All JBoss Tools 3.2.0 option to install all the plugins.


Click the Next button to calculate the system requirements and dependencies (this may take a little while). You will then be given an opportunity to review the plugins that will be installed.


Click the Next button to install the selected plugins. You will be prompted to accept the various license agreements that cover the plugins that are to be installed. Review the licenses, select the I accept the terms of the license agreements option, and click the Finish button to install the plugins.


Wait while the plugins are downloaded and installed.


You may be prompted with a warning informing you that you are attempting to install unsigned content. Click the OK button to continue.


You will then have to restart Eclipse to apply the new plugins. Click the Restart Now button to restart Eclipse.


The plugin is now installed and ready to use.

JBoss Tools now includes a usage plug-in that anonymously reports information back to JBoss. The plug-in is not enabled by default. To enable, click the Yes button.


Once enabled, the plug-in will remain active until turned off. To turn the active plug-in off, navigate to WindowPreferencesJBoss ToolsUsage Reporting.

The gathered data allows JBoss to see how the tools are being used and where they are being used geographically. Currently we are looking into the operating systems being used, screen resolution and how often the tooling environment is started. In the future geographic information will assist in focusing translation resources to areas where the developer environment is most used.

The plug-in uses Google Analytics to track and report data by acting as if you were visiting the site http://jboss.org/tools/usage/. To view the type of information being collected, refer to Section 1.2.1, “Collected usage information guide”.

To view the source code of the usage plug-in visit http://anonsvn.jboss.org/repos/jbosstools/trunk/usage/.

Below you will find an outline of the information that is reported and the Goolge Analytics fields that are used to gather this information.

Version

The Content field has been modified to report the installed JBoss Developer Studio version. Sample returned values include: jbdevstudio-linux-gtk-x86_64-4.0.0.v201009301221R-H20-Beta1.jar and jbdevstudio-linux-gtk-3.0.2.v201009161622R-H138-GA.jar.

Installed components

The Keyword field has been modified to report the installed JBoss Developer Studio components. Sample returned values include: JBoss AS, Drools, Teiid and ModeShape.

Visitor type

The Visitor type field reports if the current user is new or returning.

Language

The Language field reports the localized language the product is being used in. Sample returned values include: en-US, de-DE and fr-FR.

Location fields

The location fields report the geographical location where the product is being used based on the continent, country and city. Sample returned values include: Europe (continent), Germany (country) and Munich (city).

Eclipse interface and version

The Browser field has been modified to report the Eclipse interface and version being used. Sample returned values include: JBoss Developer Studio: 3.0.0 and JBoss Developer Studio: 3.0.1.

Operating System

The Operating System field reports the Operating System and its version that the product is running on (with Linux distribution version reporting conducted through the User Defined Value field). Sample returned values include: Linux, Macintosh 10.4, Macintosh 10.6, Windows XP and Windows 7.

Linux distribution version

The User Defined Value field reports the distribution and version of Linux, if one is being used as the Operating System. Sample returned values include: Red Hat Enterprise Linux 5.4 and Fedora 13.

Screen colors

The Screen colors field reports the color depth being used. Sample returned values include: 32-bit and 24-bit.

Screen resolution

The Screen resolution field reports the resolution being used. Sample returned values include: 2048x1536 and 1920x1080.

Java version

The Flash version field has been modified to report the Java version used. Sample returned values include: 1.6.0_20 and 1.5.0_9.

Connection speed

The Connection speed field reports the type of internet connection being used. Sample returned values include: T1, Cable and DSL.

In this chapter we'll focus more on how to operate the JBoss AS from JBoss Tools.

JBoss Tools can be used to operate a wide range of JBoss Application Server versions, which can be downloaded from the JBoss Application Server website.

This section covers the basics of working with the JBoss Server supported directly by JBoss Developer Studio via bundled AS plug-in. The server points to the JBoss Enterprise Application Platform Runtime shipped with JBoss Developer Studio.


To read more about AS plug-in, refer to the Server Manager guide.

Although JBoss Developer Studio works closely with JBoss EAP 5 we do not ultimately tie you to any particular server for deployment. There are some servers that Studio supports directly (via the bundled Eclipse WTP plug-ins). In this section we discuss how to manage self-installed JBoss AS. Suppose you want to deploy the application to JBoss 4.2.3 server. First of all you need to install it.

It does not matter where on your system you install JBoss server.

Note:

The installation of JBoss server into a directory that has a name containing spaces provokes problems in some situations with Sun-based VMs. Try to avoid using installation folders that contain spaces in their names.

There is no requirement for root access to run JBoss Server on UNIX/Linux systems because none of the default ports are within the 0-1023 privileged port range.

  • After you have the binary archive you want to install, use the JDK jar tool (or any other ZIP extraction tool) to extract the jboss-4.2.3.GA.zip archive contents into a location of your choice. The jboss-4.2.3.GA.tgz archive is a gzipped tar file that requires a gnutar compatible tar which can handle the long pathnames in the archive. The extraction process will create a jboss-4.2.3.GA directory.

This chapter is a set of hands-on labs. You get step-by-step information about how JBoss Developer Studio can be used during the development process.

In this section you will learn how to create a Seam project in JBoss Developer Studio, how to start the server and what structure your project has after it is created.

Minimize the terminal window and run JBoss Developer Studio from Applications Menu or from the desktop icon.

First you will see the Workspace Launcher. Change the default workspace location if it's needed. Click the OK button.


After startup, you see the welcome page. You could read how to work with welcome pages in previous chapter. Now select Create New... icon and then press on Create Seam Project link.

The New Seam Project wizard is started. You need to enter a name (e.g., "workshop") and a location for your new project. The wizard has an option for selecting the actual Server (and not just WTP runtime) that will be used for the project. This allows the wizard to correctly identify where the destination folder for the required datasource and driver libraries.


All settings are already specified here, you can just modify the Configuration. Click on the Modify... button to configure your custom facet options:


On the whole the dialog allows to select the "features" you want to use in your project. JBoss Developer Studio will then setup the appropriate tooling for your project. Since JBoss Seam integrates all popular Java EE frameworks, you can select any combination of technologies from the list. Here, for the default configuration, Dynamic Web Module, Java, JavaServer Faces (JSF), and Seam Facet are already selected for a typical database-driven web application. The default project facets should suffice.

In the Project Facets form you can also bring up server runtimes panel by clicking Runtimes tab on the right corner. This panel shows available server runtimes.


Click the OK and then the Next button to proceed to the next step.

A dynamic web application contains both web pages and Java code. The next wizard will ask you where you want to store Java files.


Following page provides you Web Module Settings .You can just leave the default values or choose another folder.


On the next form, you will be able to select where those library JARs come from. The easiest is just to select the JARs provided by the JBoss AS runtime associated with this project. That is why it is important to chose the right JBoss AS 4.2 runtime in the project setup window.

  • Select Library Provided by Target Runtime as Type of JSF Implementation Library. We will use the JSF implementation that comes with JBoss server.

  • Click the Next button


Next wizard step needs more settings that previous. Let's start with General section.

Leave the default Seam runtime and check a WAR deployment.


The Database section is a little tricky. The Connection Profile needs to be edited so that the new project works properly with the external HSQLDB server. By default the project wizard tries to use the JBoss embedded HSQLDB, but the tutorial uses an external database to replicate a more real world development scenario. Click on the Edit button to modify the Connection Profile.


Select HSQLDB Profile Properties. Make sure the Database location is set to hsql://localhost:1701


Click the Test Connection button. At this point it probably won’t work. This happens if the HSQL JDBC driver is not exactly the same. This can be solved by modifying the HSQLDB database driver settings. To modify the settings, click the Edit Driver Definition Driver button.


The proper Driver JAR File should be listed under Jar List. Select the hsqldb.jar file found in the jbdevstudio/jboss-eap/jboss-as/common/lib/ directory and click the OK button.


Now, the Test Connection should succeed. After testing the connection, click the OK button.


You can leave the Code Generation section as is. It refers to Java packages in which the generated code will be placed.


Tip:

If you want to name your web project "MyProject-war" note that the Test project name should not be "MyProject-war-test", it should be "MyProject-test".

Click on Finish button. Now, there should be a new Seam project called “workshop” listed in the Package Explorer view.


Now let's examine the project and its structure. Go back to the Package Explorer view in JBoss Developer Studio.

It seems like it's not much for a project but this shell application contains a login screen with default login logic, a menu template that can be further modified, and other layout templates.

It's important to note that the business logic will reside in the src/hot folder, by default. And, the package naming conventions that were used in New Seam project wizard could have been changed to something different from org.domain.workshop.session. Also, notice that there is a default Authenticator.java file. This is where custom security logic can be added. Seam has a nice declarative security model that we will explore in more detail later on. The src/main folder is a model directory. It stores the project's JPA entity beans.


The view tier of the application is also important. Seam uses facelets and there is a built-in facelets GUI editor that includes nice WYSIWYG and component drag/drop functionality. Try this out by opening home.xhtml from WebContent folder.


Notice that the templates reside in the WebContent/layout folder. There is a stylesheet in the WebContent/stylesheet folder. There is also a login and default error page. The Facelet editor will be explored in more detail later in the lab.

The project already has a datasource that was created via the Seam project wizard database settings. All of the Seam specific configuration files and JAR dependencies are included and located in their proper locations. On last noteworthy line item is related to the build script. There isn’t a build script because the Eclipse WTP (Web Tools Project) plugin is used to publish web application changes. As you can see, JBoss Developer Studio is removing a great deal of complexity from the enterprise Java project setup and deployment process. The end result is the developer is writing code, not spending time trying to figure out how to get a decent development environment and project build process.

Now it’s time to write some code. The good news is that JBoss Developer Studio can also help out in this respect. In this section, we will create a new Seam Action POJO and facelet with some custom business logic and some GUI changes.

In this section you will see how easy it is to secure the facelets and facelet components in Seam. Let’s go ahead and secure the action button, then we will secure the entire page.

Now, it’s time to reverse engineer the workshop database into a fully functioning Seam CRUD (Create Read Update Delete) application.

In JBoss Developer Studio, switch to the Seam perspective, and then right-click the project and select NewSeam Generate Entities.

The "workshop" project in the Seam Generate Entities wizard will be selected automatically. There is no need to change something more, click the Next button to proceed to the next step.


On the next page use the Refresh button to display the database, then click the Include button to include all the tables from the database, and finally click the Finish button.


After running the Generate Entities action, you will see new org.domain.workshop.entity classes. These classes represent insert/update/delete/query logic.


There is also the org.domain.workshop.entity package that contains the JPA classes. These are the entity beans that are mapped to database tables. Note that you can use Seam refactoring tools with Seam components. Read more about it in Seam refactoring tools chapter of Seam Dev Tools Reference Guide.

Last, but not least, there are facelets for all of the CRUD screens. The best way to get a feel for the generated code is to open a browser and play around with the application. Go to http://localhost:8080/workshop and insert/update/delete/query a few records. There is quite a bit of AJAX in this application, but which we will explore further later on in the lab. For now, take note of the page tabs, required field logic and data table sorting in the list pages.

Tip

If you see the error java.lang.ClassNotFoundException: org.jboss.seam.servlet.SeamListener in the console output from the Application Server, you may need to copy the jboss-seam.jar file from the lib subdirectory in the Seam library (which can be downloaded from here) into the /server/default/deploy/workshop.war/WEB-INF/lib/ subdirectory in your Application Server (where "default" refers to the server profile that you are using).

Tip

If you see the error Could not instantiate Seam component: org.jboss.seam.security.ruleBasedPermissionResolver, copy the mvel2.jar file from the Seam library to the same destination directory mentioned in the tip above.


Congratulations! You now have a fully functioning CRUD application that is AJAX enabled.

Now, it's time to write some JPA queries using the Hibernate perspective in JBoss Developer Studio.

In the upper right corner of the workbench there is a small icon (see the figure below), click on it and select Hibernate.


Look at the Hibernate Configurations view. In the "workshop" project, drill down on the Session Factory and notice that the JPA entities/attributes are listed in a nice tree view.


Right click on the Session Factory and select HQL Editor. This will open a JPA query scratch pad window.

Write your query and click on the "Hibernate Dynamic SQL Preview" tab. You should see the SQL that will be executed if this JPA query is run.


Run the query by clicking on the green run icon.

The results are listed in the "Hibernate Query Result" view. There is a "Properties" tab in the workbench that can be used to see a specific JPA result. These results represent the JPA objects because our query did not specify column names.


The query can be refined, and take note that there is nice code completion in the JPA query editor.


A refined query will return results that are more ResultSet oriented. Notice the join logic that JPA supports.


There was no need to specify an Employees table in the from part of the JPA query because JPA supports reference traversal via Java class attribute references. Not only are JPA and HQL queries fully supported, but Criteria based queries can also be written in the Criteria Editor. You should spend some time tinkering with different queries and possibly Criteria based queries, even though the instructions are not provided in this lab.


Note:

We highly recommend developing in Seam. This chapter is for users who for some reason cannot use Seam.

In this chapter you'll find out how to create a simple JSP application using JBoss Developer Studio. The application will show a classic "Hello World!" on the page.

We'll assume that you have already launched JBoss Developer Studio and also that the Web Development perspective is the current perspective. If not, make it active by selecting WindowOpen PerspectiveWeb Development from the menu bar or by selecting WindowOpen PerspectiveOther... from the menu bar and then selecting Web Development from the Select Perspective dialog box.

This section covers all the points how to create, edit and then preview JSP page.

In our simple application we need to create only one JSP page which displays a "Hello World!" message.

In the next window you can choose a template for your JSP page and see its preview.


Our hello.jsp page will now appear in the Project Explorer view.

Writing ant scripts and managing the packaging process can be quite a complicated and time consuming task for even the most trivial web applications. However, JBoss Developer Studio relieves you of this burden. All you need is to start JBoss Server and launch your application in your favorite browser.

You can also create a JAR archive with JBoss Developer Studio's Archive Tools and export it to any web server.

Note:

We highly recommend developing in Seam. This chapter is for users who for some reason cannot use Seam.

In this chapter you will learn how to create a simple JSF application being based on the "RAD" philosophy. We will create the familiar Guess Number application. The game is played according to the following rules. You are asked to guess a number between 0 and 100. If the guess is correct, a success page is displayed with a link to play again. If the guess is incorrect, a message is printed notifying that a smaller or a larger number should be entered and the game continues.

We'll show you how to create such an application from scratch, along the way demonstrating the powerful features included in JBoss Developer Studio such as project templating, Visual Page Editor, code completion and others. You will design the JSF application and then run the application from inside JBoss Developer Studio using the bundled JBoss server.

A resource file is just a file with a .properties extension for collecting text messages in one central place. JBoss Developer Studio allows you to create quickly a resource file. The messages stored in resource file can be displayed to you on a Web page during application execution.

With resource file you don't hard code anything into the JSP pages. It also makes it easier to translate your application to other languages. All you have to do is to translate all your messages to the other language and save them in a new properties file with a name that ends with the appropriate ISO-639 language code.

It is a good idea to keep your resources inside the JavaSource folder, where you keep your .java files. Every time you build the project, all .properties files will then be copied to the classes folder by default.

Your resource file and java bean will be stored in this folder.

JBoss Developer Studio will automatically open messages.properties file for editing.


  • Click the Add button for adding new attribute to your resource file

  • Enter how_to_play for the "name" and Please pick a number between 0 and 100. for the value

  • Click the Finish button

  • Add the following properties using the same process:

makeguess_button=Make Guess
trayagain_button=Play Again?
success_text=How cool.. You have guessed the number, {0} is correct! 
tryagain_smaller=Oops..incorrect guess. Please try a smaller number.
tryagain_bigger=Oops..incorrect guess. Please try a bigger number.
  • Select FileSave from the menu bar

Your .properties file should now look like follows:


The Up and Down buttons allow you to move the attributes in the list. To delete the attribute, select it and press the Delete button.

If you want to change a value or a name of your attribute, select it and then click the Edit button.

If the .properties file is rather big and there are a lot of entries in it, you can use filtering and regular expressions narrow down the list. The Filter and Regular Expressions Search is implemented by an expandable panel, closed by default:

When "Expression" is not selected (as by default), filter is case insensitive. When "Expression" is selected, filter uses regular expressions which are case sensitive


Enter the characters that should be searched for in the entries to the 'name' or 'value' input fields accordingly. The filtered results will be displayed in the table below:


When using regular expressions please note, that regular expression syntax does not use "*" for any characters and "?" for any one character. It's necessary to use "." for any one character and ".*" for any characters. Symbols "*" and "?" are used to show that the preceding token is not required, for example, "a.a" matches "aba" but not "aa", while "a.?a" or a.*a" matches both; besides "a.*a" matches "abcda".

To find the exact match, use sequences \A and \z in expression. For example, expression "\Adate\z" matches only string "date"; expression "\Adate" matches "date" and "dateline", expression "date\z" matches "date" and "Begin date", and expression "date" matches all of them.

In this section you'll learn how to create a Java bean that will hold business logic of our application.

A java bean is created.

Integer userNumber;

JBoss Developer Studio allows to quickly generate getters and setters for java bean.

int randomNumber;
public NumberBean () 
{
    randomNumber = (int)(Math.random()*100);
    System.out.println ( "Random number: "+randomNumber);
  }
  public String playagain () 
  {
    FacesContext context = FacesContext.getCurrentInstance();
    HttpSession session = 
        (HttpSession) context.getExternalContext().getSession(false);
    session.invalidate();
    return "playagain"; 
  }
  public String checkGuess () 
  {
     
    // if guessed, return 'success' for navigation
    if ( userNumber.intValue() == randomNumber ) 
    {
      return "success";
    }
else 
   {
      FacesContext context = FacesContext.getCurrentInstance();
      ResourceBundle bundle = ResourceBundle.getBundle("game.messages", 
      context.getViewRoot().getLocale());
      String msg = "";
      // if number bigger, get appropriate message
      if ( userNumber.intValue() > randomNumber ) 
         msg = bundle.getString("tryagain_smaller");
      else // if number smaller, get appropriate message
         msg = bundle.getString("tryagain_bigger");      
      // add message to be displayed on the page via <h:messages> tag
      context.addMessage (null, new FacesMessage(msg)); 
      // return 'tryagain' for navigation
      return "tryagain";
    }
  }
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import javax.faces.application.FacesMessage;
import java.util.ResourceBundle;

The whole java bean contain the following code:

package game;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import javax.faces.application.FacesMessage;
import java.util.ResourceBundle;

public class NumberBean 
{
  Integer userNumber; 
  int randomNumber; // random number generated by application
  
  public Integer getUserNumber () 
  {
    return userNumber;
  }
  public void setUserNumber (Integer value)
  {
     this.userNumber = value;
  }
  
  // constructor, generates random number
  public NumberBean () 
  {
    randomNumber = (int)(Math.random()*100);
    System.out.println ( 
   "Random number: " + randomNumber);
  }
  
  public String playagain () 
  {
    FacesContext context = FacesContext.getCurrentInstance();
    HttpSession session = 
        (HttpSession) context.getExternalContext().getSession(false);
    session.invalidate();
    return "playagain"; 
  }
  
  // check if user guessed the number
  public String checkGuess () 
  {
    // if guessed, return 'success' for navigation
    if ( userNumber.intValue() == randomNumber )
    {
      return "success";
    }
    // incorrect guess
    else 
   {
      // get a reference to properties file to retrieve messages
      FacesContext context = FacesContext.getCurrentInstance();
      ResourceBundle bundle = 
          ResourceBundle.getBundle("game.messages", 
          context.getViewRoot().getLocale());
      String msg = "";
      // if number is bigger, get appropriate message
      if ( userNumber.intValue() > randomNumber ) 
         msg = bundle.getString("tryagain_smaller");
      else // if number smaller, get appropriate message
         msg = bundle.getString("tryagain_bigger");
      
      // add message to be displayed on the page via <h:messages> tag
      context.addMessage (null, new FacesMessage(msg)); 
      // return 'tryagain' for navigation
      return "tryagain";
    }
  }
}

In this section you will learn about the faces-config.xml file.

This file holds two navigation rules and defines the backing bean used.

<?xml version="1.0" encoding="UTF-8"?>
<faces-config 
	version="1.2" 
	xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xi="http://www.w3.org/2001/XInclude"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2_.xsd">
  
  <navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
      <from-outcome>playagain</from-outcome> 
      <to-view-id>/pages/inputnumber.jsp</to-view-id>
    </navigation-case>
  </navigation-rule>

  <navigation-rule>
    <from-view-id>/pages/inputnumber.jsp</from-view-id>
    <navigation-case>
      <from-outcome>success</from-outcome> 
      <to-view-id>/pages/success.jsp</to-view-id>
    </navigation-case>
  </navigation-rule>
  
  <managed-bean>
    <managed-bean-name>NumberBean</managed-bean-name>
    <managed-bean-class>game.NumberBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
  </managed-bean>
                 
</faces-config>

The first navigation rule states that from any page (* stands for any page) an outcome of playagain will take you to the /pages/inputnumber.jsp file. Outcome values are returned from backing bean methods in this example. The second navigation rule states that if you are at the page /pages/inputnumber.jsp, and the outcome is success, then navigate to the /pages/success.jsp page.

Now, we will continue editing the JSP files for our two "views" using the Visual Page Editor.

First, edit the inputnumber.jsp file.

On this page we will have an output text component displaying a message, a text field for user's number entering and a button for input submission.

The Visual Page Editor will open in a screen split between source code along the top and a WYSIWIG view along the bottom. You can see that some JSF code will have already been generated since we chose a template when creating the page.

At the beginning it's necessary to create a <h:form> component that will hold the other components.

In source view you can see the declaration of a form.


First let's declare the properties file in the inputnumber.jsp page using the loadBundle JSF tag.

  • Add this declaration on the top of a page, right after the first two lines:

<f:loadBundle basename="game.messages" var="msg"/>

As always JBoss Developer Studio provides code assist:


  • Switch to Visual tab, where it is possible to work with the editor through a WYSIWYG interface

  • Click the outputText item from the JSF HTML group in the JBoss Tools Palette view, drag the cursor over to the editor, and drop it inside the blue box in the editor

  • Select the second column in the value row.

  • Click the ... button next to the value field

JBoss Developer Studio will display a list of possible values:


The text will appear on the page:


  • Switch to Source mode and insert a <br/> tag after the <h:outputText> component to make a new line.

  • Click the Save button.

  • On the Palette click on inputText, drag the cursor over to the editor, and drop it inside the editor after the text.

  • Switch to a Source mode and insert a <br/> tag after the <h:outputText> component to make a new line

  • Click the Save button

  • On the Palette click on inputText, drag the cursor over to the editor, and drop it inside the editor after the text

  • Select the value row and click in the second column

  • Click the ... button next to the value field

  • Expand Managed BeansNumberBean

  • Select userNumber value and click the OK button

  • Select the Advanced tab

  • Select the id row and click in the second column

  • Type userNumber in the text field

  • Select the required row and click in the second column

  • Click ... button next to the value field

  • Expand Enumeration and select true as a value


  • Click the OK button, then click the Finish button

  • Go to Source mode

  • Add the validation attribute to <f:validateLongRange> for user input validation

<h:inputText id="userNumber" value="#{NumberBean.userNumber}" required="true">
           <f:validateLongRange minimum="0" maximum="100"/>
</h:inputText>
  • Click the Save button

  • Again select Visual mode

  • On the Palette, click on commandButton, drag the cursor over to the editor, and drop it inside the editor after the inputText component.

  • In the editing dialog select the value row and click on the second column

  • Click the ... button next to the value field

  • Expand Resource Bundlesmsg and select makeguess_button as a value

  • Click the OK button

  • Select the action row and click in the second column

  • Type #{NumberBean.checkGuess} in the text field

  • Click the Finish button

  • In Source mode add <br/> tags between the <outputText>, <inputText> and <commandButton> components to place them on different lines

inputnumber.jsp page should look like this:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
<f:loadBundle basename="game.messages" var="msg"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Insert title here</title>
	</head>
	<body>
		<f:view>
			<h:form id="inputNumbers">
				<h:outputText value="#{msg.how_to_play}"/>
				<br/>
				<h:messages style="color: blue" />
				<br/>
				<h:inputText id="userNumber" required="true" value="#{NumberBean.userNumber}">
					<f:validateLongRange minimum="0" maximum="100" />
				</h:inputText>
				<br/>
				<br/>
				<h:commandButton action="#{NumberBean.checkGuess}" value="#{msg.makeguess_button}"/>			
			</h:form>
	</f:view>
	</body>
</html>

JBoss Developer Studio provides an option to download and import a ready-made project that you can explore learn from.

To adjust the settings of the Project Examples feature you need to navigate to WindowsPreferencesJBoss ToolsProject Examples.


The Show experimental sites checkbox serves to enable or disable user sites in the Project Example dialog (HelpProject Examples).

As you can see from the Project Examples Preferences image you can add a custom project example that can be provided by anyone. This feature can, for example, facilitate project testing.

In oder to add a new project example you need to select the User sites option and press the Add button to the right.

When the Add button is pressed the Add Project Example Site dialog is displayed. The dialog contains two input fields: Name, where you need to specify the name of the new entry and URL,which has to point to the XML file that contains example project(s) properties. The structure of the XML file is discussed in more detail in a later chapter of this guide. Alternatively, if the XML is stored on your local machine, you can hit the Browse button to select the file in the file system.

Here is an example of the XML file that holds project example settings:

<projects>
    <project>
		<category>User Examples</category>
		<name>User Project Example</name>
		<shortDescription>
		Short project description.
		</shortDescription>
		<description>
    	Full project description.
		</description>
		<size>10900</size>
		<url>
		http://projectexample.org/projectexample.zip
		</url>
	</project>
</projects>

Once you define the location of the XML file with projects settings you will see a new user site entry added. Please note now if you select the entry you can edit and remove it with the corresponding buttons to the right. You can not perform such operations with the Plugin provides sites.

When the user sites location is set up you can download and install the project(s). Please see the next chapter of the guide for more details.

To download a project example and start working with it you need to perform a few steps:


Alternatively, you should navigate to NewOther..., scroll down to find the JBoss Tools option (or just type in the first letters of the word "JBoss" for quick search), expand the option and select Project Examples, and click the Next button.

  • Now in the New Project Example dialog you can select a project you would like to explore and a site to download it from

    The Project Examples Wizard provides a filter field to more easily locate the project examples you want, so you can type in the project you would like to explore in the field.


Some project examples have dependencies which could not be automatically configured. In these cases you will receive a message prompt listing the detected requirements (see the figure below).


You should click the Details button to see the list of requirements and make any necessary fixes.


If you have previously specified user sites (see the User Sites chapter) they also will be displayed in the list of project examples in the category that was defined in the XML file with user sites settings.


Pleas note that to view the user sites you need to have Show experimental sites checked.

  • Press the Finish button to start downloading the project from the repository

When downloading is finished the project will be imported automatically and you will be able to see it in the Package Explorer view.

Now you can run the application on the server.


For further operation add the following code to .project files of your Web project example.

<buildCommand>
    <name>org.jboss.tools.jst.web.kb.kbbuilder</name>
    <arguments>
    </arguments>
</buildCommand>
...
<nature>org.jboss.tools.jst.web.kb.kbnature</nature>

It is needed for Code Assist and JSF EL Validation to function correctly.

The Project Examples Wizard has an option for making quick fixes for the imported project to easily fix possible issues like missing servers, Seam runtimes etc.

To enable the quick fix option you need to check the Show the Quick Fix dialog while choosing the Project Example.

When the project you selected is downloaded it will be checked for missing dependences and if any are detected you will see a dialog listing the problems.


To fix the problem you need to:

  • Select the problem from the list

  • Click the Quick Fix button

You will be offered a solution or a number of solutions to the problem.


In this case (see the image above), when the Finish button is pressed, the Seam Settings dialog box will be displayed where you need to provide a path to the Seam environment in order to fix the issue.

When the problem is fixed you will be returned to the Quick Fix dialog box with the remaining problems to be fixed.

You can also fix problems before downloading. When the project example is selected you will see warning message on the New Project Example dialog.


To fix the problem immediately you need to:

  • Click the Details... button in the New Project Example dialog

  • Select the problem from the list in the Requirement details dialog box

  • Click the Fix button


You will be offered a solution to the problem.

Refer to the following FAQ to get the answers on the most "popular" questions concerning JBoss Developer Studio.