30 Nisan 2009 Perşembe

Using GWT with Django


Well i tried GWT a few days ago and liked it very much. I'm not a js expert and for that reason dont use it too much in my web applications. But from time to time i need some fancy client-side apps to do ajaxian stuff easily. I had written an Independent Django app which was an ajax-driven event calendar. Therefore i did most of the work remotely via Django. I used jquey for ajaxian calls. But if i were a better js programmer i would do that job with less remote calls. But the Magic in GWT is cool you create your application with Java ; a very cool and easy language and it converts the written code into javascript which is compatible with most of the browsers. Therefore you dont bother with strange behaviour of the js and dont bother about if your code will run on BrowserA or BrowserX.

I followed the tutorial in GWT site and had a running application (StockWather). To complete that tutorial you probbaly would need to complete the StockWatcher firstly and then go on from here or you can just pull the code i wrote for that purpose from here[1] and just inspect it.

For communication of both ends i used XML,if you're not a fan of it you can use JSON also. I didnt use JSON because of the JSNI usage in Java code. I dont like hybrid codes like that...

  1. First create the server side code in Django :LINK
  2. You need to build a GET request in you JAVA code so u do that from here: LINK
  3. Parse the incoming XML string from Django and convert it to JAVA objects: LINK
  4. Write unittests for your client side code (GWT) because if you have errors u will get some strange JS errors which are not so decsriptive. : LINK
  5. Put GWT application in your media and put the generated HTML file in your templates directory.

Well that is all,it took some time to glue both of them (Django and GWT) but we have here a happy end :) GWT is cool but it has some little weird stuffs i dont understand yet. One of them is Designing the applications.I should find
an easy way to explain it to my designer :)

[1]: GWT-Django app

8 yorum:

drozzy dedi ki...

Wow, that parsing of XML is just scary! Are you sure there is no better way of doing this then with an error prone parser?

Just comparing the python to java code is like comparing clean water to a sewage treatment plant.

How can one even stand programming in Python and Java simultaneously?

Unknown dedi ki...

Thanks for your comment, i'm not a fan of Java also. But, in real world not everyone is looking for Python developers :) Also writing the client side code in Java is better than writing in JS. The XML part can be done in a better way of course. As i mentioned there are 2 ways to do it in GWT i chose parsing the XML :) It was just a test to see how Django and GWT will glue together ...

VanOk dedi ki...

Zdrastvuite!
U menja est' predlojenie. Smojete pomoch' v sozdanii addona k igre?
Ochen' nujen chelovek znayshchii Python, vot tol'ko cheloveka nikak ne naiti.
Nu ili skajite mojet kto smojet pomoch'.
Ochen' nujno. Zarane spasibo

Unknown dedi ki...

@VanOk
I dont understand your language,please use English ...

Adsız dedi ki...

Странно, искал совсем не это, гугл выдал Ваш сайт, и судя по всему не зря, есть что почитать! Goodwork!

Ali E. İMREK dedi ki...

Well, how can i send XML variable to Django app from GWT?

I've tried to use setRequestData("...") method of RequestBuilder in GWT and to take raw_post_data of HttpRequest in Django. But raw_post_data was empty.

Unknown dedi ki...

Hi, what do you mean by sending xml variable ? It shouldnt be different than sending normal get request to server .https://github.com/makkalot/pyalgorithm/blob/01334d2a6216e75b6f499939ec1d9a7f696153bf/gwt_test/static/WithPlugin/src/com/makkalot/client/WithPlugin.java#L97

And on Django side just handle it as it is regular get request.

Ali E. İMREK dedi ki...

Thanks for reply. I'm new on GWT.

I don't sure about difference, because the variables are sending by url in the code you've linked "stocker/?q=..."

But I want to set my vars via setRequestData("...") method of RequestBuilder, or like this;

builder.sendRequest("something... json, xml long string etc...", new RequestCallback()

I'm sure to sending succesfully, seeing on Firebug POST tab as Source data, but I cant get by django side code.