Skip to content
Apr 12 10

Upgrading Grails, GWT, grails-gwt plugin and beyond

by dkberktas

@Remotespots project was started a couple of months ago and and after some time all the technologies were updated to their current versions (Grails 1.2.2, GWT 2.0 which is a huge change from 1.7, and finally grails-gwt 0.5). Since we were busy w/ the features we ignored the upgrade but time has come to sent Remotespots to the wild, and we want it to be ready to its limits. Below you can find the steps and obstacles we encountered during the upgrade process. (I switched to Ubuntu from Windows XP, my headphones are still not working but at least I can open Eclipse under 60 seconds! so the things below is tested on Ubuntu 9.04)

  • Download and change GRAILS_HOME to new grails version (1.2.2)
  • Run grails upgrade
  • Run install-plugin gwt (so that it installs 0.5)
  • First obstacle
  • Error executing script CompileGwtModules: No such  property: usingGoogleGin  for class: _Events
    gant.TargetMissingPropertyException: No such property: usingGoogleGin for class: _Events
            at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:329)
            at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
            at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
            at gant.Gant.withBuildListeners(Gant.groovy:344)
            at gant.Gant.this$2$withBuildListeners(Gant.groovy)
            at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
            at gant.Gant.dispatch(Gant.groovy:334)
            at gant.Gant.this$2$dispatch(Gant.groovy)
            at gant.Gant.invokeMethod(Gant.groovy)
            at gant.Gant.processTargets(Gant.groovy:495)
            at gant.Gant.processTargets(Gant.groovy:480)

    To solve it, run grails clean command and empty ~\.grails\1.2.2\scriptCache folder. I found this solution from this link.

  • Another problem you are likely to see is
    grails  GWT module ... may need to be (re)compiled

    To solve it, run grails compile-gwt-modules command and refresh firefox w/ ctrl+f5 OR alt+shift+r

  • Last thing to be careful is, after started the gwt client with the command grails run-gwt-client, since GWT 2.0 get rid of hosted mode (finally), to see the changes on your code w/out restarting the server, add the suffix to the url ?gwt.codesvr=127.0.0.1:9997, from this link, you can find the solutions to the problems people have w/ the grails-gwt plugin.
Apr 2 10

GWT — Calling a Java Method from Handwritten JavaScript

by dkberktas

For the remotespots project, we developed a notification panel which is very similiar to Stackoverflow notification bar. So, what this bar provides is the a HTML message and a close bottom at the right end.

For the close button, instead of adding a hyperlink from the java code, this time we used JSNI which enables you to integrate JavaScript directly into your application.

We have a class called GenericNotifcation in the package org.remote.dogan.client. When a noticition bar is needed,

public static void showNotification(String message, int seconds)

is called.To hide the bar the following method is called,

public static void hideNotification()

So, to make the JSNI close method call from js, we need to call the hideNotification java method from js.

To do this, we add amethod to register hideNotification method a js method for the handwritten javascript

public static native void exportStaticMethod() /*-{
$wnd.closeNotification =
	@org.remote.dogan.client.GenericNotifcation::hideNotification();
}-*/;

As a second step, we should call the method exportStaticMethod() to actually make the registration of the js method. We do this in showNotification method but for a generic case, onModuleLoad is good candidate.

public static void showNotification(String message, int seconds)

{
GenericNotifcation.exportStaticMethod();
...
}

So as the last step, we add the js call in the html template like the following:
<a title=”close this notification” onclick=’closeNotification()’ />x</a>

For further information, the documentation for GWT JSNI is here.

Mar 31 10

Using GWT Listbox with Unicode

by dkberktas

In our new project remotespots.com, we use GWT for the front end. Since remotespots supports two languages (English & Turkish), with a listbox we enables users to select which language they are going to use.

GWT’s Listbox is a combo box basically. GWT support HTML in most of its widgets, but this is not the case for ListBox. You can only add String instances to a listbox.

This cause problems with characters which are non-english like ö ü ç

In such a case, to overcome the problem, unicode representation should be used.

ListBox lb = new ListBox();
lb.addItem("English", "en");
lb.addItem("T\u00FBrk\u00E7e", "tr");

The full list of the unicode representations,  this link can be used. (http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/TURKISH.TXT)

Jan 26 10

Using Twitter oauth on GAE/J

by dkberktas

Twitter supports oauth and there are many libraries for it, for  Java(twitter4J)(oauth-signpost),  most of the time you see examples of a desktop version, so it can take time to implement it on a web application (it did take time for my case).

Step 1. Get a Twitter account and create a Twitter application from http://twitter.com/apps (don’t forget to check in browser and enter a  valid callback url.

Step 2.  Download twitter4J add the library (in my case twitter4j-core-2.1.1-SNAPSHOT.jar) to project and update classpath

Step 3. Create a web application (I assume you have the Google plugin for Eclipse )

Step 4. Add the following servlets and update your web.xml. First servlet will handle login part. It will create a RequestToken which will create the magical aggrements between the consumer(your application) and provider(twitter). First servlet save the  token and secret token since we will need them later.

String token = requestToken.getToken();
String tokenSecret = requestToken.getTokenSecret();

Step 5. You forget to update web.xml didn’t you, update the web.xml

Step 6.  Enable session by adding

    <sessions-enabled>true</sessions-enabled>

to appengine-web.xml.

You can see my version from http://90.latest.denemekaya.appspot.com/login

ps. don’t forget to set the callback in Twittter to the url of the servlet for callback.

Links:

  • http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/
  • Explain the same procedure with Grails — http://blogs.bytecode.com.au/glen/2009/12/08/log-into-your-grails-app-using-your-twitter-credentials.html
Jan 24 10

Smashing Magazine’den 10 Kullanilabilirlik Ipucu

by dkberktas

Smashing Magazine karsilastigim cok guzel bir yazinin, Turkce ozeti sayilabilecek bir post. Elbette cok cok kisaltilmis bir ozetidir. Yazinin orijinal hali burada.

1. Form yaratirken iki kolonlu tasarim yerine, dikey tasarim kullanin, cunku kullanicilar formu yukaridan asagiya tarayarak doldururlar. Bir diger noktada form’daki aciklama yazilari koyu renk (bold) olmamali.

2. Kullanicilar yuzlere odaklanir. Eger yuz bize degilde, ekranda baska bir yere bakiyorsa, yuzden sonra kullanicilarin bakacagi diger nokta, bakis dogrultusudur.

3. Tasarimin kalitesi, guvenirliliginizi arttirir. Okurlar kitabin kapagindan kesinlikle etkilenirler, bu web icinde gecerli. Eger  tasarimdaki yerlesim, tutarlilik, tipografi, renk, still uyumluluk gosteriyorsa, bu ziaretciler uzerinde olumlu etki yapacaktir.

4. Kullanicilar scroll kullanmazlar. Kullanicilarin %77 scroll arayuzunu kullanimiyor, bu yunden sayfanin yuklendiginde gorunen kismi cok onemli.

5. Linkler icin gecerli renk MAVi.

6.  Arama kutulari icin ideal genislik, 26 karakter.

7. Beyaz alanlar algiyi arttirir.

8. Sadece 5 kisiyle yapacaginiz kullanilabilirlik testi, sitenizdeki kullanilabilirlik sorunlarinin %85′ini cozecektir.

9. Urunleriniz icin bilgi acisindan aciklayici sayfalar hazirlayin, sadece kisa bir sure bakacak olan ziyaretciler icin bile daha gecerlidir.

10. Kulanicilarin cogu reklamlara (ya da reklama benzeyen ogelere) karsi kor gibidir.

Jan 18 10

Using Memcache with Google App Engine (GAE/J)

by dkberktas

A simple beginning — Fragman iPhone Application

Memcache provides convenience to store a frequent query in memory, so that you don’t have to make the same execution over and over again. For the iPhone application I build (Fragman), I build a GAE/J backend for managing movie names, IMDB URLs, thumb images, video files, etc. It interacts with the Obj-c code via calls encoded in JSON.

Since the categories are updated so frequently (new trailer, top 250 , soap opera trailers), every time the user starts the application from her iPhone, the corresponding categories Id(key) lists are  created which includes all the aspects mentioned above,

what I see, after people start to use the application that, most of the time, the application got stuck with the time constraint of GAE and this causes inconvenience, so I decided to hold the category lists’s JSON in memory. Following is the code ,

this is the servlet for creating the JSON which is called after say upcoming movie list is changed. This servlet updates the memcached list

        List keyList = new ArrayList();
	static Cache cache;
	static
	{
		try
		{
			CacheFactory cacheFactory =
CacheManager.getInstance().getCacheFactory();
			cache = cacheFactory.createCache(
Collections.emptyMap());
		}
		catch (CacheException e)
		{
			// ...
		}
		//.....
                public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
	        {
                       //................
                       if(cache.containsKey(mode))
		       {
			     cache.remove(mode);
		       }
		       cache.put(mode, keyList);
	        }
                //........
          }

And this is the servlet that fetch the Fragman beans from the datastore with the given keys (key list is got from the memecached list)

          keyList = (List)cache.get(mode);
By doing this, I reduce the time that the servlet that creates the JSON takes.
Jan 18 10

Fragman iPhone Application

by dkberktas

Film fragmalarini ve trailerlarini iceren yeni iPhone uygulamasi Fragman app store’da yerini aldi.  Vizyon, gelecek, dizi ve Top 250 (imdb top 250) kategorilerini iceriyor, su an icin oldukca guncel :) devamini da getirmeyi dusunuyoruz, yardim etmek isteyenler olursa cok seviniriz. Uygulamanin web sayfasi http://ifragman.com.

app store

Jan 13 10

Yeni Tohumlar — etohum 2010

by dkberktas

2009 bizim (ben ve yekmer) için çok heyecanli bir yil oldu. Bunda etohum’un ve Burak hoca‘nin payi çok büyük.

Bu sene etohum 20 Ocak’ta yeni tohumlari duyuracak, inaniyorumki etohum bu sene daha da etkili ve basarili olacak. bu sene geçen seneki gibi girisimcilere 4 günlük bir kurs verilecek. 2009 yilinda bogaz manzarasi esliginde yapilan kurs, bu sene akdeniz sahilllerine tasinmis :) bir de incubator acilldi, bu sene etohumcular için harika geçecek sanirim. ilgili etohum linki‘de budur.

Dec 19 09

A Simple Chart for a GWT Application on GAE/J

by dkberktas

I am trying charting solutions for a GWT project and gchart seems a nice one. After some digging I create a sample project which is hosted on Google App Engine (GAE) demo. Source code is at Google project

The chart will show the remaining number of months in the current year.

  • First download the jar from the project home page http://code.google.com/p/gchart/
  • Put it under war/WEB-INF/lib and add the gchart.jar to your classpath
  • Create a  Web Application project called it GChart-samples (I assume you have Google Eclipse Plugin and follow the basic steps from here)
  • This step is for make-up, find GChart_samples.html under war/WEB-INF and clear the part between <body> tags.
  • Open GChart_samples.gwt.xml and add the following line
    <inherits name='com.googlecode.gchart.GChart'/>
  • Create a class in client folder called FirstChart and change it as the following
    package com.dogan.kaya.client;
    
    import com.googlecode.gchart.client.GChart;
    
    public class FirstChart extends GChart
    {
    	public FirstChart()
    	{
    		setChartSize(350, 350);
    
    		addCurve();
    
    		int[] data = { 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
    		for (int i = 0; i < data.length; i++)
    		{
    			getCurve().addPoint(i + 1, data[i]);
    		}
    		//curve customization
    		getCurve().getSymbol().setHeight(10);
    		getCurve().getSymbol().setWidth(10);
    		getCurve().getSymbol().setBorderColor("black");
    		getCurve().getSymbol().setBorderWidth(3);
    		getCurve().getSymbol().setSymbolType(SymbolType.LINE);
    		getCurve().getSymbol().setFillThickness(2);
    		getCurve().getSymbol().setFillSpacing(0);
    		//chart customization
    		getXAxis().setAxisMin(1);
    		getXAxis().setAxisMax(12);
    		getXAxis().setTickCount(12);
    		getXAxis().setHasGridlines(false);
    		getXAxis().setTickLocation(TickLocation.CENTERED);
    		getXAxis().setTickLabelFontSize(10);
    		getYAxis().setAxisMin(0);
    		getYAxis().setAxisMax(12);
    		//to get inteter values on y axis, be careful
    		//about the number of intervals it can be tricky
    		getYAxis().setTickCount(13);
    		getYAxis().setTicksPerLabel(2);
    		getYAxis().setHasGridlines(false);
    		getYAxis().setTickLabelFontSize(10);
    		//
    		update();
    	}
    }
  • Open GChart_samples class and change it like the following
    package com.dogan.kaya.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.RootPanel;
    
    public class GChart_samples implements EntryPoint
    {
    	public void onModuleLoad()
    	{
    		RootPanel.get().add(new FirstChart());
    	}
    }
  • My output is sth like that

ps:

some nice links about gchart are as follows:

  1. gchart homepage
  2. A simple tutorial at http://whatwouldnickdo.com/wordpress/264/simple-charts-in-gwt-with-gchart/
Dec 11 09

Back to basics — A simple beginning to Grails

by dkberktas

I guess I can finally finish my search for a good server side companion (at least for now).  A couple years ago RIFE was my only choice but unfortunately, it didn’t work out well as I expected (RIFE is an open source project but partly because of developers like me  who uses the framework but doesn’t pay his gratitude by adding sth to it, RIFE for the time being a dead project (at least for me!))

Anyway, for some time I consider turn back to good old J2EE, then wander on the land of some other Java enterprise frameworks (Spring MVC, Wicket, Struts 2, Hibernate etc ) then Google App engine Java with its in progress full stack framework like environment. Then I decide that all the ones mentioned above has steep learning curves and without feeling complely comfortable with them, It is imposible to develop sth quickly.

Then the obvious direction was rails. First give a try to Django, then read some about  RoR but both of them somehow scare me out. I need to learn a new language (which Django tutorial specificly warns about looking a good python tutorial before devlde into Django), on the other hand, Grails (my love!) just start the sentence with “don’t worry about the groovy, you can learn it along the way”.

Obviously, Grails is relatively new compared to two other alternative and it has (or used to have) to many bugs for a relaible product.

But trust me, it is easy to just start and kick the first alfa version of sth out is a joy.

Ok this post is suppose to be a yet another introduction to Grails tutorial, so…

Steps to Get Started

1.  install Grails (there is nothing I can add here — http://www.grails.org/Installation)

2. open command line and create a project with grails create-app Yeap

3. Go to the created directory cd Yeap

4. Type grails run-app

That’s it!

I’m currently using Apache Shiro plugin (previously JSecurity), Gwt plugin, Postgresql, Eclipse for the development, More posts related to these will be here soon (I hope)