ALI Portlet Development

IDK Quickstart: Hello World Portlet - .NET

This simplified Hello World portlet example allows a user to set the message that is displayed within a portlet. The portlet code sends a Portlet setting to a Set Preferences page, which stores it in the ALI database and redirects to the portal, refreshing the portlet display. This page provides instructions and sample code for .NET developers.

Note: This example assumes you have installed the AquaLogic Interaction Development Kit (IDK). For details on installing the IDK, see the IDK Product Documentation. To download the IDK or ALI Logging Utilities, go to the ALUI Developer Center on dev2dev.

Step 1: Set Up a Custom IDK Project - Visual Studio

The steps below are for the Visual Studio .NET IDE.

  1. Start Visual Studio and click File | New Project | C# Projects | ASP.NET Web Service. Type an intuitive name in the Location field.

  2. Delete Service1.asmx and Web.config.

  3. In the new project, click File | Add Existing Item.

  4. Browse to the \idk\6.0\devkit folder in the IDK installation directory.

  5. In the File Types mask, click All Files.

  6. Select Web.config. Do not select the \bin directory. (Note: The .asmx files are required for Authentication Services (AWS), Content Crawlers (CWS), Profile Services (PWS), Search Services (SWS) and SCI settings, but not for portlets.)

  7. Click Open. You will be prompted to create a class file for each .asmx file; click No for each file.

  8. Add the IDK assemblies:

    1. In the Solution Explorer (usually in the upper right), you should see the project you created in Step 1.

    2. Right-click References and click Add Reference.

    3. Browse to the \idk\6.0\devkit\bin folder in the IDK installation directory.

    4. Select all the .dll files (Ctrl+A). These are the assemblies that resolve the references in the *.asmx files.

    5. Click Open | OK.

    6. In the Solution Explorer References, you should now see edk, openfoundation, etc.

  9. Click File | Add New Item to create new classes and complete your project.

Step 2: Create Portlet Pages

As noted above, this example creates a portlet that displays the current setting value and a form for changing the value. .NET portlets use a code-behind page to manipulate settings and redirect to the portal. (A separate Set Preferences page is not necessary.)

The Web form that makes up the portlet (portlet.asp) simply initiates the code-behind page (portlet.aspx.cs) and displays a form that prompts the user to enter a message.

Note: There is no need to include html, head and body tags; the portlet is displayed as part of the HTML table that makes up the portal page. This sample code is for VisualStudio 2005.

<%@ Page language="c#" CodeFile="portlet.aspx.cs" AutoEventWireup="false" Inherits="HelloWorld.WebForm1" ResponseEncoding="UTF-8"%>

<form id="Form1" method="post" runat="server">
<br>
<asp:label runat="server" id="settingsDisplay"></asp:label>
<br><br>
Enter your message:<br>&nbsp;&nbsp;&nbsp;
<asp:textbox id="PrefName" runat="server"></asp:textbox>
<br><br>
<asp:Button id="AddButton" runat="server" Text="Submit" ></asp:Button>
<br>
</form>

The code-behind page uses the IPortletRequest object to check for the setting, and the IPortletResponse object to add the setting to the portal database and redirect to the portal.

The code-behind page instantiates the IDK and uses the IDK Portlet API IPortletRequest object to check for a Portlet setting called "MyPref". If the setting has an associated value, the page sends it back for display. If the user entered a new value in the form, the portlet sends it back for display and uses the IPortletResponse object to store it in the portal database. When the setting value and portlet display are updated, the portal page is refreshed.

 

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Plumtree.Remote.Portlet;

namespace HelloWorld

{

      /// <summary>
/// Summary description for WebForm1.
/// </summary>

      public class WebForm1 : System.Web.UI.Page

      {

            //put member variables in protected scope as that is the most
//limited scope that the aspx page can see.

protected System.Web.UI.WebControls.Label settingsDisplay;
protected System.Web.UI.WebControls.TextBox PrefName;
protected System.Web.UI.WebControls.Button AddButton;
protected Plumtree.Remote.Portlet.IPortletRequest portletRequest;
protected Plumtree.Remote.Portlet.IPortletResponse portletResponse;
protected string settingKey = "MyPref";
protected string settingValue;
 

            private void Page_Load(object sender, System.EventArgs e)

            {
       }

            #region Web Form Designer generated code

            override protected void OnInit(EventArgs e)

            {

                  //
// CODEGEN: This call is required by the ASP.NET Web Form
// Designer.
//

                  InitializeComponent();
             base.OnInit(e);

            }

            /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>

            private void InitializeComponent()

            {  

                  this.AddButton.Click += new
System.EventHandler(this.AddButton_Click);
this.Load += new System.EventHandler(this.Page_Load);

            }

            #endregion

            private void AddButton_Click(object sender, System.EventArgs e)

            {

                  //get the setting value

                  IPortletContext portletContext =  
PortletContextFactory.CreatePortletContext(Request,Response);

                  portletRequest = portletContext.GetRequest();
             portletResponse = portletContext.GetResponse();

                  settingValue =
portletRequest.GetSettingValue(SettingType.Portlet,settingKey);

                  //set the label with the retrieved value
//(if it has already been set)

                  if(null != settingValue)

                  {
settingsDisplay.Text = "Old preference value is " +              
Server.HtmlEncode(settingValue) + "!";

                  }

                  if (PrefName.Text != "")

                  {

                        settingsDisplay.Text += "\New preference value is " +
Server.HtmlEncode(PrefName.Text)+ "!";

                        portletResponse.SetSettingValue(SettingType.Portlet,
settingKey,PrefName.Text);

                  }
}
}
}

Step 3: Deploying a Custom IDK Project

Note: These steps are for IDK version 6.0 and above. Previous versions of the IDK used the Deploy Servlet to generate a server-config.wsdd file. (For instructions, see the version 5.x developer documentation.) If you are using an old version of the server-config.wsdd file, the service endpoints below might be different.

After Visual Studio is set up for development against the .NET IDK as described above, follow the steps below to deploy new services. 

  1. Compile the class that implements the interface.

  2. If you do not already have a virtual directory in IIS for your services, add one using the steps below:

    1. Click Start | Settings | Control Panel | Administrative Tools | Internet Services Manager (Internet Information Services).

    2. Select Default Web Site.

    3. Click Action | New | Virtual Directory and type the name of your Visual Studio Location. Click Next twice. Type the path to the home directory for the IDK: <installdir>\idk\6.0\devkit\dotnet.

    4. Check both the Read and Run Scripts checkboxes if they are cleared (they should be checked by default). Click Next, then click Finish.

  3. Copy the compiled class files to the \bin folder in the <installdir>\idk\6.0\devkit\dotnet directory.

Next Steps

To view a portlet in the portal, you must configure portal objects as described in Configuring Portlets in the Portal.  Note: The Set Preferences page must be included in the gateway space.

For more information on the IPortletRequest and IPortletResponse objects, see IDK Proxy and Portlet APIs.

Forms and functions must be uniquely named. Always use the Portlet ID in form and function names to avoid name collisions with other portlets on the portal page. You can append the Portlet ID using the pt:namespace and pt:token tags, as shown in the code below. (Adaptive Tags can be used on any gatewayed page. For details, see Adaptive Pagelets: Adaptive Tags.)

<pt:namespace pt:token="$$TOKEN$$" xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/'/>
<a onclick="doStuff$$TOKEN$$();" href="#">do stuff</a>
<script>
   function doStuff$$TOKEN$$() {
     alert("hello");
   }
</script>

Valid values for the token must be in the ASCII range 0x21 to 0x7E, excluding "<". The scope of the token runs from the tag defining it to the end of the file; you cannot use a token prior to defining it. A second pt:namespace tag with a different token redefines it; two tokens cannot be defined at the same time.

The Adaptive Portlet Toolkit provides tools for building cohesive applications within a portal page. Adaptive portlets work dynamically to react to user actions and refresh content within the page. For details on adaptive portlets, including Adaptive Tags and the ALI Scripting Framework, see Adaptive Pagelets.

The Programmable Remote Client (PRC) allows you to embed components and functions into any Web application delivered through the ALI framework. The PRC provides APIs for a wide range of functionality, including portal object management, search, and content processing, as well as ALI Collaboration and ALI Publisher operations. For details, see Remote APIs.