Skip to main content

How to generate simple Web sites fast

Using IBM Rational Software Architect to generate JavaServer Faces and Service Data Objects pages from UML

Steve Arnold, Senior IT Specialist, IBM 
Steve is a senior technical consultant working for IBM Rational in the UK, where he has worked for six years. His main areas of expertise are UML design and model-driven architecture, plus he has a strong interest in Eclipse and Rational product extensibility.

Summary:  This article describes how to use IBM® Rational® Software Architect to generate working Web pages from a UML data model. The generated Web site provides pages that offer create, read, update, and delete functionality for the defined data model. It can be used to generate the simple data management screens for your application, thus enabling you to focus on more complex, higher-value development.

Date:  27 May 2008
Level:  Intermediate
Activity:  8223 views

Overview of UML-to-JSF or -SDO transformation

In this article, I describe how the transformation works and the current limitations. I then walk through an example that takes a UML model of the database, marks it up, generates, and then tests the resulting Web pages.

Let's start with an overview of what the transformation does: It simply takes a marked-up class in the UML model and generates a page for a list of results, which then links to pages to create and update or delete the specific entry (see Figure 1).


Figure 1. UML table to Web pages
Diagram

If Class A is modelled as related to Class B, then a list of related B items will be shown on the Details page for A (Figure 2), thereby enabling navigation around the data in the database.


Figure 2. UML relationships to Web pages
2 screen fragments & screen captures of 3 tables

This transformation can take a significant data model and generate a working Web site for data update and management. The generated Web pages will require additional manual work, because they need to be cosmetically updated to match the UI guidelines for your organization. Or the transformation could be updated to do as much of this as practical by default.

Limitations

The transformation currently has several limitations:

  • It supports only Java™Server Faces and Service Data Objects (SDO) architecture.
  • It supports only IBM® DB2® databases (you will need DB2 installed to follow the steps in this article).
  • It does not support joins (although this could be achieved through the use of views)

Now that you know a little more about what the transformation does and doesn't do, it's time to install it and use it in an example.

Install the transformation

The installation of the UML to JSF/SDO transformation is straight-forward.

  1. Download the RAS file (Downloads) to a location on your hard drive.
  2. Start IBM Rational Software Architect and select File > Import.
  3. Choose RAS > RAS Asset and click Next.
  4. Browse to the downloaded RAS file and click OK in response to the information warning about installing a feature or plug-in.
  5. Click Next.
  6. Select the feature, accept the license agreement, and then click Finish.
  7. Click OK in the Import Results dialog that says that the import was successful but not enabled for this session.
  8. When prompted, restart to enable the plug-in.

Now switch to the Modeling perspective and go to Modeling >Transform >New Configuration to confirm that you have the UML to JSF/SDO transformation under IBM Rational Web Transformation.

Installing Source (Optional)

  1. Download the zip file to a location on your project.
  2. Open up Rational Software Architect, and choose Import > General > Existing projects, and then select archived file, and then point at the downloaded zip file.

This will then import the source projects into your workspace, and you can modify the transformation as desired.

Mark up the model

Now you're ready to complete this model example.

Import the example model

The project is contained as an archived file, inside the documentation plug-in.

  1. Select File > Import, and then General > Existing projects Into workspace.
  2. Click Next, and then select Archive File > Browse, and browse to the C:\Program Files\IBM\SDP70\plugins directory.
  3. Open the com.ibm.uk.transformations.umltojsfsdo.doc folder, and select the com.ibm.uk.transformations.umltojsfsdo.example.zip file.
  4. Select Open, and then click Finish.

In the Project Explorer, you should now have a project called:
com.ibm.uk.transformation.umltojsfsdo.example

Open the model

  1. Go to the Modelling perspective.
  2. Open the model called STORE_SCHEMA.emx (do not open the one with the profile applied, because it has already been marked up).
  3. Open the Overview diagram (Figure 3).
  4. Review the model.

Figure 3. Overview diagram
Model Overview diagram

Apply the profile

  1. Select the STORE_SCHEMA model, and go to the Profiles tab on the Properties page.
  2. Choose Add Profile, and select the CRUD_JSF_pages profile from the deployed profiles list (Figure 4).

Figure 4. Properties tab with applied profile
<Model> STORE_SCHEMA view on right

Create the database

The model must contain an abstraction of the database.

  1. Select the model, right-click, and choose to Add UML > Component.
  2. Call the component STORE.
  3. Select the STORE component, and in the Properties view, go to the Stereotype tab, choose Apply stereotype, and select DB (Figure 5).

Figure 5. Component stereotype selection
Apply Stereotypes view showing selections

  1. Now, still in Properties, go to the Advanced tab, and under DB, set the databaseUser to db2admin in the Value column.

Figure 6. Component properties
Property and Value columns

Create the schema

  1. Select the STORE_SCHEMA model.
  2. In the Properties view, apply the Schema stereotype by selecting the Stereotypes tab and then Apply Stereotype > Schema.

Mark up the key gen table

The key gen table is the table that is used to generate a primary key on insertion.

  1. Open the KEYGEN table in Project Explorer, select the SETCOL attribute, and apply the PK stereotype.

Figure 7. Project Explorer
Project Explorer shows folder and file directory

Mark up the tables

To mark up the tables, you need to stereotype them, mark their foreign keys, and align their key gen tables to KEYGEN.

  1. First, apply the TableWithCRUDJSFPages stereotype to these:
    • ORDER
    • PRODUCT
    • SALE
    • INVENTORY
    • STORE
  2. Then select ORDER, PRODUCT, SALE, INVENTORY, and STORE, go to the Advanced tab on the Properties page, and enter KEYGEN in the uniqueKeyTable field under TableWithCRUDJSFPages.
  3. Add the PK stereotype to the following columns:
    • INVENTORY.ID
    • ORDER.ORDER_ID
    • PRODUCT.CODE
    • SALE.SALE_ID
    • STORE.STORE_ID
  4. Finally, the product table will be referenced in a drop-down list from ORDER,INVENTORY and SALE. To display the description, rather than the code, you need to stereotype the Description column. Apply the Display stereotype to PRODUCT.DESCRIPTION.

In the Project Explorer, the completed model should look like Figure 8.


Figure 8. Completed model in Project Explorer
Updated, longer directory

Correctly name the foreign keys

The last step is to make sure that the foreign keys are correctly defined for the relationships.

  1. Open the Overview diagram tab. Select each composition relationship in turn, and set the role name at the composition end to STORE_ID. When you are finished, in the Project Explorer you should now see a STORE_ID column on the INVENTORY, ORDER, and SALE tables.
  2. Select each relationship to the PRODUCT table in turn, and rename the product role to PRODUCT_CODE. Again, on completion you should see a PRODUCT_CODE attribute on SALE, INVENTORY, and ORDER.
  3. The model should now look like Figure 9.

Figure 9. Final marked-up model
Updated Overview diagram

Transform a marked-up model to create the Web pages

To complete this setup, you need to create the database, configure and run the transformation, and then test the generated artifacts.

Create the database

  1. Start the DB2 Control Center, and create a new database called STORE.
  2. Then select the Schema folder under the database, and choose Create new schema.
  3. Provide a name of STORE_SCHEMA and an authorization user name of db2admin.
  4. In Rational Software Architect, switch to the Data perspective.
  5. In the Database Explorer, create a connection to the STORE database, and call it STORE.
  6. In the Data Project Explorer, open the ibm.uk.transformations.umltojsfsdo.example project, and select createDatabase.sql from the SQL Scripts folder.
  7. Right -click, and select Run SQL. Choose to use an existing connection, and choose the store connection created previously.
  8. Reconnect if necessary, and click Finish.
  9. In the Data Project Explorer, select insertData.sql, right-click, and select Run SQL. Choose to use an existing connection, and choose the STORE connection already created.
  10. Reconnect if necessary, and click Finish.
  11. The database is now set up. You can verify that it is set up OK by going to the Database Explorer and selecting STORE > Schemas > STORE_SCHEMA > Tables.
  12. Select STORE, right-click, and then select Data > Sample Contents.

You should see three rows returned, as Figure 10 shows.


Figure 10. Results of Store query
Sample Contents on right, 3 rows under columns

Create a transformation configuration

  1. Return to the Modeling perspective and select Modeling > Transform > New Configuration.
  2. Enter UML to JSF as the name.
  3. Within the IBM Rational Web Transformation folder, select UML to JSF/SDO Transformation.
  4. Then select the example project as the configuration file destination for the transformation configuration (Figure 11).
  5. When you have finished, click Next.

Figure 11. New Transformation Configuration view
Name and Transformation view

  1. Choose the model as the source, and select the example project as the target (Figure 12).

Figure 12. Transformation Source and Target view
Selected Source on left, Selected Target on right

  1. Click Next.
  2. Enter the name of the project that will be created, such as MyStore, and click Finish.

Run the transformation

  1. Select the transformation configuration from the previous step, right-click, and choose Transform > UML to JSF/SDO Transformation.
  2. This will generate MyStore Web and MyStoreEAR projects and all of the Web pages required to view, update, create, and delete data in the database.
  3. From the MyStore project, open the Web site navigation diagram.

The diagram should show the generated Web pages (Figure 13).


Figure 13. Web site navigation diagram
Shows navigation hierarchy

Test the generated artifacts

  1. Change to the Web perspective.
  2. Start your application server.
  3. Deploy the EAR file to the application server.
  4. Select the store_list.jsp file, and choose Run on server.


Downloads

DescriptionNameSizeDownload method
Deployable RAS fileumltojsfsdo_v1.0.8_ras.zip5044KB HTTP
Source Code - Archived Eclipse Projectsumltosjfsdo_v1.0.8.zip10328KB HTTP

Information about download methods


Resources

Learn

Get products and technologies

Discuss

About the author

Steve is a senior technical consultant working for IBM Rational in the UK, where he has worked for six years. His main areas of expertise are UML design and model-driven architecture, plus he has a strong interest in Eclipse and Rational product extensibility.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=310286
ArticleTitle=How to generate simple Web sites fast
publish-date=05272008
author1-email=steve.arnold@uk.ibm.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers