Posts Tagged: Grails


27
Apr 11

Empty img src or Freaking repeated request problem

Hi! This is a victorious and quick post I have to make. (: And here is why. It took me two days of debugging and googling to find out the cause of a freaking problem: browser kept up sending same request for one of the pages of a Grails app I am working on now. The reason is an empty ‘src’ attribute of an <img> element (actually, it can be any element referring to loaded resource like a .js or .css file or any media content). You can read more about the problem itself here: Empty image src can destroy your site. I myself would probably never face this problem if didn’t have captcha (generated for each request to the problematic URL) and an optional image.

And here’s the solution:
1) in server code

<img ${ !url?:’src=”$url”‘ }/>

(in Grails terms meaning: don’t render the ‘src’ attribute if the url is empty)

2) in client (javascript) code:

imgElement.src = null; // don’t set img.src to empty string, though null is fine

So first, never ever leave your ‘src’ attribute empty! And second, never ever set ‘src’ value to empty string programatically or by any other means. Third, it’s ok to do this when it’s officially fixed either html5 is fully supported by all major browsers (hopefully).

Have a good one!


11
Jan 11

Grails on GAE – I’ve gotta make it work!

Day 1: failed migrating an existing Grails application to GAE…

Day 2: a new extremely simple Grails application (one domain class!) crashes on rendering the “create” page…

Am still fighting…


15
Oct 10

The Best Web Framework for Java

This post is a duplicate of my answer to a Sergei Batiuk’s question in the Java EE Professionals discussion group on LinkedIn. The question was “Which Web Framework for Java do you find to be the best?”, namely:

“After years of development in Java, including web development, I find it hard to find a perfect web framework, while there are a lot of them out there.

The common problems are:
1. Most of them can be configured only by XML, but sometimes or most of the time I need to configure them programmatically;
2. The URLs they produce are not nice. http://website.com/index.faces, http://website.com/index.action – are you kidding me? URLs are very important when it comes to SEO;
3. The workflow model is typically inefficient;
4. Modularization is typically compromised. You cannot, for example, package JSPs into jars to distribute as modules because all JSPs must be withing the root of a web application.

The list can go on and on… What do you think about it? Is there a web framework the works perfectly for you?”


So, to make it closer to the point I’ll give you my opinion specifically in terms of web frameworks (front-end), and not data access/infrastructure/etc aspects.

Preference: from my recent experience, I would support votes for Grails, which allows you to virtually forget about configuration burden and to implement simple to fairly complex things in a very simple way.

Regarding the mentioned weak points:

* 1), 2) and 4) are pretty much supported by major web frameworks – so I can’t really see a problem here;

* 3) for workflow type web applications – Spring WebFlow is something really worth to look at (it can be married with major MVC frameworks easily) – I had very positive experience with it in a previous project. However, to answer this point appropriately, Sergei, could you please explain what you mean by “inefficient workflow model”?

Answering “Is there a web framework the works perfectly for you?”, as there’s no single remedy for every case, I would identify three major types of web-applications and appropriate framework types accordingly:

1. For intranet sufficiently massive enterprise applications with advanced data management requirements (in this case, normally standard look&feel tends to persist through the whole application) – component-based frameworks is my choice

* e.g., GWT, JFS implementations, wingS framework (the latter is quite interesting and good try to imitate Swing in the web – I used to love Swing model – though I’m not sure about the project’s current status, the latest version is dated to 2008-04)

(I’m not much experienced with RCPs like Flex, but my level of familiarization with them lets me identify them as suitable into this category, too)

2. For Internet fancy looking applications – combination of MVC + template-based + javascript solutions.

* e.g., Grails (gsp is pretty much similar to jsp, not by sounding only :) ), Spring MVC, Struts 2 + Freemarker, Velocity, Sitemesh, JSTL + jquery, yui, jprototype – whichever you are most experienced with or give your personal preference to.

3. Small few-purpose applications aimed at solving existing temporary problems quickly – you basically don’t need any framework, go with plain old (and dirty) jsp! :) … or if you have experience with, make quick consideration of Grails / Spring MVC. :)

I hope, this, despite quite high level, overview sheds some light on the problem.