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

Implementing WSRP Portlet Modes Using the .NET Portlet Toolkit

To access or update portlet mode for a WSRP portlet, use the PortletInfo.Mode property in the .NET Portlet API.

WSRP portlets can expose functionality in different modes, with each mode catering to a particular function. Many WSRP Consumers provide functionality to let users request portlet markup in various modes. There are 4 “standard” modes defined in the WSRP 1.0 specification:
  • wsrp:view
  • wsrp:edit
  • wsrp:help
  • wsrp:preview
WSRP-compliant portlets must support the wsrp:view mode. Producers can also support custom modes, defined as URIs.

Two steps are required to implement portlet modes:

  1. Configure the supported portlet modes in the wsrp-producer.xml file.

    The supported portlet modes for each portlet are specified in the wsrp-producer.xml configuration file as children of the <supports> element as shown in the example below. For a custom mode, the description may either be included in-line in the <supports> element or as part of a top-level <custom-portlet-mode> definition.

    Each supported mode must have an associated URL. Either include the URL for the mode within the <url> node, or use the idref attribute to refer to a URL defined as a child of the <portlet> element. If neither an URL nor the idref is specified, the URL is assumed to be the first one found for the portlet.

    If the <supports> element contains multiple mime-type elements, the portlet mode support applies to each of the mime-types included. To specify different portlet modes on a per mime-type basis, add multiple <supports> elements to the portlet definition, each with a different mime-type. If the same mime-type is listed more than once, an exception is thrown.
    Note: If the <portlet-mode> element is omitted, the portlet is assumed to support the wsrp:view portlet mode. If wsrp:* is specified, it implies all of the standard wsrp: values. Support for “wsrp:view” is always assumed, even if it is not explicitly indicated.
    <portlet>
    	...
    	<url id="default">http://localhost:4614/WSRPSamples/StockQuotePortlet.aspx</url>
    	...
    	<supports>
    		<mime-type>text/html</mime-type>
    		<portlet-mode>
    			<name>wsrp:view</name>
    			<url idref="default"/>
    		</portlet-mode>
    			
    		<portlet-mode>
    			<name>wsrp:edit</name>
    			<url idref="default"/>
    		</portlet-mode>
    
    		<portlet-mode>
    			<name>wsrp:help</name>
    			<url idref="default"/>
    		</portlet-mode>
    
    		<portlet-mode>
    			<name>wsrp:preview</name>
    			<url>http://localhost:4614/WSRPSamples/StockQuotePortlet_preview.aspx</url>
    		</portlet-mode>
    
    		<portlet-mode>
    			<name>urn-myproject-portletmodes:search</name>
    				<url>http://myhost/myportlet/search.aspx</url>
    				<description lang="en">shows the search view for the portlet</window-state>
    		</portlet-mode>
    		...
    	</supports>
    ...
    <custom-items>
    	<custom-portlet-mode>
    		<name>urn-myproject-portletmodes:search</name>
    		<description lang="en">shows the search view for the portlet</description>
    	</custom-portlet-mode>
    </custom-items>
    ...
    </portlet>				
    
  2. Implement the portlet mode in the portlet code.

    A portlet can access the portlet mode via the PortletInfo.Mode property during any portlet request, but may only change the current mode during a performBlockingInteraction (typically, an ASP.NET form postback). The new portlet mode is returned in the response to the WSRP Consumer. If the WSRP Consumer does not understand the mode returned by a portlet, it can ignore it. If the WSRP Consumer requests a mode that the portlet does not understand, the WSRP Producer will map to wsrp:view.

    The example below toggles the display of panels based on the portlet mode. This code is taken from the StockQuotePortlet.aspx.cs sample included with the .NET Application Accelerator 1.1 MP1.

    ... 
    protected void Page_PreRender(object sender, EventArgs e)
        {
            if (WSRPPortletContext.Current.Portlet.Mode == "wsrp:edit")
            {
                editPanel.Visible = true;
                helpPanel.Visible = false;
                // set the stockSymbols textbox to the current property value
                stockSymbolsTextBox.Text = stockSymbols;
                viewPanel.Visible = false;
            }
            else if (WSRPPortletContext.Current.Portlet.Mode == "wsrp:help")
            {
                editPanel.Visible = false;
                helpPanel.Visible = true;
                viewPanel.Visible = false;
            }
            else // view mode
            {
                editPanel.Visible = false;
                helpPanel.Visible = false;
                viewPanel.Visible = true;
                // display the quotes
                DisplayQuotes(stockSymbols);
            }
        }
    ...

  Back to Top      Previous Next