Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Extending WebSphere Portal V6 personalization capabilities: Part 2. Creating a Hello World application object

Jonathan Brunn (jbrunn@us.ibm.com), Software Architect, IBM
Jon Brunn is the architect of Lotus Quickr for Enterprise Content Management integration. Jon currently contributes to the Lotus Quickr product, especially in the areas of extension, customization, and enterprise integration. You can reach Jon at jbrunn@us.ibm.com.

Summary:  This series describes and shows you how to extend WebSphere Portal Personalization capabilities to make data from external sources available to your portal using Personalization rules. In Part 1, you learned the fundamentals for working with external data and Personalization rules. In this part, you build a very simple application object to extend Personalization, and you use the object to show and hide a portlet.

View more content in this series

Date:  14 Feb 2007
Level:  Intermediate PDF:  A4 and Letter (31 KB | 8 pages)Get Adobe® Reader®

Activity:  6491 views
Comments:  

Creating the Hello World object

In this section you create and deploy the application object.

Creating a project

Start by creating a Java project to hold the application components.

  1. Start Rational Application Developer.
  2. Create a Java project.
  3. Select New => Other => Java => Java Project.
  4. Enter CustomApplicationObjects.
  5. Click Finish.
  6. Add Personalization classes to your project’s classpath.
  7. Right-click on the project in the workspace; choose Properties => Java Build Path => Libraries.
  8. Click Add External JARs. Navigate to the pzn/v6.0/lib directory under your WebSphere Portal install root; (for example, C:\ibm\PortalServer\pzn\v6.0\lib). If your portal server is not local, you can copy the contents of this lib directory locally and then reference the JARs from the local directory.
  9. Select pznauthor.jar, pzncommon.jar, pznquery.jar, pznresources.jar, and pznruntime.jar.
  10. Click Open.
  11. Verify your Java Build Path looks like this:
  12. Click Ok to close this window.

Create the Java class for the application object

  1. Choose File => New => Class (or File => New => Other => Java => Class).
  2. Enter com.ibm.websphere.personalization.examples in the Package field, MySampleObject in the Name field, and make sure the Source Folder is CustomApplicationObjects.
  3. Click Finish.
  4. Copy this code into the Application Object
  5. Double-click on the MySampleObject.java file to open it if it is not opened.
  6. Copy the following source into MySampleObject.
    package com.ibm.websphere.personalization.examples;
    
    import java.util.Date;
    
    import com.ibm.websphere.personalization.RequestContext;
    import com.ibm.websphere.personalization.applicationObjects.
       SelfInitializingApplicationObject;
    import java.io.Serializable;
    
    public class MySampleObject implements SelfInitializingApplicationObject,
    		Serializable {
    
    	private String userName;
    	
    	public void init(RequestContext context) {
    		userName = context.getRequestUsername();
    context.setSessionAttribute("mysampleobject", this);
    	}
    	
    	public String getMySampleString() {
    		return "Hello " + userName;
    	}
    	
    	public int getMySampleInt() {
    		return 1;
    	}
    	
    	public Date getMySampleDate() {
    		return new Date();
    	}
    		
    }
    
    

  7. Select File => Save.

Deploy the object to the server

  1. Export the Java project as a jar
  2. Select the CustomApplicationObjects project.
  3. Click File => Export => JAR file.
  4. Click Next.
  5. Enter a JAR file destination. If your portal server is local, enter <wps>pzn\v6.0\collections\CustomApplicationObjects.jar substituting your portal server installation directory for <wps>, as in C:\ibm\PortalServer\pzn\v6.0\collections\CustomApplicationObjects.jar. If you are using a remote portal server, save the JAR locally and then copy the JAR to the collections directory on your portal server. The collections folder is part of a shared library created during the install and is intended to store custom application object and resource collection classes.
  6. Click Finish to export the JAR.
  7. Restart you portal server to pick up the new JAR.

Configure the application object in Portal Personalization

  1. Login to the portal server.
  2. Navigate to the Personalization Business Rules page. With the default theme, this page is accessible by clicking Launch => Personalization => Business Rules.
  3. Create a folder to contain your work by choosing New => Folder from the menu; name the folder Application Objects and click Save. Using a folder here is optional. Because export, import, access control, and versioning operate on folders, it is a good idea to give some thought to the folder structure you use. Moving some objects in Personalization after their creation will break references to those objects.
  4. With the Application Object folder open in the Personalization Navigator, choose New => Application Object from the menu.
  5. Enter My First Application Object in the name field. This name will display in the rule editor; it can be anything you choose.
  6. Enter mysampleobjectfor the Session Key. This name should match the key you used in the code in step 5c. Keeping these values the same insures that the rules engine will pick up the object from the session.
  7. Complete the Class Name field with the name of our Application Object Java class, com.ibm.websphere.personalization.examples.MySampleObject.

    If you have not put the MySampleObject class in the classpath by copying the JAR into the collections folder, or if you have not restarted the server, you might see a message: The application object class 'com.ibm.websphere.personalization.examples.MySampleObject' could not be located. Specify a valid class for this application object. If you see this message, check the location of the JAR, and restart the portal server.

  8. Click Save to store the definition of the application object in Personalization.

Attach a rule to a portlet

  1. Navigate to the portlet to which you want to apply the rule. The screen shots show the About WebSphere Portal portlet, which you can access by selecting Launch => About.
  2. Choose Edit Page Layout on the context menu for the page. The Edit Page Layout portlet is also accessible from the Administration pages in WebSphere Portal.
  3. Click Show Portlet Rule Mappings to enable the Personalization tools on the Edit Layout portlet
  4. Click on the context menu next to the text No rule mapped on the portlet where the rule should apply.
  5. In the rule editor, click the attribute link. The application object you added is now available in the rule editor. Each get method is exposed as a property in the rule editor.

Test the object

  1. Choose the My First Application Object => mySampleString property.
  2. Choose includes for the operator instead of is.
  3. Enter Hello for the value.
  4. Give your rule a name such as Test Application Object.
  5. Click the Preview tab to see that the rule returns Show, which indicatesthat the portlet will display for the current user.
  6. Select the New Rule tab, and change the value to something which is not included in the property value; for example, Hello World. Remember, the property value should be "Hello" + userName because this is what we coded in our application object. Hello World is not included in the value, and so the rule will return Hide.
  7. Click Preview to verify that the rule returns hide.
  8. Save the rule.
  9. View the page with the rule set each of the two ways, and verify that the portlet displays and is then hidden, respectively. When the portlet is hidden the page should display as follows, without the About WebSphere Portal portlet.
  10. Congratulations! You have used values returned from an application object to determine if a portlet is shown or hidden. This is a simple "Hello World" style example.

Conclusion

This part of the Extending Personalization series showed you how to create a simple application object. The values returned by the application object need to be more meaningful to write more meaningful rules. In Part 3, you create an application object which uses a Web service to return more meaningful data.

2 of 4 | Previous | Next

Comments



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=WebSphere
ArticleID=195532
TutorialTitle=Extending WebSphere Portal V6 personalization capabilities: Part 2. Creating a Hello World application object
publish-date=02142007
author1-email=jbrunn@us.ibm.com
author1-email-cc=

Table of contents


2 of 4 | Previous | Next

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).

Try IBM PureSystems. No charge.