- Product Overview
- How Do They Support SOA?
- Tutorial Overview
- What Is Included in the CD-ROM?
- Tutorial Setup
- Tutorial 7.1: Create and Test a Simple Portlet
- Tutorial 7.2: Create and Test a Portlet That Accesses a Database
- Tutorial 7.3: Deploy a Portlet
- Summary
Tutorial 7.2: Create and Test a Portlet That Accesses a Database
In this tutorial, you will create a service provider model to retrieve data from the database and create a service consumer model to present the data.
Step 1: Create a Service Provider Model
In this step, you will create a service provider model.
- Launch the WebSphere Portlet Factory Model Wizard to create a service provider model. It is one of the sample models provided by the IBM WebSphere Portlet Factory product. This sample model allows you to execute SQL statements against a database.
- Right-click PetTravel and click New, WebSphere Portlet Factory Model.
- Select PetTravel as the project. Click Next.
- Under Service Providers, select Database Service Provider as shown in Figure 7.55. Click Next.
Figure 7.55 Select to create a Database Service Provider model
- Enter PetTravelServiceProvider as the service name. Click Next.
- In step 1 of defining the service operation as shown in Figure 7.56, select jdbc/PetDB from the drop-down for SQL datasource and enter Select * from Administrator.PetTravelCompany as the SQL statement. Click Next.
Figure 7.56 Step 1 of defining the service operation
- In step 2 of defining the service operation as shown in Figure 7.57, enter getCompany as the operation name and keep all other defaults. Click Next.
Figure 7.57 Step 2 of defining the service operation
- Enter PetTravelCompany as the model name. Click Finish.
- The PetTravelCompany model has been created successfully as shown in Figure 7.58. The outline window at the bottom shows the list of builders in this model.
Figure 7.58 Database Service Provider model created
- Test the model.
- PetTravelCompany should be the selected model at this time. To test the model, click the Run Active Model icon.
- Your model should run successfully. You should see the getCompany operation you defined in the browser as shown in Figure 7.59. Click getCompany.
Figure 7.59 Database Service Provider model run successfully
- You should see the data from the database table PetTravelCompany displayed correctly as shown in Figure 7.60.
Figure 7.60 Data from database retrieved and displayed
In this step, you created a service provider model. You should see that the pieces are starting to come together. The service provider retrieves the data in the database table created in the "Tutorial Setup" section.
Step 2: Create a Service Consumer Model
In this step, you will create a service consumer model that will use a simple table to display the results from the provider model.
- Launch the WebSphere Portlet Factory Model Wizard to create a service consumer model. It is one of the sample models provided by the IBM WebSphere Portlet Factory product. This sample model displays data from a database.
- Right-click PetTravel and click New, WebSphere Portlet Factory Model.
- Select PetTravel as the project. Click Next.
- Under Service Consumers, select List and Detail Service Consumer as shown in Figure 7.61. Click Next.
Figure 7.61 Select to create a List and Detail Service Consumer model
- Enter PetTravelCompanySimpleTable as the name and select PetTravelCompany as the provider model as shown in Figure 7.62. Recall that you created the PetTravelCompany model in the previous step. Click Next.
Figure 7.62 Enter name and service
- Select getCompany from the drop-down for view data operation to provide the view data as shown in Figure 7.63. Recall that you defined the service operation getCompany to retrieve data from the database table PetTravelCompany. Click Next.
Figure 7.63 Specify service operation to provide view data
- Select COMPANY from the drop-down for details link column and keep all other defaults as shown in Figure 7.64. Recall that you created the database table PetTravelCompany with ID, Company, and Desc as the three columns. This is why Company appears as a choice in the drop-down. Click Next.
Figure 7.64 Specify how to get detail data
- Enter ListPetTravelCompany as the model name. Click Finish.
- The ListPetTravelCompany model has been created successfully as shown in Figure 7.65. The outline window at the bottom shows the list of builders in this model.
Figure 7.65 List and Detail Service Consumer model created
- Test the model.
- ListPetTravelCompany should be the selected model at this time. To test the model, click the Run Active Model icon.
- You should see the data from the database table PetTravelCompany displayed correctly in a simple table with the Details link using the Company column as shown in Figure 7.66.
Figure 7.66 List and Detail Service Consumer model run successfully
- Build a portlet WAR file for deploying in production. IBM WebSphere Portal is the production server.
- Right-click PetTravel and click Portal Server WAR, Build Portlet WAR for Production Deployment as shown in Figure 7.67.
Figure 7.67 Build portlet WAR for production
- Keep the defaults as shown in Figure 7.68. Click Finish.
Figure 7.68 Select portlet API and build path
- Go to the above build path. You should see the PA_PetTravel.war WAR file.
- Right-click PetTravel and click Portal Server WAR, Build Portlet WAR for Production Deployment as shown in Figure 7.67.
You have created a service consumer model to present data in a simple table.