views:

817

answers:

1

I am trying to build my first CRUD application and cant get the update query to work. Here is the MXML and AS.

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

<fx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.events.DataGridEvent;
        import mx.events.FlexEvent;
        import mx.rpc.events.ResultEvent;

        protected function init(event:FlexEvent):void
        {
            // TODO Auto-generated method stub
            //login.addEventListener(MouseEvent.CLICK, clickMe);
        }

        protected function doLogin(event:MouseEvent):void
        {
            trace('doLogin');
            //Alert.show("doLogin");
            loginResult.token = customUserClass.login(username_txt.text, password_txt.text);

            //sayHelloResult.token = user.sayHello('Jeff');
            //sayHelloResult.addEventListener(ResultEvent.RESULT, fromCallingHello);
        }

        protected function loginResultEvent(event:ResultEvent):void {
            //Alert.show(event.result.toString(), 'loginResult');
            trace (event.result.toString());
            if (event.result == true) {
                currentState = 'LoggedIn';
            }
        }

        //protected function fromCallingHello(event:ResultEvent):void {
        //  Alert.show(event.result.toString(), 'fromCallingHello');
        //  trace (event.result.toString());
        //}


        protected function dataGrid_creationCompleteHandler(event:FlexEvent):void
        {
            getAllUsersResult.token = usersService.getAllUsers();
            //usersService.getAllUsers();
        }


        protected function dataGrid_itemEditEndHandler(event:DataGridEvent):void
        {
            // TODO Auto-generated method stub
            //var user:Users = new Users();
            //userServiceValueObject[event.dataField]=(dataGrid.itemEditorInstance as mx.controls.TextInput).text;
            //usersService.updateUsers(userServiceValueObject);
        }       

        protected function delete_btn_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub
            usersService.deleteUsers(dataGrid.selectedItem.id);
        }


        protected function update_btn_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub
            //var users:Users = new Users();
            userServiceValueObject.id = parseInt(idTextInput.text);
            userServiceValueObject.firstname = firstnameTextInput.text;
            userServiceValueObject.lastname = lastnameTextInput.text;
            userServiceValueObject.email = emailTextInput.text;
            userServiceValueObject.username = usernameTextInput.text;
            userServiceValueObject.password = passwordTextInput.text;
            userServiceValueObject.joindate = joindateDateField.selectedDate;
            updateUsersResult.token = usersService.updateUsers(userServiceValueObject);
            //usersService.updateUsers(userServiceValueObject);
            usersService.getAllUsers();
            //usersService.updateUsers(userServiceValueObject);
        }

        //protected function updateUsers(item:Users):void
        //{
        //  updateUsersResult.token = usersService.updateUsers(item);
        //}

        protected function dataGrid_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub
            idTextInput.text = dataGrid.selectedItem.id;
            firstnameTextInput.text = dataGrid.selectedItem.firstname;
            lastnameTextInput.text = dataGrid.selectedItem.lastname;
            emailTextInput.text = dataGrid.selectedItem.email;
            usernameTextInput.text = dataGrid.selectedItem.username;
            joindateDateField.text = dataGrid.selectedItem.joindate;
        }


        protected function revert_btn_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub
            usersService.getDataManager(usersService.DATA_MANAGER_USERS).revertChanges();
        }


        protected function save_btn_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub
            usersService.commit();
        }


        protected function create_btn_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub
            //datatestService.createDatatest(datatest);
            //datatestService.getAllDatatest();
            //usersService.createUsers(userServiceValueObject);
            //usersService.getAllUsers();
            //var users:Users = new Users();
            //users.id = parseInt(idTextInput.text);
            userServiceValueObject.firstname = firstnameTextInput.text;
            userServiceValueObject.lastname = lastnameTextInput.text;
            userServiceValueObject.email = emailTextInput.text;
            userServiceValueObject.username = usernameTextInput.text;
            userServiceValueObject.password = passwordTextInput.text;
            userServiceValueObject.joindate = joindateDateField.selectedDate;
            //createUsersResult.token = 
            usersService.createUsers(userServiceValueObject);
            usersService.getAllUsers();
            //dataGrid.
        }


    ]]>
</fx:Script>
<s:states>
    <s:State name="Login"/>
    <s:State name="LoggedIn"/>
</s:states>

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <customuserclass:CustomUserClass id="customUserClass" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true" />
    <s:CallResponder id="sayHelloResult"/>
    <s:CallResponder id="loginResult" result="loginResultEvent(event)"/>


    <usersservice:UsersService id="usersService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
    <valueObjects:Users id="userServiceValueObject"/>
    <s:CallResponder id="getAllUsersResult"/>
    <s:CallResponder id="createUsersResult"/>
    <s:CallResponder id="deleteUsersResult"/>
    <s:CallResponder id="updateUsersResult"/>       

</fx:Declarations>

<s:Panel width="250" height="140" verticalCenter="0" horizontalCenter="0" title="Login" includeIn="Login">
    <s:layout>
        <s:BasicLayout/>
    </s:layout>
    <s:TextInput x="87" y="10" id="username_txt" width="151" text="jguthrie"/>
    <s:TextInput x="87" y="40" id="password_txt" width="151" text="test"/>
    <s:Label x="10" y="10" text="Username:" fontSize="14"/>
    <s:Label x="10" y="44" text="Password:" fontSize="14"/>
    <s:CheckBox x="10" y="68" label="Remember Me"/>
    <s:Button x="168" y="69" label="Login" id="login" click="doLogin(event)"/>
</s:Panel>
<s:Label includeIn="LoggedIn" x="836" y="10" text="Manage Users:" fontSize="20"/>
<mx:DataGrid includeIn="LoggedIn" x="289" y="31" id="dataGrid" click="dataGrid_clickHandler(event)" creationComplete="dataGrid_creationCompleteHandler(event)" dataProvider="{getAllUsersResult.lastResult}" editable="true" itemEditEnd="dataGrid_itemEditEndHandler(event)">
    <mx:columns>
        <mx:DataGridColumn headerText="id" dataField="id"/>
        <mx:DataGridColumn headerText="username" dataField="username"/>
        <mx:DataGridColumn headerText="firstname" dataField="firstname"/>
        <mx:DataGridColumn headerText="lastname" dataField="lastname"/>
        <mx:DataGridColumn headerText="email" dataField="email"/>
        <mx:DataGridColumn headerText="joindate" dataField="joindate"/>
    </mx:columns>
</mx:DataGrid>
<mx:Form includeIn="LoggedIn" x="289" y="258">
    <mx:FormItem label="Id">
        <s:TextInput id="idTextInput" text="{userServiceValueObject.id}"/>
    </mx:FormItem>
    <mx:FormItem label="Firstname">
        <s:TextInput id="firstnameTextInput" text="{userServiceValueObject.firstname}"/>
    </mx:FormItem>
    <mx:FormItem label="Lastname">
        <s:TextInput id="lastnameTextInput" text="{userServiceValueObject.lastname}"/>
    </mx:FormItem>
    <mx:FormItem label="Email">
        <s:TextInput id="emailTextInput" text="{userServiceValueObject.email}"/>
    </mx:FormItem>
    <mx:FormItem label="Username">
        <s:TextInput id="usernameTextInput" text="{userServiceValueObject.username}"/>
    </mx:FormItem>
    <mx:FormItem label="Password">
        <s:TextInput id="passwordTextInput" text="{userServiceValueObject.password}"/>
    </mx:FormItem>
    <mx:FormItem label="Joindate">
        <mx:DateField id="joindateDateField" selectedDate="{userServiceValueObject.joindate}"/>
    </mx:FormItem>
</mx:Form>
<mx:Form includeIn="LoggedIn" x="536" y="258">
    <mx:FormItem label="CreateUsers">
        <s:TextInput id="createUsersTextInput" text="{createUsersResult.lastResult as int}"/>
    </mx:FormItem>
</mx:Form>
<s:HGroup includeIn="LoggedIn" x="289" y="221" width="602" height="33">
    <s:Button includeIn="LoggedIn" label="Create" id="create_btn" click="create_btn_clickHandler(event)"/>
    <s:Button includeIn="LoggedIn" label="Update" id="update_btn" click="update_btn_clickHandler(event)"/>
    <s:Button includeIn="LoggedIn" label="Revert Update" id="revert_btn" click="revert_btn_clickHandler(event)"/>
    <s:Button includeIn="LoggedIn" label="Save Update" id="save_btn" click="save_btn_clickHandler(event)"/>
    <s:Button includeIn="LoggedIn" label="Delete" id="delete_btn" click="delete_btn_clickHandler(event)"/>
</s:HGroup>

A: 

I had this error, and my search led me to a note saying that message comes back when PHP is throwing an error. A quick look at the end of my PHP log showed what variable I had a typo in, and it was a quick fix after that.

Steve Wright