Friday, June 24, 2011

First Project Done

After playing around with GWT for a while, I managed to finish up with my first project. Its a very simple project to help me learn how GWT works. You can see the demo here http://quynh-nguyen.appspot.com/. Notes that I created the site for educational purpose so I didn't go over fine details such as RegEx matching for email field input or the length of username/password. Those features can be implemented easily though.

What I learned from this project:

  • Use UiBinder! It saves lots of time and speed up your website!
  • Use HTML as much as you can. Don't reply too much on widget because it can cause slowness on your site.
  • Usage of PersistenceManager and Datastore.
  • PersistenceManager can only fetch what exist in the data; so, it will throw an errors if you try to fetch something that is not existed in datastore. Thus, to check whether an object exist in datastore or not, you can use transaction with datastoreservice API instead.


DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

Transaction tnx = datastore.beginTransaction();

try{

     //first param is your ENTITY, second is the value of your ID/Name

      Key userKey = KeyFactory.createKey("User", username);

      datastore.get(userKey);

     //If found then do some query/task with your PersistenceManager or DataStore here

   

     //Don't forget to commit :)

     txn.commit();

}catch(EntityNotFound ex){

    //not found codes go here!

}finally{

     if(tnx.isActive())

         tnx.rollBack()

}


  • Cookies won't work when you try to use it on serverside. It will give you URI encoding errors when you try to call it over RPC. Yup, took me 2 hours to figure out -_- COOKIES = CLIENT SIDE!!!!!
  • I also learned how to use ClientBundle but never tested it out with this project so maybe the next one :)
I think thats about it. Next Task: GWT MVP pattern to refine my spaghetti code!!

No comments:

Post a Comment