# Oracle9iAS Portal Developer Kit (PDK)
Building the Web Services Sample Portlets using URL Parameters

Creation Date: | Sep 30, 2002
Status: | Draft (2)
Version: | PDK Release 2, (9.0.2.5 and later)

# Introduction

This document explains how to configure the URL Parameter drives Web Sample sample. This sample portlet takes a Zipcode as input and drives the other portlets in the same page. You can also get a basic understanding on rendering Web Services in portlets from the article, Understanding Web Services for Portlets.

# Assumptions

- You have installed PDK as described in the article Installing the PDK Framework and samples

- You have installed PDK Web Services as described in Installing the Web Services Sample Portlets

## Binding Portal Public Page Parameters with Web Service's URLParams

Adding URL portlet parameters involves two steps adding the portlet parameter definitions to provider.xml and then making use of the URL parameters in the implementation file.

### Portlet Declaration - provider.xml

The element tag is used to bind the define URLPramas public portlet parameters and has the following associated data

- name - required, It's the parameter passed to as a literal to invoke Web Service.

- bind - required, Web Service parameters can use the provider.xml tags to bind (Portlets can be setup to bind a URL parameter to a service parameter).

- default - optional, provide a default value to the Web Service.

- prompt - optional, which prompts for the input parameters to the Web Service

The highlighted section in the following excerpt from the PDK Sample Event Web Providers provider.xml declares public portlet parameters for the Public Parameter Portlet:

<portlet class="oracle.portal.provider.v2.DefaultPortletDefinition">
<id>4</id>
<name>ZipcodePortlet</name>
<title>Zipcode portlet</title>
<description>This portlet queries the ZIP code and sends a public parameter to the page.</description>
<timeout>30</timeout>
<timeoutMessage>Zipcode portlet timed out.</timeoutMessage>
....
<renderer class="oracle.portal.provider.v2.render.RenderManager">
<autoRedirect>true</autoRedirect>
<contentType>text/html</contentType>
<showPage>/htdocs/webservices/zipcode_form.jsp</showPage>
</renderer>
</portlet>
.........

<portlet class="oracle.portal.provider.v2.DefaultPortletDefinition">
<id>6</id>
<name>WeatherInformation</name>
<title>Weather Web Service Portlet</title>
.........
<literal class="oracle.portal.provider.v2.webservice.LiteralXML"
handler="oracle.portal.provider.v2.webservice.LiteralXML$Handler">
<element name="GetWeather">
<attribute name="xmlns">http://www.unisys.com/WebServices/</attribute>
<element name="ZipCode"
bind="urlParams/p_zip"
default="94065"
prompt="Please enter a Zip Code"/>
</element>
...
<responseXSL>getWeather.xsl</responseXSL>
...
</portlet>

## URL Parameter based JSP Implementation

The Web Services Render implements the following parameter bindings.

1. Constants - Portlets can be setup to pass a constant value to a service parameter. (e.g. <param>10</param> )
2. URL parameters - Portlets can be setup to bind a URL parameter to a service parameter. (e.g. bind="urlParams/p_zip")
3. Session attributes - Portlets can use session parameters for bindings. (e.g. bind="session/p_zip" )
4. Portlet render request parameters - Attributes of the portlet render request can be used for bindings. (e.g. bind="request/user/name")
5. Edit data - Customization data can be passed to the Web Service. (e.g. bind="editData/p_zip" )

The example demonstrares setting up a master portlet (JSP) drive another Web Services portlet(s) by passing parameters between them. You can bind the service parameter to a URL parameter declaratively, and it would automatically be driven by the URL parameter passed from another portlet.

The following code extracted from zipcode_form.jsp
...

<%
PortletRenderRequest pr = (PortletRenderRequest)
request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);
int zip;
try
{
zip = Integer.parseInt(pr.getParameter("p_zip"));
} //try
catch (NumberFormatException nfe)
{zip=94065;}
%>
...
<form method="post" action="<%=pr.getRenderContext().getPageURL()%>">
...
<input type="text" name="p_zip" size="6" value="<%=zip%>">
...
</form>
...

The JSP form portlet has p_zip as input filed. When the form is submitted the parameter are passed to all portlets bound with new value of p_zip and the portlets in the page are reload with a new zipcode.

## Adding URL Parameter Portlets to a Page (City Search Sample Page)

Once you have registered the Web Service sample provider following the article Installing the Web Services Sample Portlets, you simply need to create a new page for URL parameter communicating web service portlets based on zipcode. Add the following portlets Zipcode entry portlet, Location Web Service Portlet, Weather Web Service Portlet, Weather Web Service Portlet with Default StyleSheet, Local Time Web Service Portlet and Temperature Web Service potlet to a page.

You can enter any valid zip code and it displays corresponding information in the other four web services portlets.

Please refer to Oracle9iAS Portal online documentation for more information about using Web Services Renderers, read the articles Understanding Web Services for Portlets and How to Build Portlets using Web Services.

Oracle Corporation World Headquarters 500 Oracle Parkway Redwood Shores, CA 94065, USA http://www.oracle.com/ | Worldwide Inquiries: 1-800-ORACLE1 Fax 650.506.7200 | Copyright and Corporate Info