基于flex4技术从零开发flex博客系统 : 5 数据存储之管理Greeting
2009-05-05 12:06:18 来源:WEB开发网本文源代码下载地址:
http://flashview.ddvip.com/2009_05/flex4-lessons4-5.zip
Google App Engine for java自今年4月7日开放申请,至今不足二十日,但关于GAE for java的博文已经出现了不少。继数据存储之后,这一课要研究如何通过客户端管理Greeting,即CURD的实现。
一,列表显示
在sban.flexblog.HelloWorld.java中添加一个获取所有Greeting的接口:
public List<Greeting> getAllGreetings() {
List<Greeting> result;
try {
result = (List<Greeting>) pm.newQuery(Greeting.class).execute();
} finally {
pm.close();
}
return result;
}
在上例中,pm.newQuery(Greeting.class)负责查询所有已存的Greeting信息。List
修改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();
}
]]>
</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()" />
</HGroup>
<FxList id="vList1" dataProvider="{_greetingData}" width="60%"itemRenderer="GreetingItemRenderer">
<layout>
<VerticalLayout />
</layout>
</FxList>
</VGroup>
<TextBox text="by sban" color="gray" bottom="10" right="10" />
</FxApplication>
更多精彩
赞助商链接