5 Replies Latest reply on Jan 30, 2012 9:52 AM by reidabel

    Getting Back to the Default State from a Component

    Kurrykid Level 3

      I am using a form component with PHP to create a new record in a mySQL database.  I am able to create the record but I can't get back to the original page (state) afterwords.  If I put in currentState="Default", it doesn't respond however everything else in the code is running (i.e. the code gets commited and the datagrid gets updated with the new record).  I just can't get it to go back to the state it came from.

       

      Here's what the code looks like:

       

      protected function button_clickHandler(event:MouseEvent):void

                  {

                      var contacts2:Contacts = new Contacts();

                      contacts2.name = nameTextInput.text;

                      contacts2.address = addressTextInput.text;

                      contacts2.city = cityTextInput.text;

                      contacts2.state = stateTextInput.text;

                      contacts2.zip = zipTextInput.text;

                      contacts2.phone = phoneTextInput.text;

                      contacts2.fax = faxTextInput.text;

                      contacts2.notes = notesTextInput.text;

                     

                      createContactsResult.token = contactsService.createContacts(contacts2);

                      createContactsResult.token = contactsService.commit();

                      createContactsResult.token = contactsService.getAllContacts();

                     currentState="Default";*/

                     

                  }

       

       

      Any help would be greatly appreciated.

       

      Dave

        • 1. Re: Getting Back to the Default State from a Component
          reidabel

          Sorry, this is just off the top of my head and I'm in the middle of something else, but since you said ANY help would be appreciated ... here goes ...

           

          Could it be because of the asynchronous behavior? You've got three calls to web service methods that will all come back to their handlers at some point. Perhaps your code as listed is working fine, but one of the handlers changes the currentState AFTER this code sets it to "Default"? Maybe you need to set the current state within the handlers also ...

          • 2. Re: Getting Back to the Default State from a Component
            Kurrykid Level 3

            I tried that (I put it in the result on the CallResponder and that didn't work).  Even if I put a button on the form with the click event going to currentState="Default" it still doesn't work.  It's almost like the component is unaware of the default state.

             

            Thanks for the help.

             

            Dave

            • 3. Re: Getting Back to the Default State from a Component
              reidabel Level 1

              Hmm ... it sounds like the problem may not be related to those calls, but rather just to the state behavior. Just to verify that it never gets to the default state, as opposed to getting there and then back to the state you're in, how about adding an ...

               

              Alert.show('entered the default state');

               

              ... within an enterState method for the default state? Just to see if it fires or not. Also, how many states have you got in total? What state are you in when you are trying to get to the Default state?

              • 4. Re: Getting Back to the Default State from a Component
                Kurrykid Level 3

                No, it doesn't appear to be going to the state.  I have 2 states total…the Default State and the Form State.  In the Default state I jump to the Form state with this code (see highlighted line under the button):

                 

                <s:Panel title="Contacts"  horizontalCenter="0" verticalCenter="0" title.Form="Insert New Contact">

                        <views:ContactView id="conView" includeIn="Default"/>

                        <forms:ContactForm id="conForm" includeIn="Form"/>

                 

                        <s:controlBarContent>

                            <s:Button

                                label="Insert Contact" click="currentState='Form'"

                                label.Form="Cancel Insert" click.Form="currentState='Default'"/>

                        </s:controlBarContent>

                    </s:Panel>

                 

                 

                This is the code from the Form Component (this is 99% code that was automatically generated by Flash Builder by using the PHP service and Generating a New Form):

                 

                <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"

                         xmlns:s="library://ns.adobe.com/flex/spark"

                         xmlns:mx="library://ns.adobe.com/flex/mx"

                         xmlns:valueObjects="valueObjects.*"

                         xmlns:contactsservice="services.contactsservice.*">

                    <fx:Script>

                        <![CDATA[

                            import flash.debugger.enterDebugger;

                 

                            import mx.controls.Alert;

                            import mx.rpc.events.ResultEvent;

                 

                            protected function button_clickHandler(event:MouseEvent):void

                            {

                                var contacts2:Contacts = new Contacts();

                                contacts2.name = nameTextInput.text;

                                contacts2.address = addressTextInput.text;

                                contacts2.city = cityTextInput.text;

                                contacts2.state = stateTextInput.text;

                                contacts2.zip = zipTextInput.text;

                                contacts2.phone = phoneTextInput.text;

                                contacts2.fax = faxTextInput.text;

                                contacts2.notes = notesTextInput.text;

                 

                                createContactsResult.token = contactsService.createContacts(contacts2);

                                createContactsResult.token = contactsService.commit();

                                createContactsResult.token = contactsService.getAllContacts();

                 

                               currentState="Default";

                 

                            }

                 

                 

                        ]]>

                    </fx:Script>

                 

                    <fx:Declarations>

                        <valueObjects:Contacts id="contacts"/>

                        <contactsservice:ContactsService id="contactsService"

                                    fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"

                                    showBusyCursor="true"/>

                        <s:CallResponder id="createContactsResult"/>

                        <!-- Place non-visual elements (e.g., services, value objects) here -->

                    </fx:Declarations>

                    <s:Form id="myForm" defaultButton="{button}">

                        <s:FormItem label="Name">

                            <s:TextInput id="nameTextInput" text="{contacts.name}"/>

                        </s:FormItem>

                        <s:FormItem label="Address">

                            <s:TextInput id="addressTextInput" text="{contacts.address}"/>

                        </s:FormItem>

                        <s:FormItem label="City">

                            <s:TextInput id="cityTextInput" text="{contacts.city}"/>

                        </s:FormItem>

                        <s:FormItem label="State">

                            <s:TextInput id="stateTextInput" text="{contacts.state}"/>

                        </s:FormItem>

                        <s:FormItem label="Zip">

                            <s:TextInput id="zipTextInput" text="{contacts.zip}"/>

                        </s:FormItem>

                        <s:FormItem label="Phone">

                            <s:TextInput id="phoneTextInput" text="{contacts.phone}"/>

                        </s:FormItem>

                        <s:FormItem label="Fax">

                            <s:TextInput id="faxTextInput" text="{contacts.fax}"/>

                        </s:FormItem>

                        <s:FormItem label="Notes">

                            <s:TextInput id="notesTextInput" text="{contacts.notes}"/>

                        </s:FormItem>

                        <s:Button id="button" label="Create Contact" click="button_clickHandler(event)"/>

                        <s:FormItem label="Label">

                        <s:Button label="Button" click="currentState='Default'"/>

                        </s:FormItem>

                    </s:Form>

                    <s:Form>

                    </s:Form>

                 

                </s:Group>

                 

                 

                Thanks again for your help.  I really appreciate it as I have spent way too much time on this :-(

                 

                Dave

                • 5. Re: Getting Back to the Default State from a Component
                  reidabel Level 1

                  You're welcome, but I'm afraid I may not be of any further help - I don't see what the problem is after reviewing the code you included. No idea why it's not working. I'm grasping at straws now, but I guess I would try a button in the Form state but completely outside of the Form tags to see if THAT will let you click back to the default state or not.

                   

                  I might also fall back to the old standby of just removing stuff until it works, starting with the web service calls, then the form items, then the form. Once (if) it starts working again then you will have some more clues.

                   

                  The other thing that's perhaps unrelated but that I should mention is that while I'm no expert, and may be doing it incorrectly, I wouldn't code three web service calls consecutively. I'm just thinking that since they're asynchronous, it may not be the case that they'll be performed in the order you want. I realize you said it's been working, but still, I think I'd code it so that you have three separate call responders, one for each of the three calls and with result handlers, then:

                   

                  1. call createContacts

                  2. in the result handler of the call responder for createContacts, call the commit method

                  3. in the result handler of the call responder for the commit method, call getAllContacts

                  4. in the result handler of the call responder for getAllContacts, set currentState = 'Default';

                   

                  That will guarantee the order of completion of these tasks. Probably not solving the button/state problem, but maybe helping you out in some other way?

                   

                  Anybody else see what the issue is here?