MobilityCountryBrowser
Mobile Country Browser with Databinding created with NetBeans Mobility
Software
You will need NetBeans IDE > 6.0 with all Mobility modules (means including End2End modules). How to get such IDE? 1, install full IDE 2, install NetBeans Mobility distribution and download Mobility End to End support with Plugin manager.
Scenario
This tutorial shows how to create mobile client to a web service. And how to display the returned data easily. This approach is using Java ME databinding library that is bundled with the NetBeans Mobility.
Steps
- Create new Mobility MIDP project.
- Name it CountryBrowser
- Don't create Hello midlet.
- Generate stubs for the mobile client
- New File > MIDP > Java ME Web Service Client, NEXT
- WSDL URL = http://www.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL
- click Retrieve WSDL button
- Check Generate Databinding Structures check box
- Finish - jsr172 stubs are generated
- Create UI
- New File > MIDP > Visual MIDlet
- Put List, WaitScreen, Form, Alert into Flow Designer
- Add commands and connect the screens as on the picture
- Create country form UI
- Open the form in screen designer
- Add 4 string items to the form
- Name the string items instances name, countryISO, capital, currencyISO
- Change the labels to look as on screenshot
- Create binding
- Go to source of the visual midlet
- In method getTask() add code
- Add calls of next() and previous() methods to commandAction method
- Add calls of next() and previous() methods to commandAction method
if (command == next) {
// write pre-action user code here
'''next();'''//new code
// write post-action user code here
} else if (command == previous) {
// write pre-action user code here
'''previous();'''//new code
// write post-action user code here
}
- Show failure in alert. Change in commandAction method
- Show failure in alert. Change in commandAction method
} else if (displayable == waitScreen) { if (command == WaitScreen.FAILURE_COMMAND) {
// write pre-action user code here
'''getAlert().setString(getTask().getFailureMessage());'''//new code
switchDisplayable (getAlert (), getForm ());
// write post-action user code here}
- Create the missing methods - bind, next, previous
protected void bind() throws RemoteException {
CountriesIndexDS index = new CountriesIndexDS(); //index for navigation in aray
DataBinder.registerDataSet( index, "index" ); //register the binder
CountryInfoService service = new CountryInfoService_Stub(); //create mobile client stub
DataBinder.registerDataSet(service.FullCountryInfoAllCountries(), "countries"); //call method of web service
DataBinder.bind("countries.tCountryInfo[Index.index].sName",
new StringItemBindingProvider(), getName(), StringItemBindingProvider.FEATURE_TEXT); //bind UI and the data structure
DataBinder.bind("countries.tCountryInfo[Index.index].sCapitalCity",
new StringItemBindingProvider(), getCapital(), StringItemBindingProvider.FEATURE_TEXT);//bind UI and the data structure
DataBinder.bind("countries.tCountryInfo[Index.index].sCurrencyISOCode",
new StringItemBindingProvider(), getCurrencyISO(), StringItemBindingProvider.FEATURE_TEXT);//bind UI and the data structure
DataBinder.bind("countries.tCountryInfo[Index.index].sISOCode",
new StringItemBindingProvider(), getCountryISO(), StringItemBindingProvider.FEATURE_TEXT);//bind UI and the data structure
}
private void next() {
if (((Boolean) DataBinder.readValue("index.index < countries.tCountryInfo.length - 1")).booleanValue()) {
DataBinder.writeValue("index.index", DataBinder.readValue("index.index + 1"));//change value of the index
}
}
private void previous() {
if (((Boolean) DataBinder.readValue("index.index > 0")).booleanValue()) {
DataBinder.writeValue("index.index", DataBinder.readValue("index.index - 1"));//change value of the index
}
}
- Fix imports
- Create missing index dataset class in the VisualMIDlet class
- Run project

