2 Replies Latest reply on Oct 1, 2010 10:43 PM by advernut

    Update data item using ComboBox changeHandler

    advernut

      Hi All: This is probably a very simple operation, but I'm stumped. I want to created a "Theme switch" where I can, in one operation using a dynamically populated ComboBox, update my PHP data table - without involving a create function.  My plan is to never have more than one row in the table and only change the existing home_id field.  Also, I am running Flex 4 on a back-end dashboard and need it to be independent of the PHP front-end website.

       

      Here's my code from a test mxml page:

       

      <?xml version="1.0" encoding="utf-8"?>

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

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

         xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:ns1="*" xmlns:valueObjects="valueObjects.*">

      <fx:Script>

      <![CDATA[

      import mx.controls.Alert;

      import mx.events.FlexEvent;

      import mx.events.ListEvent;

      import mx.rpc.events.ResultEvent;

       

      import services.ServiceManager;

      import services.homepageservice.HomePageService;

      import services.homepagethemeservice.HomePageThemeService;


      protected var homePageThemeService:HomePageThemeService = ServiceManager.getInstance().homePageThemeService;

      protected var homePageService:HomePageService = ServiceManager.getInstance().homePageService;

       

       

      protected function ThemeDDL_creationCompleteHandler(event:FlexEvent):void

      {

      getAllHomePageResult.token = homePageService.getAllHomePage();

      }



      protected function ThemeDDL_changeHandler(event:ListEvent):void

      {

      homePageTheme.home_id = ThemeDDL.selectedItem.id;

       

      if (homePageTheme.home_id != null){

      updateHomePageThemeResult.token = homePageThemeService.updateHomePageTheme(homePageTheme);

      Alert.show("Theme Updated", "Change Executed");

      }

       

      }

       


      ]]>

      </fx:Script>

      <fx:Declarations>

      <valueObjects:HomePage id="homePage"/>

      <s:CallResponder id="getAllHomePageResult"/>

      <valueObjects:HomePageTheme id="homePageTheme"/>

      <s:CallResponder id="getAllHomePageThemeResult" result="homePageTheme = getAllHomePageThemeResult.lastResult[0] as HomePageTheme"/>

      <s:CallResponder id="updateHomePageThemeResult"/>

      <s:CallResponder id="createHomePageThemeResult"/>

      </fx:Declarations>

      <s:VGroup x="10" y="10" width="643" height="587">

      <mx:Form>

      <mx:FormItem>

      <ns1:VBComboBox id="ThemeDDL"

      labelField="headline"

      prompt="Select Theme"

      selectedValue="{homePage.id}"

      creationComplete="ThemeDDL_creationCompleteHandler(event)"

      dataProvider="{getAllHomePageResult.lastResult}" width="242" change="ThemeDDL_changeHandler(event)"/>

      </mx:FormItem>

       

      </mx:Form>

       

      </s:VGroup>

      </s:Application>

       

      Any help would be greatly appreciated!

       

      Thanks in advance.

        • 1. Re: Update data item using ComboBox changeHandler
          UbuntuPenguin Level 4

          You may want to rephrase your problem.  There seems to be a disconnect between the title of the question and the explanation.  You may also want to clarify what you mean by only having one row in the table , it sounds like you actually only want a table to have exactly 1 row.

          • 2. Re: Update data item using ComboBox changeHandler
            advernut Level 1

            Thanks for your response.

             

            Yes, I only want the table to have exactly 1 row.

             

            I'll rephrase to help clarify my goal.  I have a table in my database called "homePageTheme" that has a primary key field called "id" (not really required in this case, but it doesn't hurt) and a second field called "home_id", which is the field I want to update.  They are both number fields.  "home_id" will collect the primary key of the "homePage" table.  I want to pass that "id" number to the "home_id" field. I don't want to insert/create additional rows - ever.  I only want to modify/update the "home_id" field.  I am using this table as a "switch." and it ties to the front-end PHP with a WHERE clause.  When the value of "home_id" changes, so does the designated content of the website home page. Now, that's the database.

             

            An added complication is I am using a comboBox as the actual switch through a change event (see the code in my last post).  The only problem I am having is the actual update function:

             

            This works, but adds an additional field because of the create operation:

             

             

            protected function ThemeDDL_changeHandler(event:ListEvent):void

            {

            homePageTheme.home_id = ThemeDDL.selectedItem.id;

             

            if(homePageTheme.id==0){

            createHomePageThemeResult.token = homePageThemeService.createHomePageTheme(homePageTheme);

            Alert.show("Theme Added", "Change Executed");

            }

            else{

            updateHomePageThemeResult.token = homePageThemeService.updateHomePageTheme(homePageTheme);

            Alert.show("Theme Updated", "Change Executed");

            }

            }

             

             

            This does not work and I am trying to figure out why:

             

             

            protected function ThemeDDL_changeHandler(event:ListEvent):void

            {

            homePageTheme.home_id = ThemeDDL.selectedItem.id;

             

            if (homePageTheme.home_id != null){

            updateHomePageThemeResult.token = homePageThemeService.updateHomePageTheme(homePageTheme);

            Alert.show("Theme Updated", "Change Executed");

            }

             

            }

             

            I know I am not passing the value correctly from the homePage table to the homePageTheme table.  Do you know what I'm doing wrong?

            I have Google searched for days and have only seen examples that hint at the answer.  Hope this clears things up a bit.

             

            Thanks!

             

            Message was edited by: advernut