Showing posts with label GWT. Show all posts
Showing posts with label GWT. Show all posts

Sunday, February 21, 2010

TDD - what should go first

Hi.

Plenty of time has passed since the last time I opened The Blog.

The topic of the day is 'how you write code good'. I don't remember times when I had enough time for the unittests. So, i'm trying to figure out several rules for myself to stay when working. Now the following sequence seems to be doing its job:

How this happens now. I want to write a new business-logic method:
  1. I create a method stub in a (bean). With the name only.
  2. I think of what should this method get as input, and what should produce in output, in both normal and exceptional cases.
  3. I modify method to the correct signature.
  4. Then - i generate javadoc ;). In the javadoc I write down all the thoughts I had when was doint 2. of this list.
  5. I go to test. And create 1 test class for this method. In this class, I do write one-by-one all the cases (negative and positive) of how it's done.
  6. Mocking - I'd use it, but yet we have a pretty well-done structure, so I can rely on live objects. Though, I'd try using mockito for the brand new things.
  7. I run tests - they fail. That's good :)
  8. I implement method - tetsts should start working. If one of them fails, I need to correct either the tests themselves or the method - depending on what's error.
/me knows that all the stuff above is well-known, wide-used and so on. The list should be treated as a reminder for myself.

Tuesday, September 29, 2009

Google Web Toolkit RPC serialization error and Collections.EMPTY_LIST (Collections.emptyList())

Well, heading made my day.
Actually java.util.Collections.EMPTY_LIST and java.util.Collections.emptyList() are not GWT-serializable and will cause SerializationException being thrown on attempt to transfer them across the wire.

Beware!
Use new ArrayList() instead

Monday, September 14, 2009

Integrating Google Analytics and GWT

Problem is that GWT apps are single-paged by their nature; they are applications. Though, having way to track user's action would be good. No one cancelled custom-written stuff, but mature analytics tools such as Google Analytics would give you much more functionality.

Fast, and easy. Have not tried it yet - need to get rid of some pending work.
here's link to google groups discussion - http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/61912b40a2ca7b2a/

Shortly, you just load analytics script to your single-paged site as external script, and then manually call 'log' method from them to create records in analytics database. Pretty easy, huh?
Nice thread on GWT and SEO on GWT group.
You might have seen Ian Bambury on the web, with his http://examples.roughian.com/#Home GWT example site.

In this thread Ian describes way his application is indexed. Think this is cool, especially real-world experience in long-running gwt seo :)

Thanks Ian.









Thursday, August 13, 2009

GWT Canvas widget - drawing in a browser

Story

I believe many of you felt that some thing are hard to acquire with pure DOM objects and maniputllation. DOM puts you into hard fram. If you ever tried make something round-cornered, you know that count of the libraries doing this exceeds any reasonable task.

Methods used there are different: some use colored graphic corners, but don't allow you for selecting any color you want. Some of them need JavaScript runing on a page. Some need some weird markup, and tricks with the HyperText controls for IE. Some simply don't work well.

So, why not just to draw?

So, (how) can I draw in browser?
HTML 5 Canvas elements allows some drawings. But, making a web-application today, I'd not use this as a production decision. Simply because some old bad browsers don't know it.

And we don't want to make people feel lost because they are using IE6, do we? There's a solution, though. It's name is VML. It's Micro$oft answer to the SVG. (by the way, SVG is not that a good standard itself, too). Internet E$plorer does support VML, but the API is quite different from Canvas.

If we take 2 coverage areas - one of browsers already covered with Canvas tag (FireFox, all webkits, Opera) and VML (IE's) - we'll have plenty solid browser coverage.

The problems yet to be resolved is a cost of development. In order to get something working, you'll have spent more than twice more time than for single Canvas or for VML only.

So, (how) can I draw in browser? (GWT way)

When someone says about masking differences between the browsers, I always think of GWT. That's the best thing I love in it.

And, I used to search for vector graphics library for Google Web Toolkit.

I found one (just as a proof-of-concept) in the GWT-Widgets library. (There's also an interactive demo for the Canvas widget - you can draw different shapes over image just in a webpage without any flash, java or any other hard stuff).

Actually, I liked it.
Also, after incorporating the GWT-Widgets Canvas to a project, I found another one. This is demo for newer Canvas wrapper, and this is gwt-canvas project home page

The least I wanted to show you is the sample of Canvas working in the real world. The following is a way to see it (it's in Cyrillic, so I'll do verbose notes :) )
  1. The site is about calculation of the metal-plastic windows cost basing on different selections from user.
  2. Open up http://osnova.ks.ua
    It loads slowly, but wait until all the stuff is loaded.
  3. In the top navigation menu, select 'Посчитай!' item. This means 'Calculate' in english. It is the fourth item from the left, and it has vivid red background.
  4. You'll see a 'Выберите тип конструкции...' blue link underlined in the center of screen. Click on it.
  5. You'll see basic shape selector. The shapes themselves are drawn with canvas.
  6. Select one - and you'll get it big. Big shape with all sizes is also drawn with the help of canvas widget.
That's all for this site.

What I found good and bad in drawing on the webpage with GWT and Canvas

Pros:
  • It works
  • It works in different browsers
  • It works fast enought
  • Instrument palette is enough for many basic features
Cons:
  • As it is PoC, there are some issues. I've seen that sometimes wide lines disappeared in IE, leaving wireframe only.
  • You can NOT draw text. The text you see there - it is just images with letters. Actually, there's a solution for this - but it's weird. There's a pair of client and serverside script. Client sends request to the server with the phraze it wants to get. Serverside has the text with all the alphabet as an image, and then glues the phraze, thus creating image with the desired text, and then passes that by to client.
    That's too heavy for such a simple task
  • It can be done more easily with Flash, but this is a double-sided penny. You'll need your users to have Flash installed. From the statistics of people coming to this blog, 3 of 80 don't have flash installed. That's too bad for big amount of people. :)
Hope this stuff will be useful for you!

Friday, July 24, 2009

How to deal with big GWT applications

Well, this is a bit of personal experience.
Instead of making extra-large GWT app having all the functions at one place I would use 'mixed' approach.

'Mixed' means that we install different app features on different pages (yes, user would need to change page from time to time) and exchange data through server session storage.

This would give us several good points:
  1. Page is (oftenly) refreshed, thus freeing memory :)
  2. Not that much code to load/execute
  3. Ability to make more clean code (not so much intermodule communications)
  4. More structured and less complex code (no 'overhead for common'). That's the main, I believe.
  5. Ease of content rendering.
Bad things:
  1. It's not that sleek and smooth.
  2. Lots of requests to server. Additional files loaded (.cache, .nocache, all dependenices all the time. it's cached, yes, but anyway...)
  3. Weird compilation. Having 7 gwt compilations is even worthe than 1, I think. Though, can be well-automated with ant.
  4. Can not use anymore stateless server (so, not that easy clustering/performance scaling)

It's something that can be considered as 'good practice', and 'personal opinion'.
If I were starting large GWT project now, I'd design it as described here.

Btw, take a look at LinkedIn. :)

Tuesday, May 26, 2009

GWT FlexTable bug

Just faced a complex and really bad bug with GWT's FlexTable.

It tends to forget about the cells removed! So, if I remove some cells, and then add some more, the old ones randomly appear.

Problem is that I was developing really complex layout with dynamic cell manipulation and hard use of rowspan/colspan. And spent 4 hrs fixing algorithm :( :( :(..

Technical details
  • Methods FlexTable::clearRow() and FlexTable::clearCell() seem to be broken (at least in GWT 1.5). They do their job, but sometimes deleted cells reappear in table. That's frustrating.
  • This is also stated on the Google code tracker : Issue 1766
  • I avoided this problem by replacing calls to clearRow and clearCell to FlexTable::clear(). Yes, that's a heavy solution - but it did fit for me :)

Monday, March 23, 2009

Google Web Toolkit (GWT) Search Engine Optimization (SEO) demo will be soon

I'm going to create a little demo showing how one can make ajax-loaded content indexable by search bots.

Basic idea is to create "secondary site" - static one - showing EXACTLY the same content as primary one. If bot gets to secondary site, it can index it well because of static nature.
If user gets to the specific page crawled by bot, it just gets redirected to the dynamic version of the site, showing the same content.

Here are some key tools I'm going to use:
  • OpenSymphony SiteMesh - good decorating filter. It would allow us to wrap the entire page into some kind of template. For example, we could put navigation header/footer for bots and old browsers and redirect statement for modern browsers, deciding on user-agent.
  • Some Java-based CMS for generating/accessing content. Not decided yet. Even better is to use Wiki engine.
  • Google Web Toolkit, surely.
  • Tomcat as a servlet/jsp container.
Right now it seems to me that I don't need anything more.
So, waiting for a demo. Hope I'll have several spare hours to get hands on this interesting stuff.

By the way, there's one interesting problem I can see now: If I put static content inside HTML panel, this would cause problems with navigation and links. For wiki, especially. Any link displayed would lead us out of the dynamic application, which is not desired.

Alternate solution is to put content to the IFRAME element. Don't think I really like it, but...

Wednesday, March 18, 2009

Afraid of being banned by google for 'cloacking?'

Cloacking, basically, is idea of presenting different content to normal users and to bots. This malicious technique is used by bad people to increase their ranking at Google, and get traffic, while presenting to user content, which was not really requested by user. And there are some good news in the end of the article :)

Example of Cloacking (do not do like this!)
Here is just a rough example. Imagine, there's a page on the web with url http://exampledomain.url
If Google crawler gets to this page, it is presented with one version of page - clean, structured, full of text, headings, etc. This version of the page has lots of keywords, say 'free software download'. It is ranked good by Google bot.
It is possible to understand, who is 'knocking on the door' - machine or real user.
So, if an internet user comes to this page, he sees a face of some PR company showing up.

This is considered to be cloacking, and site may be removed by Google personnel from Google indices once they discover such bad behavior.

Problems for good guys
Ok, this anti-cloacking technology makes search indexes more clear, readable and reliable. But what if you have fully-dynamical site? Yes, site which is fully powered by javascript, or flash?
If its navigation done with javascript - you have problems.
If your application is build with the Single Page Interface - there's no correct way to make it indexable. (this is how guys from Redmond understand SPI)

Good news (for good guys only)
"The only hard and fast rule is to show Googlebot the exact same thing as your users."
These is very good news (yes, for me it's news. I know that posting has been published @07). This means, that your site will not go banned, if you show the same content for same URLs, but in different way.
So, some links:
Ok. Gone for now - will post something on this topic soon...

SEO and GWT

I'm going to research a bit what's going on the gwt and seo world now...
If you understand you don't know any of those words, GWT stands for Google Web Toolkit - tooling for creating rich web applications, and SEO stands for Search Engine Optimization.

So, getting hands on it...
In this posting, just 2 links to the documents I'm going to work on at first:
  1. GWT Google Group posting about SEO and GWT. Quite an old thread, something may have changed from those times. People which are well-known to the GWT society are writing, such as Sanjiv Jivan and Ian Bambury.
  2. A whitepaper on GWT and SEO from BackBase. I've only started reading it, so can not yet tell my opinion.
Hope that SEO is applicable for such complex and cool applications as ones built with GWT :)