<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

    <channel>
    
    <title>Stainless Code - Blogs</title>
    <link>http://www.stainlesscode.com/blog-articles/</link>
    <description />
    <dc:language>en</dc:language>
    <dc:creator>dstieglitz@stainlesscode.com</dc:creator>
    <dc:rights>Copyright 2009</dc:rights>
    <dc:date>2009-03-28T15:59:00-05:00</dc:date>
    <admin:generatorAgent rdf:resource="http://expressionengine.com/" />
    

    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/stainlesscode" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
      <title>Los Angeles Groovy / Grails Meetup started</title>
      <link>http://feedproxy.google.com/~r/stainlesscode/~3/EW5-OZBuA3Y/</link>
      <guid isPermaLink="false">http://www.stainlesscode.com/blog-articles/los_angeles_groovy_grails_meetup_started/#When:15:59:00Z</guid>
      <description>I attended the NYC-area Groovy / Grails meetup hosted by Jean Barmash and decided to start an analogue group in Los Angeles. If you’re interested, sign up or log on to meetup.com and join us. As of the time of this writing our first meetup is not scheduled, as I’m still in search of a good venue. We’ll probably start off, as Jean did, with some basic Groovy/Grails demonstrations and take it from there. I live in the Pasadena area so I will start the venue search accordingly.


If you’re interested in sponsoring this meetup, have any other questions, or can suggest a good venue please contact me at dstieglitz (at) stainlesscode.com.


Links:


The New York Groovy / Grails Meetup Group

The Los Angeles Groovy / Grails Meetup Group&lt;img src="http://feeds.feedburner.com/~r/stainlesscode/~4/EW5-OZBuA3Y" height="1" width="1"/&gt;</description>
      <dc:subject>Groovy/Grails</dc:subject>
      <dc:date>2009-03-28T15:59:00-05:00</dc:date>
    <feedburner:origLink>http://www.stainlesscode.com/blog-articles/los_angeles_groovy_grails_meetup_started/#When:15:59:00Z</feedburner:origLink></item>

    <item>
      <title>A Grails 1.0.4 Gotcha</title>
      <link>http://feedproxy.google.com/~r/stainlesscode/~3/qK18FOdabpI/</link>
      <guid isPermaLink="false">http://www.stainlesscode.com/blog-articles/a_grails_104_gotcha/#When:19:22:01Z</guid>
      <description>Experiencing lots of unexplained, frustrating LazyInitializationExceptions in your Grails application lately? It could be due to a gotcha I was wrestling with that’s present even through Grails 1.0.4. Fixing it will likely take some time as it will require some rethinking and probably some refactoring of the core Grails framework but there is a workaround, once you figure out you’ve run into this gotcha.


The symptom is that you get a LazyInitializationException when you don’t expect one (well, you never really expect them) but even if you’re an experienced Hibernate developer this might throw you for a loop. The problem is that the Grails OSIV filter will have closed the Hibernate “currentSession” by the time the SiteMesh template is processed, so ANY calls to GORM dynamic methods will through this exception if you’re accessing lazy-initialized fields from your domain objects.


The solution is to remove all Hibernate calls, including those in tag libraries, from your SiteMesh templates. Or, if you must have the aforementioned calls, you can modify your tag libraries (since I know everyone is using tag libraries instead of just mashing code into your GSPs within  brackets, right?)  in a manner similar to this:


    def isReseller = { attrs, body -&gt;

        if (authenticateService.userDomain()) {

        def u = Person.createCriteria();

        def user = u.get {

             eq("id",authenticateService.userDomain().id)

             fetchMode(’primaryAccount’,FM.EAGER)

             fetchMode(’primaryAccount.type’,FM.EAGER)

             }

         }

    }



The above code assumes you’re using the Spring Security plugin (aka ACEGI) and want to check for a specific account type for the logged-in user when rendering your SiteMesh layout. It will eagerly fetch the primaryAccount and primaryAccount.type objects (they are 1-to-1 references in this example) when retrieving the account, so no session is required once the call is finished.


Hopefully I saved you some hours here… you can see the JIRA entry for this at http://jira.codehaus.org/browse/GRAILS-2764.


Happy holidays to all, and here’s to a prosperous 2009. If you’ve been hit hard by the financial crisis, I hope that it doesn’t last long. Once again we are reminded that “what goes up must come down,” and also that greed and stupidity are a bad combination… especially for financiers and their financial-industry colleagues.&lt;img src="http://feeds.feedburner.com/~r/stainlesscode/~4/qK18FOdabpI" height="1" width="1"/&gt;</description>
      <dc:subject>Groovy/Grails</dc:subject>
      <dc:date>2008-12-29T19:22:01-05:00</dc:date>
    <feedburner:origLink>http://www.stainlesscode.com/blog-articles/a_grails_104_gotcha/#When:19:22:01Z</feedburner:origLink></item>

    <item>
      <title>ACEGI (Spring) Security, HTTPS, and Grails</title>
      <link>http://feedproxy.google.com/~r/stainlesscode/~3/JXmHChjMzb0/</link>
      <guid isPermaLink="false">http://www.stainlesscode.com/blog-articles/acegi_spring_security_https_and_grails/#When:21:28:00Z</guid>
      <description>I had a requirement in a recent project to have all logins handled by HTTPS, and I wanted to implement this using Grails 1.0.2 with the acegi-plugin. There seemed to be a number of issues with the plugin, specifically with some package names and configuring the ACEGI channel selectors. Of note are that the package names have changed in the ACEGI-Spring migration, for example, packages org.acegisecurity.util... and org.acegisecurity.securechannel... have become org.springframework.security.util and org.springframework.security.securechannel, respectively. I didn't find this reflected in the online documentation for either Spring Security or Grails, at least not yet.

Steps to Configure HTTPS Channels
First, install the acegi plugin.

Next, configure the channel filter in the web.xml file. This requires us to install the grails templates which will contain the web.xml template grails uses to produce the deployed web.xml.

grails install-templates

will do the trick. Navigate to the src/templates/war and add the filter to the web.xml template there:

    
  		Acegi Channel Processing Filter
  		org.springframework.security.util.FilterToBeanProxy
  		
    			targetClass
    			org.springframework.security.securechannel.ChannelProcessingFilter
  		
	
    
    
  		Acegi Channel Processing Filter
  		/*
	

Now, when we build our application, this filter will be configured in our deployed web.xml. 

The final step is to set up the spring beans, and this is done using the Grails DSL for configuring Spring beans (the SpringBuilder). A great reference on the SpringBuilder can be found on the Grails documentation online (http://grails.org/Spring+Bean+Builder). The code should be put into yout grails-app/conf/spring/resource.groovy file (the entire file is reproduced here):

import org.springframework.security.securechannel.ChannelProcessingFilter
import org.springframework.security.securechannel.ChannelDecisionManagerImpl
import org.springframework.security.securechannel.SecureChannelProcessor
import org.springframework.security.securechannel.InsecureChannelProcessor

beans = {
	secureChannelProcessor(SecureChannelProcessor)
	insecureChannelProcessor(InsecureChannelProcessor)

	channelDecisionManager(ChannelDecisionManagerImpl) {
		channelProcessors = [secureChannelProcessor, insecureChannelProcessor]
	}

	channelProcessingFilter(ChannelProcessingFilter) {
		channelDecisionManager=channelDecisionManager
		filterInvocationDefinitionSource='''
			  CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
			  PATTERN_TYPE_APACHE_ANT
			  /login/**=REQUIRES_SECURE_CHANNEL
		      '''
	}
}&lt;img src="http://feeds.feedburner.com/~r/stainlesscode/~4/JXmHChjMzb0" height="1" width="1"/&gt;</description>
      <dc:subject>Groovy/Grails</dc:subject>
      <dc:date>2008-05-30T21:28:00-05:00</dc:date>
    <feedburner:origLink>http://www.stainlesscode.com/blog-articles/acegi_spring_security_https_and_grails/#When:21:28:00Z</feedburner:origLink></item>

    <item>
      <title>IPTV and the Next Generation Television Experience</title>
      <link>http://feedproxy.google.com/~r/stainlesscode/~3/pwl_KKhJM2k/</link>
      <guid isPermaLink="false">http://www.stainlesscode.com/blog-articles/iptv_and_the_next_generation_television_experience/#When:18:27:00Z</guid>
      <description>At The National Association of Broadcasters (NAB) conference two weeks ago I attended a keynote and panel discussion about IPTV. “Where we are now and what we have learned” was the title. The Keynote speaker was Microsoft’s SVP of Microsoft TV and both his speech and the subsequent panel discussion touched on several topics, including defining what that next-generation television experience really is, and how all of the supporting industries will be affected by the shift to whatever that viewer experience will be. His speech was quite Microsoft-centric, although he can’t really be faulted for that. All of the panelists agreed that it’s not clear what this experience will look and feel like although it will be two-way, not one-way as it is today and it will no longer be only about the best picture and sound quality. The experience itself; the interactivity (and therefore also the content) will be paramount. In fact, I’d venture to say that if the content was compelling enough, viewers will endure a weaker visual and audible experience.


The challenges to this new experience are many, including:


Lack of standards for getting video to viewers over the IP network, and also for getting information back from them
The need for a more scalable internet, larger address space, and cheaper bandwidth
New creative ideas about what two-way television feels like


IPTV today is the same television experience we’ve been used to, just delivered over IP networks. It’s prepackaged, completely closed and tightly controlled by industry. So what will this new set of content experience consist of? What will two-way TV look like? How will open source play in this new world? In throwing the ball around with some friends and colleagues we came up with some ideas:


Newscasts where people report news from their homes
Game shows where people can play-- live, from their living rooms
Potential for great, interactive educational programming


I’m curious to hear your ideas on this topic of the next-generation TV experience… what will it feel like?&lt;img src="http://feeds.feedburner.com/~r/stainlesscode/~4/pwl_KKhJM2k" height="1" width="1"/&gt;</description>
      <dc:subject>New Media</dc:subject>
      <dc:date>2008-04-27T18:27:00-05:00</dc:date>
    <feedburner:origLink>http://www.stainlesscode.com/blog-articles/iptv_and_the_next_generation_television_experience/#When:18:27:00Z</feedburner:origLink></item>

    <item>
      <title>Tech Note: Grails Custom One-To-Many Scaffolding</title>
      <link>http://feedproxy.google.com/~r/stainlesscode/~3/tjqRz94Zge4/</link>
      <guid isPermaLink="false">http://www.stainlesscode.com/blog-articles/grails_one_to_many_scaffolding/#When:17:19:00Z</guid>
      <description>One small issue we have with Grails is that out-of-the-box it doesn't scaffold a UI to deal with one-to-many (OTM) relationships for existing objects. You can add a new instance of an entity to a container object when editing it, but if you have pre-existing objects you can't add them to the container. When you're in the early phases of an application and are tweaking your domain model this can be a big help. Here I'm going to present a quick way of modifying the scaffolding templates to allow you to generate a UI that can allow this behavior. There's a lot of value in knowing how to modify the Grails default behavior and this short tutorial should give you a little introduction into how Grails works under the covers.


Create the application

grails create-app OneToManyScaffolding

Create the domain model
In this example we create a Container and an Component object, where Container contains many Components.

grails create-domain-class Container
grails create-domain-class Component

Next, flesh out the domain objects:

class Component {
	
	String name
	
        String toString() {
		return name
	}
}

We implement the toString() method so that when the scaffold displays the objects in the UI, we'll get a value that has some meaning. We also build our Container domain class having a hasMany reference to our newly-created component class.

class Container {
	
        String name
	static hasMany = [ components : Component ]

        String toString() {
                return name
        }
}

Let's run the app to see what we get out-of-the-box. First we'll create a container using the UI (ContainerController -&gt; New Container). When we attempt to edit our new container we get an edit screen with an "Add Component" link; however, clicking this link takes us to the "Create Component" screen. If we'd had some pre-created Components we wanted to add to this container the out-of-the-box UI would not allows us to do this. We can implement this behavior for the default UI by modifying the templates that generate these pages.
Install the scaffolding templates
First we'll need to install the templates themselves, and Grails makes this quite easy. You'll only need to issue:

grails install-templates

When this operation completes there will be a src/templates/scaffolding directory added to the application. This directory contains all of the Groovy templates that are used to generate the scaffolded pages when you issue a "generate-all ..." command. There is also a GSP that generates the "editor" for domain objects called "renderEditor.template" that contains logic we'll modify to get this working.
Modify the scaffolding templates
Open the renderEditor.template file and find the "renderOneToMany" method. The last line before the method returns generates the link we see that allows us to add (currently only new) objects to our container object. Add the following line below:

pw.println "Associate ${property.referencedDomainClass.shortName}";

This will create an "Associate ..." link below the "Add ..." link on the Container edit page. Clicking on the link will call the "list" action of the component class and pass in 3 paramters: component_id, source, and callback. To complete the flow for associating the objects we'll need to create a new method, "choose," in the template that generates the controllers. This template is in the same scaffolding directory and is called Controller.groovy. Add the method definition to the end of the class:

    def choose = {
        redirect(controller:params.source,action:params.callback,params:params)
    }

We'll need to regenerate the controllers now since we've changed the scaffolding templates, so issue a "grails generate-all Container" and "grails generate-all Component."


Now we have to crack open the list template and modify it to produce links that know when we're trying to list instances and when we're trying to select an association. Each instance link is generated in an each closure near the bottom on the template. We'll add some code to generate a different link when a "callback" parameter is passed in, indicating we've come from an "Associate ..." link and not an "Add ..." link.

        
            ${${propertyName}.${p.name}?.encodeAsHTML()}
        
        
            ${${propertyName}.${p.name}?.encodeAsHTML()}
        


We've modified the behavior to call the "choose" method we implemented above on the Container class, which will in turn call the method specified in the "callback" parameter we've been passing around in the URLs. The callback method will be called on the "source" object also passed around. In this specific case, Grails expects to see an addComponent method in the Container controller, so let's go ahead and add that method:

    def addComponent = {
    	def container = Container.get(params["container_id"])
    	def component = Component.get(params["id"])
    	container.addToComponents(component)
    	render(view:'edit',model:[container:container])
    }

That completes the code for the flow, so now you should be able to add components to your model, and then associate them with a controller in your view. Be careful not to overwrite your custom controller methods when you regenerate controllers, or better yet, tweak this code so those methods can live in a service.&lt;img src="http://feeds.feedburner.com/~r/stainlesscode/~4/tjqRz94Zge4" height="1" width="1"/&gt;</description>
      <dc:subject>Groovy/Grails</dc:subject>
      <dc:date>2008-04-10T17:19:00-05:00</dc:date>
    <feedburner:origLink>http://www.stainlesscode.com/blog-articles/grails_one_to_many_scaffolding/#When:17:19:00Z</feedburner:origLink></item>

    <item>
      <title>Tech Note: Scaffolding JSON with Grails</title>
      <link>http://feedproxy.google.com/~r/stainlesscode/~3/2-WVNQeVFrI/</link>
      <guid isPermaLink="false">http://www.stainlesscode.com/blog-articles/scaffolding_json_with_grails/#When:15:27:00Z</guid>
      <description>For the uninitiated, JSON “is a lightweight data-interchange format,” as humbly posted on JSON.org. It’s useful for architects in search of a lighter-than-XML transport or JavaScript developers who want service providers sending them easy to use objects for use in their pages. Grails has out-of-the-box JSON support via the JSONObject library, as well as through their converters “plugin” (which is now included in the core distribution). Converting grails domain objects to JSON (or XML, for the enthusiast) is as complicated as


render myDomainObject as JSON


and 


render myDomainObject as XML


This is fantastic, and to include a JSON service in your app, you would simply add a method to your controller as such:


def json = {
    if(!params.max) params.max = 10
    render MyDomainObject.list( params ) as JSON
}


It doesn’t get better for the lazy developer, unless you want Grails to automatically add this method to each scaffolded controller class you generate. This is possible by customizing Grails’ scaffolding templates. First, install the templates by issuing


grails install-templates


at your project’s root. This will create the src/templates directory where the artifact and scaffold templates live. Crack open the src/templates/scaffolding/Controller.groovy file and add the following closure template:


def json = {
    if(!params.max) params.max = 10
    render ${className}.list( params ) as JSON
}


It’s essentially a copy of the list closure, except the controller will render a JSON string instead of passing a list to the view. You’ll also need to import the JSON converter so add this to the import section of the template:


import grails.converters.JSON;


That’s it, and the next time you generate a controller for one of your domain objects you can get a JSON list by hitting the /MyApp/MyDomainObject/json URL.


@see http://www.grails.org/Artifact+and+Scaffolding+Templates

@see http://www.json.org/&lt;img src="http://feeds.feedburner.com/~r/stainlesscode/~4/2-WVNQeVFrI" height="1" width="1"/&gt;</description>
      <dc:subject>Groovy/Grails</dc:subject>
      <dc:date>2008-04-02T15:27:00-05:00</dc:date>
    <feedburner:origLink>http://www.stainlesscode.com/blog-articles/scaffolding_json_with_grails/#When:15:27:00Z</feedburner:origLink></item>

    <item>
      <title>Great article on Groovy DSLs</title>
      <link>http://feedproxy.google.com/~r/stainlesscode/~3/CaauMrX4INc/</link>
      <guid isPermaLink="false">http://www.stainlesscode.com/blog-articles/great_article_on_groovy_dsls/#When:16:12:00Z</guid>
      <description>Check out this article on writing domain-specific languages for Groovy 


DSLs are a powerful feature of the language and for programming in general. It’s always advisable to give software users a language to interact with the software, rather than just a monolithic program that does very specific tasks.&lt;img src="http://feeds.feedburner.com/~r/stainlesscode/~4/CaauMrX4INc" height="1" width="1"/&gt;</description>
      <dc:subject>Groovy/Grails</dc:subject>
      <dc:date>2008-03-12T16:12:00-05:00</dc:date>
    <feedburner:origLink>http://www.stainlesscode.com/blog-articles/great_article_on_groovy_dsls/#When:16:12:00Z</feedburner:origLink></item>

    <item>
      <title>The launch of stainlesscode.com</title>
      <link>http://feedproxy.google.com/~r/stainlesscode/~3/1O87pvYAU4w/</link>
      <guid isPermaLink="false">http://www.stainlesscode.com/blog-articles/the_launch_of_stainlesscodecom/#When:17:40:00Z</guid>
      <description>I’m finally happy to say we’re wrapping up the development of the new stainlesscode.com, and I’d like to give special thanks to the folks at Ripe Media (http://www.ripemedia.com) for doing a great job on the design and getting it all integrated on to our hardware. I hope that this new site is more than just a brochure for our company; I’d really like for it to be a better way for our team to communicate with our clients and the development community as a whole. We’ve been immersed in web 2.0 development for some time and have had little opportunity to actually leverage some of the great things about web 2.0 for ourselves. In some small way I hope the blogs on this site will positively impact development projects elsewhere through code examples, experiences and comments from readers. I’m proud of our team and what they’ve done and I’m eager to have them share their expertise with others through this medium.&lt;img src="http://feeds.feedburner.com/~r/stainlesscode/~4/1O87pvYAU4w" height="1" width="1"/&gt;</description>
      <dc:subject>Stainless Code</dc:subject>
      <dc:date>2008-02-17T17:40:00-05:00</dc:date>
    <feedburner:origLink>http://www.stainlesscode.com/blog-articles/the_launch_of_stainlesscodecom/#When:17:40:00Z</feedburner:origLink></item>

    
    </channel>
</rss>
