Form transition problems

46 views
Skip to first unread message

mikko.nu...@gmail.com

unread,
Aug 21, 2014, 3:10:32 AM8/21/14
to codenameone...@googlegroups.com
Hi,

I'm having difficulties with my form transitions. I have a simple form that is supposed to authenticate and gather customer data into following forms using a simple web service call. So when login button is pushed from the "Main" form it calls service that uses overridden ConnectionRequest (MyCustomerRequestHandler) object to retrieve data. At the overridden postResponse() method I decide from the parsed xml content if authentication was successfull and data was retrieved. Obviously when authentication is failed I need to stay on the "Main" form and show to user that credidentials were wrong. And if authentication is successfull "Home" form is shown with populated data. However when I call showForm() at the postResponse() the form does change but it changes also back to "Main" form and I cannot proceed. Here is my code:

    // At the StateMachine
   
@Override
   
protected void onMain_BtnLoginAction(Component c, ActionEvent event) {

       
if (findTxtUsername().getText().equals("") || findTxtPassword().getText().equals("")) {
           
Dialog.show("Notification:", "Please fill all required fields", "OK", null);
       
} else {

            authenticationData
.setUsername(findTxtUsername().getText());
            authenticationData
.setPassword(findTxtPassword().getText());

           
MyCustomersService.authenticateAndGetData();
       
}
   
}


        // At the MyCustomersService
       
public static void authenticateAndGetData() {

       
MyCustomersRequestHandler myCustomersRequestHandler = new MyCustomersRequestHandler();
       
InfiniteProgress infiniteProgress = new InfiniteProgress();
       
Dialog dialog = infiniteProgress.showInifiniteBlocking();

        myCustomersRequestHandler
.setPost(false);
        myCustomersRequestHandler
.setUrl(/////);
        myCustomersRequestHandler
.addArgument("username",
       
StateMachine.getAuthenticationData().getUsername());
        myCustomersRequestHandler
.addArgument("password",                      StateMachine.getAuthenticationData().getPassword());
        myCustomersRequestHandler
.setDisposeOnCompletion(dialog);

       
NetworkManager.getInstance().addToQueue(myCustomersRequestHandler);
   
}

   
   
// At MyCustomersResponseHandler
   
@Override
   
protected void postResponse() {

       
NetworkManager.getInstance().shutdown();

       
if (AuthenticationParser.isAuthorized(getDocument())) {
               
StateMachine.setMyCustomersResponces(MyCustomerResponseParser.parseElementToObject(getDocument()));
           
StateMachine.getStateMachine().showForm("Home", null);

       
} else {

           
StateMachine.getStateMachine().showForm("Main", null);
       
}

   
}

   
@Override
   
protected void readResponse(InputStream inputStream) throws IOException {

       
if (inputStream != null) {
            setDocument
(SimpleXMLParser.parseInputStream(inputStream));
       
}

   
}

    // At the StateMachine
   
@Override
   
protected void beforeHome(Form f) {

       
MyCustomersService.populateMyCustomers();
   
}

So what happens is that the wanted form ("Home" or "Main" ) is shown for a bery brief moment and right after the "Main" form is shown again. Is there a architectural problem in my code or what?

Shai Almog

unread,
Aug 21, 2014, 12:49:01 PM8/21/14
to codenameone...@googlegroups.com, mikko.nu...@gmail.com
Hi,
shutting down the network manager is wrong.
I'm guessing your button has a command with a target form which it shouldn't have. Remove that target and all should work as expected.

mikko.nu...@gmail.com

unread,
Aug 22, 2014, 6:46:28 AM8/22/14
to codenameone...@googlegroups.com, mikko.nu...@gmail.com
Hi,

and thanks for your swift reply. What is the proper way to release the connection request from the network manager's queue? Even though the request got response and UI was already populated with the data, the queue remained busy and other requests couldn't be done. shutDown() was the workaround for that, I knew it might have been harsh way.

The button didn't have any commands defined [null]. I even created another button but result was the same. Usually I tell StateMachine to change the form before making the actual connection request and when request has finished I simply populate the containers with incoming data. Obviosly I can't do that now since I don't know which form to go before the connection request's response is parsed :/. As said the right form is briefly shown and populated, but it instantly changes back to "Main" form.


Shai Almog

unread,
Aug 22, 2014, 12:17:06 PM8/22/14
to codenameone...@googlegroups.com, mikko.nu...@gmail.com
Hi,
I would suggest you debug that. I'm assuming you are placing something into the network queue or blocking in some way.

I suggest you override the createContainer method in the state machine, place a breakpoint there and then see who is trying to show the correct and the incorrect form. Then track it back to see why each was invoked.
Reply all
Reply to author
Forward
0 new messages