BlackBerry
Skip Top Navigation
Developers Partners
North America [change region] Products Solutions Purchasing Support
Developers


Create Communication Between the User Interface and the Length Conversion Web Service

Exercise

Create the communication between the user interface and the length conversion web service. To transmit the data to the web service, create a screen local variable and map data to it for storage. Data selected from or entered in the drop-down lists and text box can be mapped to this local variable before being sent as a message to the web service. A request message bound to the web service and containing the data from the local variable enables the conversion web service.

Objectives

  • Discover how the user interface and the length conversion web service communicate with each other.
  • See how to transmit the data to the web service, create a screen local variable and map data to it for storage and use local variable to enable web service conversion.

Setup Tasks

Open BlackBerry MDS Studio™ and select the LengthConverter project which you created in the previous labs. See the labs entitled Creating a Bottom-up BlackBerry MDS Studio Project and Design the Main Screen and User Interface for more details.

If you have not completed the first two labs in this series, create the LengthConverter project following these steps:

  1. Download the LengthConverter workspace (ZIP) and unzip the file
  2. Import the LengthConverter workspace to BlackBerry MDS Studio
    Click File menu -> Import Existing… -> Browse - > select LengthConverter -> Finish

Tasks

Create a local variable

  1. Click the screen canvas.
  2. In the Properties pane, in the Local Variables property, click ....
  3. In the Local Variables dialog box, click +.
    Note: The BlackBerry MDS Studio proposes the creation of the local variable called lengthParameters that can store the initial and final length unit and the initial value.
  4. Click OK.

Assign controls to the lengthParameters local variable

  1. On the screen canvas, click the choice1 control.
  2. In the Properties pane, in the Mapping property, click ....
  3. Expand Local Variables.
  4. Expand lengthParameters.
  5. Click fromUnit.
  6. Click OK.
  7. On the screen canvas, click the choice2 control.
  8. Repeat steps 2 through 4.
  9. Click toUnit.
  10. Click OK.
  11. On the screen canvas, click the editBox1 control.
  12. Repeat steps 2 through 4.
  13. Click fromValue.
  14. Click OK.

Set the Convert button to send data to the web service for conversion

Using the button, the user can activate the web service. When pressed, the BlackBerry MDS Application sends the data on the main screen to the lengthParameters local variable. The convertLengthRequest message sends the local variable information to the web service. The conversion web service converts the length value.

  1. On the screen canvas, click the Convert button control.
  2. In the Wizards menu, select Workflow Wizard.
  3. Select the Send a message check box.
  4. Click Next.
  5. In the list of data types, expand Local Variables.
  6. Click lengthParameters.
  7. Click Next.
  8. Click convertLengthRequest.
  9. Click Next.
  10. In the left pane, click lengthParameters to assign a screen parameter.
  11. In the right pane, click parameters to assign a message parameter.
  12. Click Assign.
  13. Click Finish.

Tip: You can view the script that the BlackBerry MDS Studio generates in Navigator > Scripts. Double-click script_Onscr_Mainbutton1Click. The script displays the syntax for sending a message to the web service when the user clicks the Convert button.

Create a global variable to receive data from the web service

When the web service converts the length, it generates a response message containing the converted length data. The LengthConverter application stores this data in a global variable. To display the converted length to the user you map the Result edit box to the global variable.

  1. In the Navigator pane, expand Data.
  2. Right-click Globals.
  3. Click New Global.
  4. In the Create New Global dialog box, in the Name field, type result.
  5. Click Finish.
  6. In the Global (result) Variable Editor, click the drop-down arrow beside the Data Type field.
  7. Expand data component.
  8. Click Result.
  9. Click OK.

Map the web service response message to the result global variable

  1. In the Navigator pane, expand Messages.
  2. Double-click the convertLengthResponse message.
  3. In the Message Editor, click the Fields tab.
  4. Click the first Data Mapping cell.
  5. Click ....
  6. In the Choose Data Mapping dialog box, select the Is Mapped check box.
  7. Click the result global variable.
  8. Click OK.

Note: The convertLengthResponse message and the result global variable are related. When the web service sends a response, the LengthConverter application stores the value in the result global variable. The relationship canvas displays the visual representation between the message and data.

Map the result global variable to the edit box to display the converted length

  1. In the Navigator pane, double-click scrMain.
  2. On the screen canvas, click editbox2.
  3. In the Properties pane, in the Initial Value property click ....
  4. In the Initial Value dialog box, expand Globals.
  5. Expand result.
  6. Click toValue.
  7. Click Apply.
  8. Click OK.

Refresh the main screen when receiving the response message

The LengthConverter application receives the converted length in the web service response message. To display the converted length, the main screen must refresh when the application receives the response message.

  1. Click the screen canvas.
  2. In the Properties pane, in the Refresh Messages property, click ....
  3. Click Add.
  4. Click OK.

Save the project

  1. In the Navigator pane, click the LengthConverter project.
  2. On the toolbar, click Save.

Additional Labs

Go to the next exercise in “Creating a Length Conversion Application Using the Bottom-up Approach”, Optimize Wireless Bandwidth Using Message Binding .

Back to the Developer Lab Main Menu

 
Other Resources
 
     
 Home | Products | Solutions | Purchasing | Support | Developers | Worldwide | News | About Us | Contact Us | Site Map
 Legal | Copyright © 2008 Research In Motion Limited, unless otherwise noted.