AquaLogic .NET Portlet Toolkit WSRP Development Guide

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

Manipulating WSRP Properties Using the .NET Portlet Toolkit

To use WSRP properties in a portlet, configure the properties in the WSRP Producer and use the .NET Portlet API. To access and define properties, you can use a property attribute or a property collection.

  1. To define properties for use in a portlet, add entries for each property to the <portlet-property> element within the <portlet> element in the wsrp-producer.xml configuration file. For a full list of configuration elements, see WSRP Producer Configuration Elements (wsrp-producer.xml).
    		<property name="stockSymbols" type="xs:string" defaultValue="BEAS"/>
  2. Access the property using the .NET Portlet API. You can use a variety of methods to access and manipulate properties.
    • The property attribute provides type specific read-write binding of an WSRP property to a page member variable (field). The property attribute can be bound to fields with types of String, int, float, bool, or DateTime. Values for fields marked with a property attribute are set during the Load event of the Page; any changes are persisted during the EndRequest event of the HttpApplication.
      PortletPropertyAttribute has two optional properties:
      • Key: A string that provides the key name of the property to which the member variable is bound. If the property is defined for the portlet in the wsrp-producer.xml configuration file, the key value must match the value of the name attribute for the property. If this value is not defined, the key defaults to the name of the member variable on which it is defined. Key values must be unique within a page.
      • DefaultValue: A string that provides the value to use when the property is unavailable or has not yet been set. If this value is not provided, it will default to a value based upon the type of the variable as follows:
        Property Type Default value if not assigned
        string String.Empty
        int, long 0
        double, float 0.0
        bool false
        DateTime DateTime.MinValue
      Note: You must include one of the following access modifiers on all local fields that are bound to a property using a property attribute: [protected | internal | protected internal | public]. The modifier “private” is not supported. Since “private” is the default modifier if none is specified, the modifier must not be omitted.
      [PortletProperty(Key = "stockSymbols")]
      protected string stockSymbols;
      [PortletProperty(DefaultValue = "orange")]
      protected String colorSelection;
    • The property collection allows you to access all of the property values in the request in dictionary format. The WSRP.PortletPropertiesCollection is a true read-write collection that can be shared across pages that use Server.Transfer.

      In this example, a property collection is used to update the property value so it can be passed to another page. This sample code is taken from the Stock Quote Portlet example included with the .NET Portlet Toolkit.

      public partial class StockQuotePortlet2_Edit : System.Web.UI.Page
      	string StockSymbols
      		get { return WSRPPortletContext.Current.Portlet.Properties["stockSymbols"]; }
      		set { WSRPPortletContext.Current.Portlet.Properties["stockSymbols"] = value; }
          protected void Page_Load(object sender, EventArgs e)
              // set the stockSymbols textbox to the current property value
              if (!Page.IsPostBack)
      			stockSymbolsTextBox.Text = this.StockSymbols;
      	protected void SaveButton_Click(object sender, EventArgs e)
              // update the portlet property
      		this.StockSymbols = stockSymbolsTextBox.Text;
      		// set the mode back to view and transfer back to the view page
              WSRPPortletContext.Current.Portlet.Mode = "wsrp:view";
      		// Note: since we set the property value using the Properties collection
      		// it will be available on the destination page.

For a full description of the API, see the complete class documentation for the WSRP section of the Portlet API, installed into the Microsoft Visual Studio 2005 Combined Help Collection.

  Back to Top      Previous Next