Adding a custom tag for Web services

Once you have generated your custom tag, it appears in the System Tree. When you drag it to a JSP, the tag library is automatically associated with the page. You must specify the input and output arguments for the custom tags for the Web services in the JSP. Output arguments are stored in the pageContext of the JSP container.

Deployment of the custom tag for Web services is the same as deployment of any custom tag in PowerBuilder. See “Editing a JSP deployment configuration” for details.

Custom tags for Web services throw a JspTagException for nonrecoverable errors. The JspTagException contains information about the root cause of the exception and the point where the error occurred in processing the custom tag. This exception can be caught in a Try-Catch block or mapped to a specific error page in the Deployment Configuration Properties dialog box for the JSP target. An error page can also be specified in a page directive. See “Error handling” and “Error Mapping” for details.

Example using a currency exchange Web service

This example, using the currency exchange service available on the XMethods Web site, demonstrates how custom tags for Web services on a JSP are defined to a JSP container. You proceed with these steps after generating a TLD and JAR file for the service using the JSP Web Service Proxy wizard. The remainder of this example assumes that you accept all the wizard defaults after selecting the CurrencyExchangeService.wsdl file.

First you declare the custom tag library to the JSP. This makes all of the tags in the library available to the JSP. The exchange prefix allows for easy reference to the tag library. You can drag the library from the Components tab of the System Tree to the JSP in the HTML editor to add this code.

<%@ taglib uri="WEB-INF/tlds/CurrencyExchangeService.tld"
prefix="exchange" %>

Once the tag library is available to the page, you declare the input arguments for the custom tags in a server script.

<%
    String firstCountry = "usa";
    String secondCountry = "japan";
%>

Next, you invoke the Web service through the custom tag, passing the input parameters in a server-side expression.

<exchange:getRate country1="<%= firstCountry %>"
    country2="<%= secondCountry %>" />

Then you get the value of the returnValue variable from the custom tag and display it. This value is set when the tag is executed.

<P>The exchange rate between "<%= firstCountry %>" and "<%= secondCountry %>" is: 
<%= CurrencyExchangeService_getRate_returnValue %></P>