I went thru several tutorials and projects on my own to learn a bunch of stuff and thanks to the many forums and such for helping.
I wound up checking out VistaFei and it's been a great help.
I checked out Googlipse which was cool too, but w/o the GUI editing I wasn't convinced I needed it.
Also this tutorial by Robert Hanson was VERY helpful to get started.
To download VistaFei, you have to register w/ the forum and then go to this post (or this post for mac). It only shows the links if you're logged into the forum.
You'll need some things (see this post) like Java5 and the GWT of course.
So I went thru the tutorials and such from the forum. Very cool and played around with it on my own.
A few things that were helpful to learn...
- the GWT page on IsSerializable doesn't mention that a Serializable class needs an empty/default constructor
- GWT seems to only allow/support JUnit testing for the 'client' package
- VistaFei regenerates all the generated code so back up your changes
- RPC callbacks need a way to communicate their results back to the entry point class
These last 2 points are my focus here...
Generated code
When VistaFei generates the code, it overwrites the existing code which makes sense. However, if you've made changes to that code, you'll need to back it up somewhere. Currently, I put all my code at the bottom (and fully qualify the references so that I don't have to change any imports) and back it up to a file named <file name>_code.txt. I intend to write a script to find those files and put the code w/in the last curly-bracket in the appropriate file (or you can and send it to me unless someone has a better option???).
Similarly, the RPC server implementation classes are overwriten w/ the default (relatively) empty methods. I wrote 2 .bat files that back these files up and restores them... when I remember to do it. :)
Using the VistaFei properties area, I added code to the onClick event and such. I tried to keep it simple like 'handleAddEvent();' so that it doesn't ever need to change. Then I add that method at the bottom.
RPC Callbacks
When it uses RPC, I usually call a class like ControllerRPC w/ static methods to handle the RPC. I pass in the caller ('this') for any callback processing. The ControllerRPC gets the appropriate ServiceManager class that VistaFei generated and runs the request method. I create the callback w/ the success and failure methods.
Since I have the calling class, I can call whatever method I need to on it (generally something I write since most of the members/methods of the caller are private since it's the entry point class: generated, gui).
So the entry point (MyApp.java) gets the onClick event for the 'Add' button and calls handleAdd(). That method calls ControllerRPC.addItem(sName, this) which gets the AddItemServiceManager.INSTANCE and calls requestAddItem(sName, callback) where the callback is defined w/ the 'accept' and 'failed' methods. Something like this (forgive the formatting)...
public static void addItem(final String sName, final MyApp theApp)
{
AddItemServiceManager asm = AddItemServiceManager .INSTANCE;
asm .requestaddItem(sName, new AddItemIResponse() {
public void accept(Object result) {
// TODO Auto-generated method stub
System.out.println("accept");
theApp.setItemAdded((AddedItem)result);
}
public void failed(Throwable caught) {
// TODO Auto-generated method stub
System.out.println("failed: " + caught.getMessage());
}
});
}
The parameters need to be final if you're going to manipulate them. The above method is the way it's done in the VistaFei RPC tutorial but I cdn't tell it from the website. I had to download the source which is on that same page.
Dig around the VistaFei forum and the GWT doco - in particular the Developer's Guide. Also, the blog, forum, developer's groups, etc. are helpful of course.
BTW, I'm using db4o for my backend, server side database and it rocks.... HARD!
I hope some of the above is useful to someone. Please leave comments/questions either way.
Also, if anyone has better solutions for protecting your custom code in the generated classes, let me know.
3 comments:
Looks pretty good, thanks for sharing
hi,
for the "code generate" problem,I'll share what I did ,
Firstly, add your own code in some file(e.g. MyApp.java which is the EntryPoint file),
after your work, then open that file in 3rd party editors(I use EditPlus,the UltraEdit is also OK)
run the Generate code in VistaFei,as you said ,the file MyApp.java will be cleaned up,your job just did was erased,but,don't worry
active EditPlus,there will be an pop up window tell you the file content has been modified by others,do you want to load it? just click "No",because current the file was our work! then click "Save" in EditPlus ,there also an pop up window ask you whether you want to save it anywhere, click "Yes"
Open VistaFei,one pop up window tell you the content has modified,want to load it again, of cause,click the "yes", ohh, our job returned!
wish this will save your time and effort, any other good method or comments, just contact me directly with MSN phray2002@hotmail.com or send mail to phray.zhang@hotmail.com
I'm basically done w/ the site I was working on w/ the GWT stuff: http://www.giftparrot.com
Post a Comment