Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

20
Part II – Portlet Development When you are standing on the top of Sears Tower, you have a pretty good view of the entire city of Chicago. To take a snapshot of a city’s section, you need to use a camera with good zoom in capability. This similar analogy can be applied to a portlet. A portlet gives you a snapshot view of an application. It can be rendered in a small container window within the portal user interface. G6 portal makes it really easy to develop portlets. For many development projects, the IDK 1 should be used. It is a set of libraries allowing a portlet application to leverage many of portal’s built-in functions, such as session management, persistence, and dynamic HTML controls. We will begin by writing the HelloWorld Portlet. 1 AquaLogic User Interaction Development Kit (IDK), forrmerly called Enterprise Development Kit (EDK), and other developer libraries can downloaded from BEA’s dev2dev website at http://edocs.bea.com/alui/devdoc/docs60/index.html#References/API_Libraries/ index.htm 1

description

This is the chapter 2 of the Aqualogic Developer's Notebook. It demonstrate the basic concept about portlet development.

Transcript of Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

Page 1: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

Part II – Portlet DevelopmentWhen you are standing on the top of Sears Tower, you have a pretty good view of the entire city of Chicago. To take a snapshot of a city’s section, you need to use a camera with good zoom in capability.

This similar analogy can be applied to a portlet. A portlet gives you a snapshot view of an application. It can be rendered in a small container window within the portal user interface.

G6 portal makes it really easy to develop portlets. For many development projects, the IDK1 should be used. It is a set of libraries allowing a portlet application to leverage many of portal’s built-in functions, such as session management, persistence, and dynamic HTML controls.

We will begin by writing the HelloWorld Portlet.

1 AquaLogic User Interaction Development Kit (IDK), forrmerly called Enterprise Development Kit (EDK), and other developer libraries can downloaded from BEA’s dev2dev website at http://edocs.bea.com/alui/devdoc/docs60/index.html#References/API_Libraries/index.htm

1

Page 2: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

Chapter 1 - HelloWorld Portlet In our first example, we will write the HelloWorld portlet. Then, we will add dynamic contents to that portlet and show time and user’s IP address.

1 SetupIn the G6 portal, portlets are remote objects that get processed by the portal gateway. Portlets are web services objects and require you to register a remote server in the portal. (That is why EDK prefixes are either com.plumtree.remote or Plumtree.Remote.)

1.1 For Java developer(Create Java project)We will use the Tomcat application server in the NetBeans 5 IDE.

1. Select the <File> menu, and choose <New Project>. The following dialog box will display on your screen.

2. Select <Web Application>, and click next button.

2

Page 3: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

3. Type in the project name <helloworld> and choose an appropriate directory to save the project. (I am using c:\My Documents\g6_book\java_src directory to hold all my java projects related to this guide.) Click Finish to create this project. (We are not using JSF or Struts. The next window can be ignored.)

4. Right click on the <helloworld> node and choose new JSP page.

5. Type in <helloworld> for the JSP File Name. (The existing index.jsp can safely deleted.)

3

Page 4: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

6. Replace the page content with following content. <%@page contentType="text/html"%>

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Hello World Page</title> </head> <body>

<h1>HelloWorld Page</h1> </body></html>

4

Page 5: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

7. Launch your application by right click on the <helloworld.jsp> file and choose <Run File>.

8. Depending on how you configured the NetBeans IDE, either IE or Mozilla Firefox browser will launch. In the address bar, you will find < http://localhost:8084/helloworld/helloworld.jsp >. This tells you on which port number your Tomcat app server is running.

5

Page 6: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

9. Alternatively, you can find your Tomcat’s port number by clicking on the NetBeans’ Runtimes tab and then right click on the Bundled Tomcat’s properties.

6

Page 7: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

1.2 For .NET developerWe will use IIS application server.

1. We will first create a folder to hold all our project files. (I am using the C:\My Documents\g6_book\asp_src directory.) Note: It is crucial to give you IIS account (ASP.NET user) appropriate permissions. You can right click on the folder and choose security tab to set it. Without that, your IIS may not work and gives you security errors.

7

Page 8: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

2. Create a new virtual directory with the IIS manager. Give it a descriptive name. The direct URL to access our applications will become http://localhost/<applicationname>

8

Page 9: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

3. Next, we launch Microsoft Visual Studio .NET IDE. Click <File> … <New Project>.

4. Choose ASP.NET Web Application and set the location to store files, e.g. http://localhost/helloworld

9

Page 10: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

5. Right click on the project, and choose <Add Web Form>. This creates the ASPX page and the C# code behind file.

10

Page 11: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

6. Change the page layout of the <helloworld.aspx> file to FlowLayout.

7. Replace the HTML content of the page with the following.<%@ Page language="c#" Codebehind="helloworld.aspx.cs" AutoEventWireup="false" Inherits="helloworld.helloworld" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML>

<HEAD><title>helloworld</title>

</HEAD><body>

HelloWorld ASPX page</body>

</HTML>

11

Page 12: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

8. Build the project by pressing Control + Shift + B keys together. And, browse to the web page.

1.3 Show web page as a portletNext, we will display the helloworld.jsp page as a portlet inside the G6 portal. To do this, we need to set up a remote server and a web service representing the <helloworld.jsp> page.

1. Log into the portal as the “Administrator”, click on the <Administration> tab. And, create an <Administrator Folder> to hold your objects, e.g. remote server, web services, portlet. You can name this folder as <myJavaProject> or <myASPProject>.

12

Page 13: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

2. Inside this folder, create a remote server for your projects.

3. The remote server’s base URL and port number should match your Tomcat or IIS settings. (I prefer separately appending my project’s name to the end of the remote server’s base URL. That allows me to reuse a remote server object for multiple projects.) Give the remote serve a clear and concise name, e.g. <My Java Remote Server> or <My ASP Remote Server> and save it.

13

Page 14: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

4. Now create a web service for your <helloworld.jsp> or <helloworld.aspx> page.

a. On the Main Setting page, you can select your Remote Server <My Java Remote Server> or <My ASP Remote Server> and URL to call your <helloworld.jsp> or <helloworld.aspx> page. As a developer, you may want to debug and step through you application. For that convenience reason, it is suggested to set both Portlet and Gateway Timeouts to long time. In my example, both timeouts are set to 20 minutes.

14

Page 15: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

b. On the HTTP Configuration page, set minimum and maximum cache time to 0 seconds and deselect the “Suppress errors where possible (show cached content instead)” checkbox.

As a developer, you want your portlet to reflect your application’s latest state. However, in the production environment, you will want your portlet to be cached for performance reason.

Click on the <Add Gateway Prefix> link and enter “.” in the textbox. You can gateway contents on your remote server by:

- A specific filehttp://<remoteserver>/helloworld/portlet.jsp- A directory and everything below ithttp://<remoteserver>/helloworld/.- The entire remote serverhttp://<remoteserver>/helloworld/

Note: Gateway URLs are case sensitive Special case - If you want to specify an URL that is not relative to

the current remote server, just enter the complete URL in the Web Service editorhttp://<remoteserver>/helloworld/http://myotherserver:9000/app

If you are using IIS as your application server, make sure you had given appropriate permissions to your ASP.NET user.

15

Page 16: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

5. Create a new portlet from your web service.

Both “Narrow” and “Wide” type portlets can be placed on the regular pages.

“Header” and “Footer” type portlet can be useful for pluggable navigation and is used through the portal’s “experience definition”.

“Content Canvas” type portlet can be used to display a company’s or a community’s custom logo.

16

Page 17: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

6. Add the portlet to a page.

1.4 Add dynamic content

1.4.1 Add time stamp & show browser’s IP addressOur next step is to add some dynamic contents on the portlet page. We will start by showing the server’s current time when this page was loaded. We also want to show browser’s IP address.

Java:Modify the helloworld.jsp page.

7. <%@page contentType="text/html"%>8. <html>9. <head>10. <meta http-equiv="Content-Type" content="text/html; charset=UTF-

8">11. <title>Hello World Page</title>12. </head>13. <body>14. HelloWorld.jsp Page <br/>

17

Page 18: Chapter 2 - Understanding ALUI Portal with helloworld, (Aqualogic Developer's Notebook)

15. <%="The Current time is: " + new java.util.Date()%>16. <br>17. <%18. out.print( "Browser's IP address is " + request.getRemoteAddr() );19. %>20. </body>21. </html>

ASPModify the helloworld.aspx page.

22. <%@ Page language="c#" Codebehind="helloworld.aspx.cs" AutoEventWireup="false" Inherits="helloworld.helloworld" trace="false" %>

23. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >24. <HTML>25. <HEAD>26. <title>helloworld</title>27. </HEAD>28. <body>29. HelloWorld ASPX page<br>30. <%31. Response.Write ("The current time is: " +

DateTime.Now.ToString());32. %>33. <br>34. <% 35. Response.Write("Browser's IP address is: " +

Request.ServerVariables["REMOTE_ADDR"]);36. %>37. </body>38. </HTML>

Optionally, the trace option can be set to true or false, to aid debugging the ASP page.

1.5 Bonus Questions How do you pass parameters to a portlet? How do you set cookie with either a JSP or ASPX file? How do you keep persistent data across several pages?

18