Tutorial - Using profiling in your new applicationAdded by IBM on August 31, 2010 | Version 1 (Original)
|Continuing from the "hello world" application tutorial you add the power of profiling to your application.
Continuing from the "hello world" application tutorial you add the power of profiling to your application.
Using these tutorials
This set of tutorials are a great starting point for a new WebSphere® Portlet Factory developer. Each of the four parts of this tutorial take between 30 and 45 minutes to complete. The tutorials should be completed in the following order, as each builds on knowledge obtained in the previous tutorial. In addition, we recommend visiting the WebSphere Portlet Factory Learning Roadmap
on the WebSphere Portlet Factory wiki after completing these tutorials to further advance your WebSphere Portlet Factory learning experience.
| Creating a Web Application Project||In this tutorial you will learn how to create a web application project.|
| Creating an application||In this tutorial, you will build a simple "hello world" application and then create a portlet from that application. |
| Creating a database application||In this tutorial you will create a service provider model against a sample database using the SQL Table Create builder, and then create a user interface service consumer model, using the Service Consumer and Data Services User Interface builder.|
| Using profiling in your new application||Continuing from the "hello world" application tutorial you add the power of profiling to your application.|
What you will learn
In this tutorial, you will add profiling to the application. Profiling allows WebSphere Portlet Factory to build several versions of an application dynamically by supplying sets of alternative values for various parts of the application.
Creating a profile set and applying profiling to the Application
One of the most powerful aspects of WebSphere Portlet Factory is that models can be used in conjunction with a concept called profiling to generate multiple versions of the same application by combining different sets of predefined parameters with the same code base. In this part of the tutorial, you will create a new profile set for a set of builder inputs. The profile set contains two different sets of values for the profiled builder inputs. One set of values makes the application behave one way and the other set of values makes it behave another way. When you have finished, you will have two versions of the application each of which can be invoked by flipping a switch and re-running the model.
- Create a profile set for a Text builder.
- Let's return to the MyFirstPortlet model you worked with in the Creating an application tutorial and find the Text builder call named namedTag and open it by double-clicking it in the Design view or in the builder call list. That builder call should appear in the builder call editor to the right.
- Look for a builder input named Text with a value of Tutorial Basics – Hello World!. Click to profile enable this builder input.
What is Going on Here?
The first time you profile enable a builder input in a model WebSphere Portlet Factory creates a profile set for you with the model name followed by the suffix "ps" as the name of that implicitly created profile set. For example, for the model MyFirstPortlet, Designer automatically creates a profile set named MyFirstPortletps.
- Click Create Entry, change the name to Text and the prompt to Text To Display and click OK when finished.
- Click Create Profile to add a second profile, in addition to the "Default" profile. Name this profile MyFirstPortletAlternateView and click OK. For the profile value, enter Profiling Tutorial - alternate view
- Click OK when finished.
- At this point the builder call changes are not saved. Save your changes by clicking File -> Save.
- Apply the profile and test the application.
- Before applying the MyFirstPortletps profile, run the model again to see what values appear in the Application. At this moment, there should be no changes and the application should behave exactly as it did the last time you tested it.
- Close the browser to return to WebSphere Portlet Factory Designer, and look to the bottom section of the workspace. There should be a panel with tabs labeled Problems, Tasks, and Applied Profiles. (If these tabs are not displayed, choose Window -> Reset Perspective ) Click the Applied Profiles tab.
- In the Applied Profiles tab, there is a drop-down list containing the names of all of the profiles in the MyFirstPortletps profile set. This profile set appears in this tab because there are builder inputs in this model associated with profile entries in that profile set. Choose MyFirstPortletAlternateView from the list and click the Apply button.
What Happens Now?
By choosing the MyFirstPortletAlternateView profile and applying it, WebSphere Portlet Factory Designer specifies that explicit profile when it runs the model and initiates a process called regeneration. During regeneration, the model and the inputs supplied by the chosen profile are combined to create new version of the application.
You can see the two variations of your application in the Design view and the Application Tree view. As you switch between the two profiles and click the Apply button, you can see the changes in the application. For example, if you expand the Application Tree to WebApp -> Page -> page1 and click on page1. To the right you will see a few of the <div> tags with their content replaced by static text, filenames, and JSP scriptlets and expressions.
- Run the model to see the changes. This time you should see the text values from the MyFirstPortletAlternateView profile instead of the Default profile from the MyFirstPortletps profile set.
- Add an Image builder and profile it for use with the MyFirstPortletps profile set.
In this step, you will add an Image builder and use profiling to determine when this builder should be enabled or disabled. Disabled builders do not make any contributions to the generated application. Associating a builder's enable/disable value to a profile entry allows builders to be added or deleted automatically by regeneration based solely upon which profile is applied at regeneration time.
- In WebSphere Portlet Factory Designer, add an Image builder to the model. Use the table below to assign its inputs:
Table 2. Image builder inputs
|Input Name||Enter this value for the given input|
|Location Technique||Relative to Named Tag|
|New Tag Name||imgTag|
|Image Source||Click to the right of this field to bring up a reference chooser. Click the Choose File tab and choose /samples/tutorials/images/tutorial_basics_image.jpg and click OK.|
- Run the model with the added image here, to make sure it's working, before profiling it.
- Inside the builder call editor, look to the top of the Image builder call and expand the section called Properties by clicking on it. You will see an input named Enable Builder. Click to profile enable this builder input. As with the other profile entry, use Create Entry, and change the prompt to Display Image, and set the UI type to "Checkbox" and edit the Label After Check Box field to My Checkbox. Click OK. The UI types for profile entries will show up when you customize (configure which profile to use) in Portal.
- Set the profile value to unchecked for the Default profile, for this image builder call enablement profile entry. Edit the Label After Check Box field and remove the text My Checkbox. Click OK.
- Test the profile again to ensure everything is working.
- Using the Applied Profiles tab, apply the Default profile and run the application. In the web browser, you should see the default version of the application. This version should not display the image file.
- Now apply the MyFirstPortletAlternateView profile and run the application again. This time you should see the image file.
- Open the Portlet Adapter builder named "tutorial_basics"
- In the Portlet Adapter builder call editor, enable value customization by choosing Show individual profile values in Edit Defaults for the MyFirstPortletps profile set. Click OK in the builder call editor to apply the changes, then save the model.
- Re-publish the application.
- Login to the portal again as an administrator, so you will be given access to the Shared Settings feature. Navigate to the portal page where your portlet is located.; Open the portlet's title bar drop down menu and choose "Shared Settings". This will put the portlet in the shared settings (also known as "edit defaults" by the portlet adapter builder and portlet JSR 168 and 286 specifications) customization mode so that you can specify the custom values for those profile entries.
Lessons learned and next steps
By profiling some of the builder call inputs in a model, several versions of the application can be generated by simply switching profiles. In WebSphere Portlet Factory Designer, profiles can be chosen from the Applied Profiles
tab. Depending upon how a Portlet Adapter builder call is configured, portlet administrators and users can apply various profiles in WebSphere Portal by using the Configure and Edit modes of the portlet. Profiles can also be chosen programmatically through a process called profile selection handling.
Profiles can also be used for localization, and profiling to portal groups. See this wiki article
for more information.
Parent topic: Tutorials for IBM WebSphere Portlet Factory: wpf7
Using sample handlers: wpf7