dimanche 22 mai 2011

DATABINDING, WEB SERVICE and NETBEANS IDE

 DataBinding, Web Services and NetBeans 6.7

Prerequis Prerequisites
  - JavaME
- Netbeans Visual Mobile Designer Tool
- Netbeans Web Service Client Wizard tool

databinding Component
The element of NetBeans 6.7 IDE databinding is an easy to use tools to link these variables so that their changes be synchronous.  It will produce an architecture of data link in your MIDlet and everything you have to do is to specify who is linked with that and that operations will take place on the variables.

  The web service
In this tutorial we'll use databinding to display information from a previously created web service with Netbeans IDE. Our web service is just happy to tell you .... hello.(We'll keep it simple is the principle that counts). and our mobile application allows you to provide your name as parameter web service. A variable will be bound (databinding) to these various transactions and update the result of web service whenever you provide a new setting.
This is an example that you can just enter the operating mode of the tool databinding this in Netbeans.

  -> Create a new web project -> select a server (eg tomcat) -> Once you create the project done right click on the node -> choose new file -> web service
-> A file is created -> click on the small bulb notified by Netbeans and add a task to your web service.
Here is my final code example:
------------------------------------------------------------------------------------------------------ -------------------------------------------------- -------------------------------------------------- -
public class bonjourWS {

@WebMethod(operationName = "getMyPass")
public String operation(@WebParam(name = "nomParam")
String nomParam) {

return"Bonjour "+nomParam;
}
}
Right click on the file of your web service and test your web service.

JavaME client
 Use the Web service client JavaME netbeans wizard to generate a client in your mobile application. Right click on your mobile project -> web service client JavaME -> ....
After generating the code check if the stub was also generated if the file open. Wsclient that was generated and click "generate stubs"



 Application flow
With the tools Visual MIDlet design a simple flow like this
  
 Application screen
 Add the DataSet item to the palette in your application and add resources in two images in PNG format in the directory of your project.

Place items in the NetBeans palette as you see in the image below 
For the numbering here is what the work to be done:

1 -> right click -> property -> image -> databinding -> box and select dataSet [DataSet]
-> Enter in dataSet.photo EL Read "this just means that the term" picture "that will allow us to link the image to display to that of a variable with the ticket databinding.




2 -> right click -> property -> text -> databinding -> box and select dataSet [DataSet]
-> entrez dataSet.nom dans "EL Read" ceci signifie juste que c'est le terme "nom" qui nous permettra de lier le texte de cet champ à une variable par le billet du databinding. -> Enter in dataSet.nom EL Read "this just means that the term" name "that will allow us to link the text of the field to a variable with the ticket databinding. C'est sur ce champ de texte que nous utiliserons notre web service. It is on this text field that we will use our web service.



3 - As we did with the addition of the DataSet component in our project done on such a resource to add images in the code.

The application code
Go to the "Source" of the Visual Mobile Designer and add a declaration for an instance of the Stub class that you generate.  In my case it corresponds to the code:
 
-------------------------------------------------------------------------------------------------------------------------------------------
private bonjourWSService_Stub bews = new bonjourWSService_Stub();
-------------------------------------------------------------------------------------------------------------------------------------------

Locate the getValue method and adjust it by inserting a code similar to this one

------------------------------------------------------------------------------------------------------------------------------------------
public Object getValue(String name) throws IllegalStateException {

String a = choiceGroup.getString(choiceGroup.getSelectedIndex());

if (name.equals("nom")) {

/ * Note: The following clause if you use to specify what to do with the element of appointed dataSet.nom databinding * /

try {
/ / THIS IS OUR VERY SMALL CODE

return bews.getMyPass(a);
/ * Note: Bews is the subject of the Stub class we instantiated. just by typing "Bews." NetBeans offers a list of methods available for this purpose and among these methods it appears that our web service. . I call it so she and I pass a parameter value of the local variable "a". As you have noticed, a contains the value of field checked (name of the character chosen) * /
catch (RemoteException ex) {
ex.printStackTrace();
}
}
if (name.equals("photo")) {

  / * You can thanks to databinding to match that image to an image provided by a web service, but that's a matter aute .... */
}

}
return null;
} 
Test your application

 The application works fine now you are able to, efficiently handle the tool databinding in your applications to Netbeans mobile ... at least I hope so. Your suggessions are the property came.
[NOTE: The databinding as we have done will be done at application launch. To make it more dynamic set the command "validate" a method that will refresh the variables. Or you use two forms, one for the user's choice and one for displaying the result. .. ..  this tutorial is called to be improved at any time]
I just wanted to do so ...

Aucun commentaire:

Enregistrer un commentaire