Login

Building Your First WSRP Portlet  

Product version:

4.61

Document version:

1.0

Document last saved:

22-11-2006

 

Purpose

This document will guide you through the first basic steps of building your own WSRP portlet. This document is of a technical nature and is mainly of interest to EPiServer developers.


Table of Contents

Introduction

Create the Hello EPiServer Portlet


    - Registration   
    - The User Control
    - Styles

Modes and States

    - Modes
 

    - Window States

WSRP Interaction

    - Interact Through the Portal

    - Adding Interaction to HelloWorld

    - Resources

Summary



Introduction

A good way to start learning about how to implement WSRP is to create a small WSRP sample portlet. This technical note guides you through a short "hello world" example and illustrates the basic functionality of a WSRP portlet.

Create the Hello EPiServer Portlet

Registration

All portlets that are available in an EPiServer application must be registered. It is recommended that you do this during the Application Start Event. The minimum code needed to do the registration is displayed below.

Note The registration will point out which user control to load when a consumer calls the portlet.

// Define the markup types

string[] modes                        = new string[] { "wsrp:view" ,

                                                       "wsrp:edit" ,

                                                       "wsrp:help" ,

                                                       "wsrp:preview"};

string[] windowstates                 = new string[] { "wsrp:normal" ,

                                                       "wsrp:minimized",

                                                       "wsrp:maximized",

                                                       "wsrp:solo"};

MarkupType[] markupTypes              = new MarkupType[] {

                     new MarkupType( "text/html" , null , modes , windowstates) };

// Register the portlet

IPortlet portlet = UserControlPortletInvoker.RegisterPortlet(

                    "templates/wsrp/portletcontrols/wsrpHelloWorldControl.ascx" );

// Set the title and markup types of the registered portlet

portlet.DefaultDescription.title      = new LocalizedString("Hello World","EN");

portlet.DefaultDescription.markupTypes = markupTypes;

If the producer is added to another EPiServer the following services will be displayed: 

The User Control

The user control defined when the portlet is registered will be used to create the markup sent to the consumer. In this first Hello World sample, the user control is very simple. It only contains the text “Hello World!”. No code behind is required.

Hello World!

Of course the sample will not be useful in real life, because it does not support any functionality or graphic design specified by the WSRP standard.

Styles

As mentioned above, the user control will generate a block of markup that will be displayed in the portal when the portal calls getMarkup. Add some more HTML elements to the control. To follow the WSRP specification, each element should be based on a valid CSS class defined in WSRP. Read more about the approximately 40 predefined styles in the WSRP Specification (http://www.oasis‑open.org/committees/download.php/3343/oasis‑200304-wsrp-specification-1.0.pdf).

<p class="portlet-section-header">This header section uses the style "portlet-section-header"</p>

<p class= "portlet-section-subheader">This sub-header section uses the style "portlet-section-subheader"</p>

<p class= "portlet-section-body">This body section uses the style "portlet-section-body"</p>

<form action="#">

<p align="center" class="portlet-section-header">A Sample Form</p>

<center>

  <table>

    <tr>

      <td class="portlet-form-label">This form label uses the style "portlet-form-label"</td>

    </tr>

    <tr>

      <td class="portlet-form-label" align="center"><input name="Submit" type="button" class="portlet-form-button" value='Button  uses the style "portlet-form-button"'/></td>

    </tr>

  </table>

</center>

</form>

 

Because of the standardized styles used in the markup, the final output will be according to the graphical standard defined in the portal. This will give the end user a homogenous site, even if all parts are produced through different producers.

Modes and States

Modes

The WSRP standard defines four different modes – view, edit, preview and help. During registration, each portlet will be able to define which modes it supports. The portal will then display a toolbar accordingly. The selected mode can “behave” differently.

wsrp:view

The normal mode of a portlet is wsrp:view mode. In this mode content is shown or a service is used. The end user can also enter data and follow hyperlinks in wsrp:view mode. Typically this is done when a service needs interaction from the end user, such as entering form data or when the end user navigates within a set of information.

wsrp:edit

Normally a portlet has a wsrp:edit mode in which the end user can do personalized settings of the service. For example, he or she can define how information from behind should be shown, enter configuration data of a service or enter a personalized title of the portlet.

wsrp:preview

The wsrp:preview mode can be used to give a preview of content or a service related to the settings done in the wsrp:edit mode. The wsrp:preview mode is seldom used.

wsrp:help

Each portlet can present its own help function and it is shown in the wsrp:help mode.

Window States

Each portlet can be shown in different window states – normal, maximized, minimized and solo. The portlet can often have different content (markup) in the different states. The portal gives the end user a possibility to gain an overview of a service when it is in normal state (small). When the user wants to start working with the service and maximizes it, it will then show a complete set of tools and information.

wsrp:normal

When a portlet is shown in wsrp:normal window state, the area showing information is often limited. A typical use of the wsrp:normal window state is to show an overview or a short summary of the information/service of the portlet.

wsrp:maximized

In wsrp:maximized window state, the portlet will use the whole area of the portal workspace.

wsrp:minimized

When a portlet is in wsrp:minimized window state, it will make room for other portlets on the portal page.

wsrp:solo

The wsrp:solo window state is implemented differently in different portal environments. In some cases it uses the full browser window and in some cases the portlet opens itself in a new window. The wsrp:solo window state is seldom implemented.

WSRP Interaction

Interact Through the Portal

One of the most important things with the portal concept based on WSRP is that all interaction to a portlet is handled through the portal. Every click on a navigational link (referring to a local resource) and every form posting will result in a call to the portal. The portal will then call the portlet based on the arguments in the URL. The action described is called a Blocking Interaction. The portal will now contact the producer and tell it that a Blocking Interaction has been initiated for the specific portlet. The portal also sends another request to the producer asking for new markup (getMarkup) for the portlet.

Adding Interaction to HelloWorld

Add the following line to HelloWorld.ascx and save the file.

<%= DateTime.Now.ToLongTimeString() %>

When you now click the View mode button in the portal, it will communicate with the producer portlet and will result in an update of the new time-tag in the portlet.

When you click the button, however, nothing happens. This is because EPiServer has not converted the URL – it is not a relative URL. All relative URLs in a markup, generated by the user control, will be converted to WSRP links. All other links are left as they are. Add the following lines to HelloWorld.ascx:

<a href="/">Internal link</a>

<a href="http://www.episerver.com">External link</a>

When you now look at the content in the portal, the first “Internal link” has been converted to a WSRP link. Clicking the link will result in an update of the time-tag indicating that the portlet has received a Blocking Interaction call. Clicking the "External link” will instead open the site, as external links are not converted.

Resources


The last thing we will add to hello world is an image reference. IMG tags are also converted by EPiServer and all resources (like images or documents) are loaded through the portal using its built-in resource proxy.

Add the following image tag to your .ascx file.

Note  You may have to adjust the URL, if you have installed EPiServer in a virtual directory.

<img src="/images/communication.jpg" />

Summary

You have now created a small working WSRP portlet that includes modes, window states, resources links and navigational links. The next step now is to go through the samples included in the sample templates in EPiServer 4.60 and later. They can be found at \templates\wsrp\portletcontrols. These samples include a full example of a working WSRP portlet.

EPiTrace logger