ConnectionRequest application

56 views
Skip to first unread message

Junel Mata

unread,
Nov 3, 2014, 11:08:22 PM11/3/14
to codenameone...@googlegroups.com
I need help about my current project. I created a login form and a web service which contains a authenticateUser(userID,password) method that returns a boolean. My problem is that I want to use the ConnectionRequest in the client side code and use an infinite progress to add animation while waiting. how can I apply this to my code? 

Shai Almog

unread,
Nov 4, 2014, 1:00:42 AM11/4/14
to codenameone...@googlegroups.com
What's the problem?
Just use the connection request to invoke the webservice and show an infinite progress.
There are several How Do I videos covering different ways of doing a webservice see: http://www.codenameone.com/how-do-i.html

Junel Mata

unread,
Nov 4, 2014, 1:29:29 AM11/4/14
to codenameone...@googlegroups.com
My problem is how to invoke a webservice method using connection request because in the http://www.codenameone.com/how-do-i.html video you used JSON as the example.

here's my code:
public void Login(){
        
        BoxLayout box = new BoxLayout(BoxLayout.Y_AXIS);
        TableLayout tl = new TableLayout(2,2);
        summary = new Form("Account Summary");
        main = new Form("IBC Japan");
        
        TextField userID = new TextField();
        TextField password = new TextField();
        
        Label user = new Label("User ID");
        Label pass = new Label("Password");
        
        Button loginbtn = new Button("Login");
        Button exit = new Button("Exit");
        loginbtn.setAlignment(Button.CENTER);
        exit.setAlignment(Button.CENTER);
        
        user.setAlignment(Label.RIGHT);
        pass.setAlignment(Label.RIGHT);
        
        Container fields = new Container();
        
        fields.addComponent(user);
        fields.addComponent(userID);
        fields.addComponent(pass);
        fields.addComponent(password);
               
        fields.setLayout(tl);
        main.setLayout(box);
        
        main.addComponent(new Label("          "));
        main.addComponent(new Label("          "));
        main.addComponent(fields);
        main.addComponent(loginbtn);
        main.addComponent(exit);
        
        //The red text is the example code from your tutorial which I followed.

        ConnectionRequest r = new ConnectionRequest();
        r.setPost(false);     
        r.addArgument("q", "@codename-one");
        InfiniteProgress prog = new InfiniteProgress();
        Dialog dlg = prog.showInifiniteBlocking();
        r.setDisposeOnCompletion(dlg);
        NetworkManager.getInstance().addToQueueAndWait(r);
        
        loginbtn.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evt) {
               //here in this section is where I want to add the connection request above but my problem is how should I do it here.
               //I am new in codename one thats why I dont know how to add connection request as part of my code flow.
               //I created the authenticateUser method using the web service wizard which accepts two string arguments and returns a boolean.
               if(authenticateUser(userID,password)){ 
                     showSummary("acctBal");
                }
                else{
                     Dialog.show("Incorrect Input","The User ID and Password you entered are Incorrect","Retry",null);
                }
            }
        });
        
        exit.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evt) {
                System.exit(0); 
            }
        });
        
        main.show();

Shai Almog

unread,
Nov 4, 2014, 11:28:33 AM11/4/14
to codenameone...@googlegroups.com
When you say webservice do you mean SOAP?
That's painful on the client since the whole envelope and protocol process is anything but simple. There are some discussions on SOAP in the forum but generally I would recommend looking at the web service wizard video where we provide a way to work with a proxy that would perform the actual SOAP communication for you. This is both more efficient and easier to work with.

Junel Mata

unread,
Nov 4, 2014, 7:08:55 PM11/4/14
to codenameone...@googlegroups.com
Thank you very much though I didn't got my desired answer. I am currently using the webservice proxy process to communicate with my application. What I wanted really is to use both the web service proxy and connection request for my application.

Shai Almog

unread,
Nov 4, 2014, 11:14:57 PM11/4/14
to codenameone...@googlegroups.com
I don't understand the problem?
Notice that in this demo http://www.codenameone.com/blog/build-mobile-ios-apps-in-java-using-codename-one-on-youtube we use the webservice wizard for server communication then use a ConnectionRequest (or really the MultiparRequest subclass) to upload files which isn't supported by the webservice wizard.

Junel Mata

unread,
Nov 5, 2014, 12:36:14 AM11/5/14
to codenameone...@googlegroups.com
My server communication is OK and I just figured out how to make the webservice wizard and connection request work together. Thanks
Reply all
Reply to author
Forward
0 new messages