Developing Portlets for WebSphere Portal Server

Using MyEclipse with WebSphere support, you can develop JSR Portlets and deploy to WebSphere Portal 6.1, 7.x, or 8.x. With this tutorial, you’ll develop a default portlet using the New Portlet wizard. Using WebSphere Portal server requires a MyEclipse Blue or Bling subscription. In this tutorial, you’ll learn to:

  • Configure the WebSphere Portal Server connector
  • Access the Portal Server from within MyEclipse
  • Create a portlet project
  • Deploy and test a portlet

Duration Time: 30 Minutes

Start Tutorial Now

Don't have MyEclipse? Download Now

1. Required WebSphere Portal Server Installation Information

Although this tutorial walks through the process of developing JSR Portlets, MyEclipse for WebSphere supports developing all types of Java EE applications including Web, EJB, and web services that you can deploy to WebSphere Portal because it is running on top of WebSphere app server.

This tutorial was created using WebSphere Portal 8.0. The installation of WebSphere Portal 8.0 server was done using the typical installation type, which means that we not only installed WebSphere Portal server but installed a new copy of the WebSphere app server to run the portal server.

 For this tutorial, you'll need the following values to configure WebSphere Portal in MyEclipse.

  • WebSphere app server installation location 
  • WebSphere profile installation location used for portal server 
  • WebSphere Portal Server installation location 

The WebSphere Portal installation summary contains the required values.

2. Configure the WebSphere Portal Connector

  1. Click new_server_icon on the Servers view toolbar. Alternatively, right-click the Servers view, and select New>Server.

    Available application servers
  2. Select the server connector and version to configure.
    add_new_server_wps
    Choosing WebSphere Portal Server connector
  3. Accept localhost as the host name or you can provide the fully qualified DNS name or IP address of the host machine.
  4. Accept the default server name or enter a new name. The server name identifies the server in the Servers view.
  5. Accept the default Create a new runtime environment option for first-time connector setup, and click Next. 
    configure_new_wps
    WebSphere Portal Server connector configuration page
  6. Enter the runtime environment information, including the path to the server installation.
  7. Select the JRE for your version of WebSphere Portal Server. 
  8. Click Next to continue entering configuration information. These values are populated automatically from the server configuration.
    configure_new_wps_pg2
    Additional configuration details
  9. Click Next to select projects to configure on the server. 
    deploy_portal_proj
    Adding projects to the server
  10. Click Finish. The server is configured and appears in the Servers view.
    new_portal_server
    New server in the Servers view

Note: You can edit server configurations at any time by double-clicking the server name in the Servers view to open the Server Configuration editor.

3. Access the Portal Server from MyEclipse

Now that the WebSphere portal server is in the Servers view, it acts as any other server in MyEclipse. This section describes how to start the portal server and access it from the embedded MyEclipse browser.

  1. Start the server by selecting the server and clicking runServerIcon on the Servers view toolbar.

    During server startup, the console indicates the WebSephere Portal server has started. This means you have correctly configured the connector. If you don't see these messages, you likely have a misconfigured server connector.
    console_output
    WebSphere Portal 8.0 running from within MyEclipse
  2. After the server is started, access the portal home page in the MyEclipse Web Browser using the address http://localhost:<your port>/wps/myportal to ensure the portal application is available.

    Log in using the same username and password you provided when configuring the server.
    portal_1
    WebSphere Portal login pageAfter you are logged in, a welcome page appears.
  3. Access the WebSphere Admin console by right-clicking the WebSphere Portal server in the Servers view and selecting Open Admin Console.
    admin_0
    Opening the Admin consoleadmin_1
    WebSphere app server admin console home 

4. Create a Portlet Project for WebSphere Portal

To develop a JSR portlet to deploy to WebSphere Portal 7.0 or 8.0, you first need to create a web project, add JSR 286 Portlet facets to it, and then create your portlets before deploying to the portal server.

Note: For WebSphere Portal 6.1, select JSR 168 when adding the facet.

  1. Either create a new or select an existing MyEclipse web project, using your WebSphere Portal Server version as the target runtime.

    Note: For WebSphere Portal 7.0, your Web project must use the Web 2.5 specification, rather than Web 3.0. WebSphere Portal 8.0 supports Web 3.0.
  2. Right-click the project, and choose MyEclipse>Project Facets>Install JSR Portlets Facet.
  3. Select the JSR 286 portlet specification and your WebSphere Portal version target runtime.addPortletCapabilitiesWindow
    Adding Portlet facets
  4. Click Finish to complete the wizard. Portlet resources are added to the project. Libraries are added as part of the WebSphere Portal runtime library.
    portal_project
    Portal project structure
  5. Right-click the project and select New>Other. Type Portlet into the Wizards search field. Select Portlet, and click Next.
    new_portlet
    New Portlet wizardThe first page of the New Portlet wizard looks much like a New Servlet wizard. However, there are some important fields to pay attention to, specifically the Template to use field and the doView() and doEdit() checkboxes.
    new_portlet1
    Entering package and portlet names and selecting a template
  6. Click Next to specify several fields to add to portlet.xml and to optionally modify the file name of the generated JSP file. 
    new_portlet2
    Configuring Portlet properties
  7. Click Finish to add the entry into portlet.xml, create the portlet Java file and also create the JSP view file.
    new_portlet3
    Portlet.xml file

5. Deploy the Portlet

After you create portlets, they are ready to be deployed to WebSphere Portal. Deployment for portlets is identical to normal Java EE Web application deployment in MyEclipse. When you deploy to WebSphere Portal, MyEclipse detects that your project contains portlets and WebSphere Portal server-specific deployment happens automatically so the project's portlets are correctly registered with the portal.

  1. Right-click the WebSphere Portal server in the Servers view, and select Debug.
    debug1
    Starting the server in debug modeIf your project is not already deployed, right-click the server, and select Add/Remove Deployments. With your portlet project deployed, next add the portlet to a new portal page and test it. 
  2. In the MyEclipse Web Browser, open the portal home page at http://localhost:<your port>/wps/myportal.
  3. Log into the portal application, and click Edit Mode in the header.
  4. Click More, and select New Child Page.
    portal_deploy_3
    Adding a new page on which to place the portlet
  5. Give the page a name, and click Create.
  6. Click the Content tab, enter your portlet name in the Search field, and be sure you are searching All content. The results display your deployed portlet.
    portal_deploy4
    Searching for the deployed portlet
  7. Click the portlet, and click Add to Page.
    portal_deploy5
    Adding the portlet to the new page
  8. Click Save. The portlet displays the default message added to the .JSP file when it was created by the portlet wizard.
    portal_deploy_6
    Portlet as it appears on the portal server

6. Test and Debug the Portlet

Now that you have a portlet application, you can test and debug it like any other Java EE Web application deployed to WebSphere app server. When you add or view portlet content on your portlet page, breakpoints you set are hit, and you can debug the application. The following image shows the MyEclipse Java debugger stopped at a breakpoint in the portlet class.

debug2
Debugging a portlet class

7. Undeploying a Portlet

Undeployment is very similar to deployment in that to correctly delete the portal app, the server has to be running. When you undeploy the portal, configuration change happens first, and then the Java EE application (WAR) is undeployed from the server. 

To undeploy the portlet, expand WebSphere Portal in the Servers view, right-click the portlet app, and click Add/Remove Deployments.

undeploy_portal_project
Undeploying the portlet

8. Resources