Developing Portlets for WebSphere Portal Server
Using MyEclipse with WebSphere support, you can develop JSR Portlets and deploy to WebSphere Portal 6.1 and up. With 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
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.
- Click on the Servers view toolbar. Alternatively, right-click the Servers view, and select New>Server.
- Select the server connector and version to configure.
- Accept localhost as the host name or you can provide the fully qualified DNS name or IP address of the host machine.
- Accept the default server name or enter a new name. The server name identifies the server in the Servers view.
- Accept the default Create a new runtime environment option for first-time connector setup, and click Next.
- Enter the runtime environment information, including the path to the server installation.
- Select the JRE for your version of WebSphere Portal Server.
- Click Next to continue entering configuration information. These values are populated automatically from the server configuration.
- Click Next to select projects to configure on the server.
- Click Finish. The server is configured and appears 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.
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.
- Start the server by selecting the server and clicking 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.
- 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.
After you are logged in, a welcome page appears.
- Access the WebSphere Admin console by right-clicking the WebSphere Portal server in the Servers view and selecting Open Admin Console.
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.
- 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.
- Right-click the project, and choose MyEclipse>Project Facets>Install JSR Portlets Facet.
- Select the JSR 286 portlet specification and your WebSphere Portal version target runtime.
- Click Finish to complete the wizard. Portlet resources are added to the project. Libraries are added as part of the WebSphere Portal runtime library.
- Right-click the project and select New>Other. Type Portlet into the Wizards search field. Select Portlet, and click Next.
The 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.
- Click Next to specify several fields to add to portlet.xml and to optionally modify the file name of the generated JSP file.
- Click Finish to add the entry into portlet.xml, create the portlet Java file and also create the JSP view file.
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.
- Right-click the WebSphere Portal server in the Servers view, and select Debug.
If 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.
- In the MyEclipse Web Browser, open the portal home page at http://localhost:<your port>/wps/myportal.
- Log into the portal application, and click Edit Mode in the header.
- Click More, and select New Child Page.
- Give the page a name, and click Create.
- 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.
- Click the portlet, and click Add to Page.
- Click Save. The portlet displays the default message added to the .JSP file when it was created by the portlet wizard.
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.
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.