Google App Engine for Java has been open since April 7 this year, less than 20th, but there have been many blog posts about Gae for Java. After data storage, this lesson is to study how to manage greeting through the client, that is, curd implementation.
One, the list shows
Add an interface to get all greeting in Sban.flexblog.HelloWorld.java:
public List<Greeting> getAllGreetings() {
List<Greeting> result;
try {
result = (List<Greeting>) pm.newQuery(Greeting.class).execute();
} finally {
pm.close();
}
return result;
}
In the example above, Pm.newquery (Greeting.class) is responsible for querying all the stored greeting information. The List data is mapped to ArrayList in the Flex client.
Modify the Index.mxml client code, after which the final code is as follows:
<?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= "ten" right= "ten"/>
</FxApplication>