Wednesday, July 14, 2010

I need to be pampered

So, I’ve sort of fallen off the blog wagon, an event that I think was noticed by exactly one person -- me. But I have legitimate excuses. In the past month, I’ve had a daughter and launched a brain child -- Cry From The Cubicles.

I’ll keep the proud parent gushing confined to Facebook and limit my talk here to the Cry From The Cubicles. The site has a tag line of ‘Workplace Insanity Shared’, and I believe that is as succinct a description as possible. We all see things every day at the job that are funny, or aggravating, or don’t make sense. I have a whole network of friends that IM me every day with the latest office occurrence that has made them take pause. The site is basically a shared version of this.

The prime technology leveraged is Grails, which I have come to fall in love with. No, its not the right tool for every job, but there is probably no better tool in the Java world for RAD & agility. I will post more about my experiences with it soon.

In the meantime, I will be changing diapers, earning a living and getting new features implemented in cry from the cubicles. Wish me luck! I need it!

Saturday, May 29, 2010

Grails UI Performance Plugin is THE BOMB


So, I added the grails UI performance plugin to my app over the weekend. It basically promises to provide build and app support for the 14 rules of High Performance Websites from Steve Sounders.




These are things like:


  • Adding far futures expires headers to relatively static resources like images, CSS and JS

  • minification and compression of CSS and JS

  • bundling of different CSS and JS files into singular files at build time

  • Keeping the CSS at the top of the page and javascript at the bottom





But does it work? Yeah, it appears to. I ran some tests having the performance tuning on and off. This first picture is with no performance tuning (cache primed). The page took 3.57 seconds to render.




No performance tuning with primed cache





This second picture is with UI performance plugin turned on. The page took 1.74 seconds to render, and the number of requests for resources dropped dramatically. That is a 48% increase in performance, and if you look at the time to return the HTML page, it was significantly higher the second time around.





All in all, it took about 2-3 hours to get the plugin wired up appropriately for my app and to make the view change necessary. In the future, I would probably wire this plugin early so you can use its tags as you go. Also, this only applies to the app when running as a war, so use grails run-war to test it out. Once you have it configured, you will need to turn it off in the development environment to be able to run your app with grails run-app again. This just requires uiperformance.enabled = false in your development config.

Friday, May 28, 2010

Cryptic grails bug

So, I ran into a grails bug with link creation as I near closer to a prod release of my super-duper top secret site.


<g:createlink absolute="true"/>


will *always* render a link that is HTTP and on the unsecured port (80 or 8080), even if the request was of the rendering page was HTTPS. It seems like there should be a property to have it honor the protocol & port of the request.

Actually, looks like this is a known bug: http://jira.codehaus.org/browse/GRAILS-3625

The workaround I used was to create a custom tag that would output the base for an absolute URL:


def baseUrl = {
out << "${request.scheme}://${request.serverName}:${request.serverPort}${request.contextPath}/"
}


I could then chain the tags together to create links I wanted:


${baseUrl()createLink(controller: 'foo', action: 'bar')}


This worked fine enough in my case, the fix was simple, but figuring out there was an actual bug in the framework that required a workaround on my part took some time.

Saturday, May 1, 2010

So I dig me some grails named URL mappings. They allow you to associate a logical name with a URL mapping, and then to specify that name later when rendering links with the
tag to have it write the URL appropriately. Here is an example...

In UrlMappings.groovy:

name profileMapping: "/profile/show/$alias/$listOd?" {
controller = "profile"
action = "show"
}


In a GSP page:

<g:link mapping="profileMapping" params="${[alias: profile.alias, list: currentList.id]}"/>


This is important, because often the default mapping of /controller/action/id is not the best suited for the task. You might want to specify something more human readable than a numeric ID for usability and SEO, for instance.

Anyway, this is just another reason I really like grails.

Thursday, April 29, 2010

REST Client Firefox Plugin

So, I do a lot of work with ajax/json or RESTful services exposed to the an HTML/JS or Flex client. When testing such services, I find it very useful to develop and test them in isolation from the client to make sure things work as they should. Then I can wrap the service calls in whatever client logic is appropriate.

A great tool for quickly testing these services is the REST client Firefox plugin. It allows you to enter the HTTP method, URL, headers and a body then issue your request. You can examine the response header and body to make sure things work as they should.

If you haven't used this plugin and are doing this kind of development, give it a try. I think you will definitely find it a time saver.

Monday, April 26, 2010

Grails Breadcrumbs

So, I'm currently developing the next big thing on the internet -- a user-generated content site that monetizes through ads and print-on-demand merchandise sales! What, no look of astonished wonder on your face? You act like thats been done before or something.

Okay, well, it has. And I really don't want to get into the details of what makes this unique until its ready for launch. There will be plenty of time for that later. In the meantime, I do want to talk about the technology behind the website.

I'm using grails as the MVC/service/persistence stack, with a heavy dose of jquery on the client-side for RIA goodness. In the coming months, I'm going to be discussing these technologies, plugins built on top of them that I am leveraging, and then the actual custom code I've had to write in support of the site. So, without further ado, I want to discuss...

Grails breadcrumbs!

Grails has a wonderful plugin community that has written many, many plugins to speed up web-app development (more about this in future posts). With regards to breadcrumbs, there is a menus plugin that wasn't really going to suit my needs. It seemed to tie you to a general site navigation framework that wasn't going to work for this site. So I had to go about making breadcrumbs for myself, and this is how I did it:

  • Created a breadcrumb model

    • BreadcrumbMapping class that contains a URI pattern to match against a name or a name generator closure.

    • Breadcrumb class that contains the actual URI hit that triggered a mapping, a reference to the mapping, and a name generated from the mapping's name or closure.

    • Breadcrumbs class that is basically a stack of breadcrumbs



  • Created a grails filter for the breadcrumbs. This examines any URI requests, looks up the BreadcrumbMapping for it, and appropriately manipulates the Breadcrumbs instance in the user's session to give an accurate navigation path

  • Created a renderBreadcrumbs tag to output a breadcrumbs navigation path using links with each Breadcrumb's name and URI

This approach has worked well. The only downside to this point is that I am using regular expressions to do the URI matching. I would rather use whatever API is in place to do standard grails URL mapping syntax. If I can get that figured out, I will probably refactor this out of the site as a whole and release it as its own plugin. This is something that would definitely be generally reusable for sites that want to implement breadcrumbs without any specific navigation framework.

Does anyone have any ideas as to where the URL mapping code is in grails, and if its generally leveragable outside the URL-to-controller mapping features of the framework itself?

Sunday, April 25, 2010

ITS ALIVE

I started a blog.

And the earth shook.

Or perhaps I have indigestion.