10 Replies Latest reply on Apr 5, 2010 7:35 AM by emekakanu

    Flex 3 Button Click Twice



      First of all, I know similar discussion posts for this issue already exist, but having tried the suggestions in those forums to no avail I am left with no other choice.

      On my form, a user has to click the submit button twice for the application state to change, thereby causing the request to be sent twice to the application backend

      I am working on an application with a Flex front end and a Java/Spring application backend.

      The flex front end uses an MVC approach with the aim of reuse.

      I am trying to create a record by filling a form and passing a request to a controller class which sends the request to the java backend and gets a result.


      x="10" width="100%" id="formVBox">


      <mx:Form width="100%" id="newPatientForm" creationComplete="{patient = new Patient()}">
      <mx:FormItem label="First Name">
      <mx:TextInput id="firstName" text="{patient.firstName}" change="{patient.firstName=firstName.text}"/>
      <mx:FormItem label="Surname">
      <mx:TextInput id="surname" text="{patient.surname}" change="{patient.surname=surname.text}"/>

      <mx:Button label="Submit" click="newPatientRecord()"/>


      <mx:FormItem label="Sex">
      <mx:ComboBox id="sex" dataProvider="{sexOptions}" close="closeHandler(event);"/>

      The view sends the request to the controller
      private function newPatientRecord():void
           //Swap something that will allow the MX:State to show a different view
           currentState = "form-positive";

      The Controller then sends the request to the java backend and gets a result
      public function createNewPatient(patient:Patient):void
         service.addEventListener("result", createNewPatientResult);
      private function createNewPatientResult(event:ResultEvent):void{
         model.patient = event.result as Patient;
         model.state = PatientModelImpl.STATE_POSITIVE;

      The view component then updates its state and displays something else.

      <mx:State name="form-positive">
      <mx:RemoveChild target="{newPatientForm}"/>
      <mx:AddChild relativeTo="{formVBox}" position="lastChild">
      <mx:Label text="Create Patient Complete"/>

      Firstly, I wanted to know if this approach is a good idea and is there something fundamentally wrong with the design and approach
      Secondly, what is causing the