StrikeIronVwpDemoArticle

Consuming StrikeIron Web Services Using Visual Web Pack

Overview

This tutorial outlines the steps to consume StrikeIron web services prepackaged with NetBeans 6.0 using facilities provided by the Visual Web Pack. Specifically, it will demonstrate how to build a web application that invokes the US Address Verification service to verify the address entered by the user.

Prerequisites for the Tutorial

  • NetBeans 6.0 Web & Java EE (download)
  • Java Standard Development Kit (JDK) version 5.0 or above (download)
  • Glassfish V2 or Tomcat Web Server, both of which you can select from the installer that you use to install NetBeans IDE 6.0.

Prepackaged StrikeIron Services

NetBeans 6.0 comes prepackaged with a set of popular StrikeIron web services. You can access them as follow:

  • Switch to the Services tab.
  • Open the Web Services node.
  • Open the StrikeIron Services node and you should see the following services:

http://wiki.netbeans.org/wiki/attach/StrikeIronVwpDemoArticle/webservicesmgr_StrikeIronVwpDemoArticle.png

Later in the tutorial, we will demonstrate how to consume these web services by drag-and-dropping them onto the design canvas for Visual Web Pack.

Creating a Web Project

First, you need to create a web project containing the Visual Web Pack functionality.

  • Choose File > New Project. Under Categories, select Web. Under Projects, select Web Application and click Next.
  • Under Project Name, enter USAddressVerificationDemo.
  • Under Server, select Sun Java System Application Server or Glassfish and click Next.
  • Check Visual Web JavaServer Faces under Frameworks as shown below and click Finish.

http://wiki.netbeans.org/wiki/attach/StrikeIronVwpDemoArticle/frameworks_StrikeIronVwpDemoArticle.png

Designing the Web Page

After you create the USAddressVerificationDemo project, the IDE will automatically open the default Page1.jsp in the visual designer. On the right hand side of the canvas, you will also see the visuaul component palette. We will implement the page as shown below:

http://wiki.netbeans.org/wiki/attach/StrikeIronVwpDemoArticle/canvas_StrikeIronVwpDemoArticle.png

Here is how the page is created:

  • Drag and drop the Label component from the palette to the desired location. After the label is created on the canvas, you get modify the text of the label. Repeat the same step to create each label.
  • Drag and drop the Text Field component to the desired location. Change the id property for the text field in the Properties window. Repeat the same step to create each text field. (For this demo, from top to bottom, please change the id for each text field to the following: addressLine1TF, addressLine2TF, cityStateZipTF and resultTF.)
  • Drag and drop the Button component to the desired location and change the text to Validate and the id to validateButton.
  • Switch to the Services tab and open the Web Services/StrikeIron Services/USAddressVerification/USAddressVerificationSoap node. Drag and drop the verifyAddressUSA operation node onto the canvas. You should see two nodes, USAddressVerificationSOAPVerifyAddressUSA1 and USAddressVerificationSoapClient1 node appear under the Page1 node in the Navigator window as shown in the screen shot above.

Implementing the Web Page

This section will walk your through implementing the code to invoke the US Address Verification service using data collected and display the result.

  • Double click on the Validate button. The IDE will switch to the Java source view and place the cursor on validateButton_action().
  • Type in the the code as shown below:

http://wiki.netbeans.org/wiki/attach/StrikeIronVwpDemoArticle/code_StrikeIronVwpDemoArticle.png

Note that in order to access the US Address Verification service, you need to enter your StrikeIron userid and password. You can obtain them from StrikeIron. Alternatively, you can specify your email address by uncommenting the statement calling setUnregisteredUserEmail() and commenting out the calls to setUserID() and setPassword(). However, you will only be able to access the service a very limited number of times.

Testing the Web Page

To test the application, do the following:

  • Right click on the project and select Run. The browser will open.
  • In the browser, type in an address in the Address Line 1, Address Line 2 and City State & Zip text fields and click Validate. You should see the result in the Result field as shown below:

http://wiki.netbeans.org/wiki/attach/StrikeIronVwpDemoArticle/test_StrikeIronVwpDemoArticle.png

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo