Home > Articles > Web Services > WebSphere

  • Print
  • + Share This
This chapter is from the book

Tutorial 7.1: Create and Test a Simple Portlet

In this tutorial, you will create a project for all the models that will be built in Tutorials 7.1 and 7.2. You will then create a simple portlet.

Step 1: Create a Project in IBM WebSphere Portlet Factory

In this step, you will create a project in Portlet Factory Designer.

  1. Launch the Create Portlet Factory Project Wizard to create a WebSphere Portlet Factory project.
    1. WebSphere Portlet Factory Designer should have been started in the "Tutorial Setup" section.
    2. Click File, New, WebSphere Portlet Factory Project to create a project as shown in Figure 7.32.
      Figure 7.32

      Figure 7.32 Create a WebSphere Portlet Factory project

    3. Enter PetTravel for the project name. Click Next as shown in Figure 7.33.
      Figure 7.33

      Figure 7.33 Enter the project name

    4. There is no need to add feature sets to your project as shown in Figure 7.34. These feature sets provide additional builders that are not needed for this tutorial. Click Next.
      Figure 7.34

      Figure 7.34 Select feature sets

    5. Select WAS61 from the drop-down for application server deployment configuration as shown in Figure 7.35. Click Finish.
      Figure 7.35

      Figure 7.35 Specify application server deployment configuration

  2. After the progress indicator, click No when asked whether you would like to deploy your project now as shown in Figure 7.36. You will be shown how to deploy your project in a development environment in a separate step.
    Figure 7.36

    Figure 7.36 Deployment Request dialog

  3. Your project PetTravel has been created successfully and appears in the Project Explorer window as shown in Figure 7.37.
    Figure 7.37

    Figure 7.37 Project created

You have successfully created the project.

Step 2: Create and Test a Simple Portlet

In this step, you will create a simple model. You will then test the model using the deployment configuration you created in the setup section.

  1. Launch the WebSphere Portlet Factory Model Wizard to create a Main and Page model. It is one of the sample models provided by the IBM WebSphere Portlet Factory product. A Main and Page model supplies a page and a main action that presents that page when the application is run.
    1. Right-click PetTravel and click New, WebSphere Portlet Factory Model as shown in Figure 7.38.
      Figure 7.38

      Figure 7.38 Create a new WebSphere Portlet Factory model

    2. Select PetTravel as the project as shown in Figure 7.39. Click Next.
      Figure 7.39

      Figure 7.39 Select the project to contain the model

    3. Under Factory Starter Models, select Main and Page as shown in Figure 7.40. Click Next.
      Figure 7.40

      Figure 7.40 Select to create a Main and Page model

    4. Keep all the defaults as shown in Figure 7.41. Click Next.
      Figure 7.41

      Figure 7.41 Specify page type

    5. Enter PetTravelFAQ as the model name as shown in Figure 7.42. Click Finish.
    Figure 7.42

    Figure 7.42 Specify the model name and save

  2. Modify the content of the HTML page in the model.
    1. The PetTravelFAQ model has been created successfully as shown in Figure 7.43. The outline window at the bottom shows the list of builders in this model. Double-click the imported page builder page1.
      Figure 7.43

      Figure 7.43 Main and Page model created

    2. Click Edit Page to modify the page content in HTML as shown in Figure 7.44.
      Figure 7.44

      Figure 7.44 Edit page

    3. To modify the page content, follow the example as shown in Figure 7.45 or provide your own HTML content. Click Save Page, then Apply and OK to save changes for the builder.
      Figure 7.45

      Figure 7.45 Modify page content and save builder changes

    4. Click File, Save to save changes for the model as shown in Figure 7.46.
      Figure 7.46

      Figure 7.46 Save model changes

  3. Deploy the project for development testing.
    1. Right-click PetTravel and click Application Server WAR, Build WAR for Dev Testing as shown in Figure 7.47.
      Figure 7.47

      Figure 7.47 Deploy project for development testing

  4. Test the model.
    1. Click the Run Active Model icon as shown in Figure 7.48.
      Figure 7.48

      Figure 7.48 Run selected model

    2. A little setup is needed for the first time. Expand WebSphere Portlet Factory Model and select Active Model as shown in Figure 7.49. Click Run.
      Figure 7.49

      Figure 7.49 Run setup

    3. Your model should run successfully. The page you provided HTML content for is shown in a browser as in Figure 7.50.
      Figure 7.50

      Figure 7.50 Main and page model successfully run

  5. It is simple to make this model run as a portlet as well. Only one builder needs to be added.
    1. In the outline window, click the Add a Builder Call to the Current Model icon as shown in Figure 7.51.
      Figure 7.51

      Figure 7.51 Add a builder call

    2. In the Builder Picker window as shown in Figure 7.52, select Portal Integration for the category name and Portlet Adapter for the builder. Click OK.
      Figure 7.52

      Figure 7.52 Select a builder to add to the model

    3. Enter PetTravelInfo as the name and the portlet title. Enter Pet Travel Information as the portlet short title. Click Apply and then OK as shown in Figure 7.53.
      Figure 7.53

      Figure 7.53 Fill in information for the Portlet Adapter builder

    4. The Portlet Adapter builder has been added to the model as shown in Figure 7.54. Click File, Save.
      Figure 7.54

      Figure 7.54 The Portlet Adapter builder added to model

  6. You only need to do this step if you will not be doing the next section to create and test a portlet that accesses a database. Right-click PetTravel and click Portal Server WAR, Build Portlet WAR for Production Deployment. Keep the defaults. Click Finish.

You have created and tested the model. The model is used to generate the portlet.

  • + Share This
  • 🔖 Save To Your Account