Channels ▼
RSS

.NET

.NET Development & the IBM WebSphere Portal Server

Source Code Accompanies This Article. Download It Now.


Sample JSR 168 Application in ASP.NET

One benefit of portals is the ability to perform integration at the UI layer, letting a portal page update multiple back-end systems simultaneously. To enable this, it is essential that portlets share data. WebSphere inter-portlet communication is facilitated by a broker that lets portlets exchange similarly typed properties. Essentially, the source portlet must define a WSDL file that specifies an output message (see Listing Six), while target portlets must define a WSDL file that specifies the related input message format (Listing Seven).

The WSDL files are fairly standard except within the operation node. Referring to Listing Six, you must define a named action and named parameter of the ActionRequest to which you attach your data as a named attribute. Within your .NET code, the data is applied to the attribute (Listing Eight).

<types>
  <xsd:schema targetNamespace="http://www.ibm.com/wps/search">
    <xsd:simpleType name="SearchType"><xsd:restriction base="xsd:string"></xsd:restriction></xsd:simpleType>
  </xsd:schema>
</types>
<message name="Search"><part name="Text" type="tns:SearchType"/></message>
<portType name="Service"><output message="tns:Search"/></operation></portType>
<binding name="Binding" type="tns:Service">
  <portlet:binding/>
  <operation name="Search">
    <portlet:action name="Action" type="standard" caption="action" description="Search text"
    actionNameParameter="ACTION_NAME"/>
    <output><portlet:param name="demo_text" partname="Text" boundTo="request-attribute" caption="text"/></output>
  </operation>
</binding>
Listing Six

<types>
  <xsd:schema targetNamespace="http://www.ibm.com/wps/search">
    <xsd:simpleType name="SearchType"><xsd:restriction base="xsd:string"></xsd:restriction></xsd:simpleType>
    </xsd:schema>
</types>
<message name="Search"><part name="Text" type="tns:SearchType"/></message>
<portType name="Service"><operation name="Result"><input message="tns:Search"/></operation></portType>
<binding name="Binding" type="tns:Service">
  <portlet:binding/>
  <operation name="Result">
    <portlet:action name="Action" type="standard" caption="action" description="Search text"
    actionNameParameter="ACTION_NAME"/>
    <input><portlet:param name="demo_text" partname="Text" caption="text"/></input>
  </operation>
</binding>
Listing Seven

PortletRequest pr = vmw.portlet.PortletUtils.getPortletRequest();
ActionRequest ar = pr as ActionRequest;
if (ar != null)
{
    string actionName = ar.getParameter("ACTION_NAME");
    if (actionName == "Action")
    {
        ar.setAttribute("demo_text", data);
    }
}
Listing Eight

The target portlet reads the data back from the ActionRequest (Listing Nine). The sample application demonstrates how to write two portlets that cooperate. The first portlet provides a search text box and a submit button (Search.aspx). Once clicked, the portlet loads a new page (SearchResults.aspx) with a DataGrid displaying the result of the search. In a real-world application, this would probably involve a web service call or database look-up; however, for simplicity the sample code simply loads some XML from a file of test data. Initially, the second portlet is empty, but when the user selects a row in the DataGrid, a number of values from the selected row are broadcast via the property broker and displayed in the page LinkedData.aspx. If the second portlet interrogates another database using this data, you have a simple method of integrating two systems at the UI layer.

ActionRequest ar = vmw.portlet.PortletUtils.getPortletRequest() as ActionRequest;
if (ar != null)
{
    string actionName = ar.getParameter("ACTION_NAME");
    if (actionName == "Action")
    {
        string demoText = ar.getParameter("demo_text").ToString();
    }   
}
Listing Nine

Once the portlets are deployed, they must be "wired" up. This process is an administrative task that defines to the WebSphere property broker the particular output message that the source portlet data is to send to the target portlet. The wiring tool is described in the WebSphere Portal documentation.

To run the sample, you need Visual Studio 2003 and a copy of Mainsoft for Java EE, Portal Edition (trial versions are available). The sample app (available online at www.ddj.com/code/) includes a Visual Studio.NET Java EE Portal project consisting of two simple portlets demonstrating inter-portlet communication as described in this article.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video