AquaLogic User Interaction Development Guide

     Previous Next  Open TOC in new window   View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Creating a Custom Pagelet with the .NET IDK Proxy API

This example creates a simple pagelet that displays information from the proxy, including setting values. .NET pagelets use a code-behind page (.aspx.cs) to retrieve settings and a web form (.aspx) to display the pagelet content.


  1. Before writing any code, create a new IDK project as described in Setting Up a Custom .NET IDK Project.
  2. In the new project, implement your code. The example below uses a code-behind page and a web form.

The code-behind page (IDKPagelet.aspx.cs) instantiates the IDK and uses the IProxyContext interface to retrieve IProxyRequest and IProxyUser objects to access information about the user and the settings associated with the pagelet.

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; 
using System.Xml; 
using System.Text; 
using Bea.Alui.Proxy;

namespace IDKProxyWS
{
/// <summary>
/// Hello World Pagelet
/// </summary>
   public class IDKPagelet : System.Web.UI.Page 
   {
      public String name; 
      public bool isGuest; 
      public int userID; 
      public String envType; 
      public String payload; 
      public String Att1,Att2; 
      public String SessionVar;
      private void Page_Load(object sender, System.EventArgs e
      {
         // Put user code to initialize the page here
         InitializeCSP();
      }
      private void InitializeCSP()
      {
         IProxyRequest proxyRequest; 
         IProxyResponse proxyResponse; 
         IProxyUser proxyUser; 
         IProxyContext proxyContext; 
         ProxyContextFactory factory; 
         HttpRequest request = HttpContext.Current.Request; 
         HttpResponse response = HttpContext.Current.Response;

         try
         {
            factory = ProxyContextFactory.getInstance(); 
            proxyContext = factory.CreateProxyContext(request, response); 
            proxyRequest = proxyContext.GetProxyRequest(); 
            proxyResponse = proxyContext.GetProxyResponse(); 
            envType = proxyRequest.GetEnvironment().GetType().ToString();
            proxyUser = proxyRequest.GetUser(); 
            isGuest = proxyUser.IsAnonymous(); 
            name= proxyUser.GetUserName(); 
            userID = proxyUser.GetUserID();

            Att1 = (String)proxyRequest.GetSetting('attr1');
            Att2 = (String)proxyRequest.GetSetting('attr2');
            Att2 = (String)proxyRequest.GetSetting('SessionVar');

            byte[] bpayload = proxyRequest.GetPayload().GetText()
            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding()
            payload = enc.GetString(bpayload)
         }  
         catch(Bea.Alui.Proxy.NotGatewayedException e)
         {
         }
      }
   }
#region Web Form Designer generated code
... 
#endregion
}
The web form that displays the pagelet (IDKPagelet.aspx) displays the information retrieved by the code-behind page above.
<%@ Page Language='c#' runat='server' CodeBehind='IDKPagelet.aspx.cs' AutoEventWireup='false' inherits='IDKProxyWS.IDKPagelet' %>
<%@ import Namespace='System.Collections' %> 
<%@ import Namespace='System.Web' %> 
<%@ import Namespace='System.Web.UI' %>

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN' >
<html>
<head>
<title>IDKPagelet</title>
<meta name='GENERATOR' Content='Microsoft Visual Studio .NET 7.1'>
<meta name='CODE_LANGUAGE' Content='C#'>
<meta name='vs_defaultClientScript' content='JavaScript'>
<meta name='vs_targetSchema' content='http://schemas.microsoft.com/intellisense/ie5'>
</head>

<body MS_POSITIONING='GridLayout'> 
<span xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/'>

Proxy Pagelet <BR>
<%
   Response.Write('IDK Proxy Pagelet<BR>');  
   Response.Write('Environment Type ' + envType + '<BR>'); 
   Response.Write('Guest User? ' + isGuest + '<BR>'); 
   Response.Write('User Name: ' + name + '<BR>'); 
   Response.Write('User ID: ' + userID + '<BR>'); 
   Response.Write('<P>');

   Response.Write('Pagelet Attributes:<BR>');
   Response.Write('Attribute1: ' + Att1 + '<BR>');
   Response.Write('Attribute2: ' + Att2 + '<BR>')
   Response.Write('SessionVar: ' + SessionVar + '<BR>')
   Response.Write('<P>')

   Response.Write('Pagelet XML Payload:<BR>'); 
   Response.Write('<textarea name=xml cols=80 rows=6>' + payload + '</textarea>'); 
   Response.Write('<P>');
%>
</span>
</body>
</html>

  Back to Top      Previous Next