Oracle WebCenter Interaction Web Service 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 Oracle WebCenter Interaction Portlet with the .NET Oracle WebCenter Interaction Development Kit (IDK) Portlet API

This simplified Hello World portlet example allows a user to set the message that is displayed within a portlet.

Before writing any code, create a new Oracle WebCenter Interaction Development Kit (IDK) project as described in Setting Up a Custom .NET Oracle WebCenter Interaction Development Kit (IDK) Project.

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. 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. The sample code below is for VisualStudio 2005.
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.
<%@ 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 instantiates the Oracle WebCenter Interaction Development Kit (IDK) and uses the 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);

                  }
}
}
}

After you have completed the portlet code, deploy your custom project as described in Deploying a Custom .NET Oracle WebCenter Interaction Development Kit (IDK) Project in IIS.


  Back to Top      Previous Next