WEB开发网
开发学院图形图像Flash 基于flex4技术从零开发flex博客系统 : 5 数据存储... 阅读

基于flex4技术从零开发flex博客系统 : 5 数据存储之管理Greeting

 2009-05-05 12:06:18 来源:WEB开发网   
核心提示: 1,pm.deletePersistent用于删除单个对象2,基于flex4技术从零开发flex博客系统 : 5 数据存储之管理Greeting(6),pm.deletePersistentAll用于删除一个集合3,pm.getObjectById用于获取单个对象4,数据会自动存储,需在s

1,pm.deletePersistent用于删除单个对象

2,pm.deletePersistentAll用于删除一个集合

3,pm.getObjectById用于获取单个对象

4,更新Greeting对象时,只需设置该对象属性,在pm.close之前,数据会自动存储。需在sban.flexblog.Greeting中,添加如下setter:

public void setGreetingContent(String v)
        {
                this.greetingContent = v;
        }

修改Index.mxml客户端代码,最终如下:

<?xml version="1.0" encoding="utf-8"?>
<FxApplication xmlns="http://ns.adobe.com/mxml/2009" initialize="onInit()">
        <Script>
                <![CDATA[
                        import mx.controls.Alert;
                        import flash.net.URLLoader;
                        import flash.net.URLRequest;
                        import mx.rpc.events.ResultEvent;
                        import mx.rpc.events.FaultEvent;
                        import mx.rpc.AbstractOperation;
                        import mx.rpc.remoting.RemoteObject;
                        import mx.messaging.ChannelSet;
                        import mx.messaging.channels.AMFChannel;
                        import mx.collections.ArrayCollection;
                        import mx.managers.CursorManager;
                        import mx.events.IndexChangedEvent
                        
                        [Bindable]
                        private var _greetingData : ArrayCollection;
                        
                        [Bindable]
                        private var _greeting : Object;
                        
                        private var _remotingObj : RemoteObject = new RemoteObject("GenericDestination");
                        
                        private function onInit() : void
                        {
                                configRemoting();
                                getAllGreetings();
                        }
                        
                        private function configRemoting() : void
                        {
                                _remotingObj.source = "sban.flexblog.HelloWorld";
                                _remotingObj.endpoint = "weborb.wo";
                        }
                        
                        private function greetViaRemoting() : void
                        {
                                var op : AbstractOperation = _remotingObj.getOperation("greet2");
                                var handler : Function = function(event : ResultEvent) : void
                                        {
                                                op.removeEventListener(ResultEvent.RESULT, handler);
                                                getAllGreetings();
                                                Alert.show( event.result.toString() );
                                        };
                                
                                op.addEventListener(ResultEvent.RESULT, handler);
                                op.send(vNameTxt.text,vContentTxt.text);
                        }
                        
                        private function getAllGreetings() : void
                        {
                                var op : AbstractOperation = _remotingObj.getOperation("getAllGreetings");
                                var handler : Function = function(event : ResultEvent) : void
                                        {
                                                op.removeEventListener(ResultEvent.RESULT, handler);
                                        
                                                _greetingData = ArrayCollection(event.result);
                                        };
                                        
                                op.addEventListener(ResultEvent.RESULT, handler);
                                op.send();
                        }
                        
                        private function deleteAllGreetings() : void
                        {
                                var op : AbstractOperation = _remotingObj.getOperation("deleteAllGreetings");
                                var handler : Function = function(event : ResultEvent) : void
                                        {
                                                op.removeEventListener(ResultEvent.RESULT, handler);
                                                getAllGreetings();
                                                //Alert.show(event.result.toString());
                                        };
                                        
                                op.addEventListener(ResultEvent.RESULT, handler);
                                op.send();
                        }
                        
                        private function deleteItem() : void
                        {
                                if(vList1.selectedItem)
                                {
                                        var itemId : Number = vList1.selectedItem.id;
                                        
                                        var op : AbstractOperation = _remotingObj.getOperation("deleteById");
                                        var handler : Function = function(event : ResultEvent) : void
                                                {
                                                        op.removeEventListener(ResultEvent.RESULT, handler);
                                                        getAllGreetings();
                                                        //Alert.show(event.result.toString());
                                                };
                                                
                                        op.addEventListener(ResultEvent.RESULT, handler);
                                        op.send(itemId);
                                }
                        }
                        
                        private function selectionChangedHandler(event : IndexChangedEvent) : void
                        {
                                var itemId : Number = vList1.selectedItem.id;
                                var op : AbstractOperation = _remotingObj.getOperation("getGreetingById");
                                
                                var handler : Function = function(event : ResultEvent) : void
                                        {
                                                op.removeEventListener(ResultEvent.RESULT, handler);
                                                
                                                _greeting = event.result;
                                        };
                                        
                                op.addEventListener(ResultEvent.RESULT, handler);
                                op.send(itemId);
                        }
                        
                        private function edit() : void
                        {
                                var content : String = vContentEditTxt.text;
                                var op : AbstractOperation = _remotingObj.getOperation("editGreeting");
                                
                                var handler : Function = function(event : ResultEvent) : void
                                        {
                                                op.removeEventListener(ResultEvent.RESULT, handler);
                                                getAllGreetings();
                                        };
                                        
                                op.addEventListener(ResultEvent.RESULT, handler);
                                op.send(_greeting.id, content);
                        }
                ]]>
        </Script>
        
        <layout>
                <BasicLayout />
        </layout>
        
        <VGroup width="100%">
                <HGroup>
                        <Label text="user:" />
                        <FxTextInput id="vNameTxt" text="sban" />
                </HGroup>
                <HGroup>
                        <Label text="content:" />
                        <FxTextInput id="vContentTxt" text="greeting content" />
                </HGroup>
                
                <HGroup>
                        <FxButton id="vSendBtn" label="remoting greet"click="greetViaRemoting()" />
                        <FxButton id="vDelAllBtn" label="deoete all greetings"click="deleteAllGreetings()" />
                        <FxButton id="vdelItemBtn" label="delete selected item"click="deleteItem()" />
                </HGroup>
                
                <FxList id="vList1" selectionChanged="selectionChangedHandler(event)" 
                        dataProvider="{_greetingData}" width="60%"itemRenderer="GreetingItemRenderer">
                        <layout>
                                <VerticalLayout />
                        </layout>
                </FxList>
                
                <Form borderStyle="solid">
                        <FormItem label="ID:">
                                <Label text="{_greeting.id}" />
                        </FormItem>
                        <FormItem label="User:">
                                <Label text="{_greeting.user}" />
                        </FormItem>
                        <FormItem label="Content:">
                                <FxTextInput id="vContentEditTxt"text="{_greeting.greetingContent}" />
                        </FormItem>
                        <ControlBar>
                                <FxButton id="vSubmitBtn" label="submit" click="edit()" />
                        </ControlBar>
                </Form>
                
        </VGroup>
        
        <TextBox text="by sban" color="gray" bottom="10" right="10" />
        
</FxApplication>

上一页  1 2 3 4 5 6 7  下一页

Tags:基于 flex 技术

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接