Thursday, December 23, 2010

after a request, page reloads 2 times and contains very little html

I just fixed a very strange issue in our application.

It went something like this:
User would click on a link that opened another page. This page would flash for a second, then another page would open containing just the string "2010".

The bug came from QA as being a regression related to recent development, so i started debugging in the code. There was nothing in the logs.

Then i opened firebug, went into "net" mode and persisted it. I saw my original request made, along with headers, and then another request made, this one had no headers at all.

Solution:

document.write is evil. There was recently a change to the code which attempted to make the copyright year dynamic by replacing it with
document.write(new Date().getFullYear());
inside of a script tag. This alone wouldn't cause the issue, but document.write only works correctly if its called when the page is being rendered. If the page is rendered, it will overwrite the entire page with whatever its writing out. The issue was the the page the user was going to next, was gotten via ajax, and thus the script was called after the page was loaded, overwriting the entire page.

Oh the glory of being a programmer.

Saturday, December 04, 2010

Convert map to object in groovy

You need to convert a map into an object in groovy. There must be a better way then iterating through the map and setting all the properties in the object via reflection or otherwise. There is:


posting with syntaxhighlighter

I always forget the markup for posting syntax highlighted code. here it is:

<script class="brush: java" type="syntaxhighlighter">

thank me later