Tuesday, May 27, 2008

Ext plugin discontinued



I just want to mention that I decided to discontinue working on the Ext (Scaffolding) plugin for Grails.

The reason is Ext's recent license change (1, 2, 3, 4) to GPL v3. Although the Ext team has announced some Open Source FLOSS exceptions, for me it's end of the line here Ext concerned.

Monday, May 12, 2008

Uber Generate All script for Grails



While I was creating a Grails application on an exsiting database schema I was to lazy to run grails generate-all 15 times. So I created an Uber Generate All script, which generates controllers and views for all domain classes in your application.

If you want to use it create a new script within your application (e.g. grails create-script UberGenerateAll) and copy in the code below:


import org.codehaus.groovy.grails.commons.GrailsClassUtils as GCU
import groovy.text.SimpleTemplateEngine
import org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator;
import org.codehaus.groovy.grails.scaffolding.*
import org.springframework.mock.web.MockServletContext
import org.springframework.core.io.Resource;

Ant.property(environment:"env")
grailsHome = Ant.project.properties."environment.GRAILS_HOME"

includeTargets << new File ( "${grailsHome}/scripts/Package.groovy" )

generateViews = true
generateController = true

target('default': "The description of the script goes here!") {
    depends( checkVersion, packageApp )
    typeName = "Domain Class"
    doStuff()
}

target(doStuff: "The implementation task") {

    rootLoader.addURL(classesDir.toURL())
    def beans = new grails.spring.WebBeanBuilder().beans {
        resourceHolder(org.codehaus.groovy.grails.commons.spring.GrailsResourceHolder) {
            this.resources = "file:${basedir}/grails-app/domain/**/*.groovy"
        }
        grailsResourceLoader(org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean) {
            grailsResourceHolder = resourceHolder
        }
        def pluginResources = [] as Resource[]
        if(new File("${basedir}/plugins/*/plugin.xml").exists()) {
            pluginResources = "file:${basedir}/plugins/*/plugin.xml"
        }

        pluginMetaManager(org.codehaus.groovy.grails.plugins.DefaultPluginMetaManager, pluginResources)
        grailsApplication(org.codehaus.groovy.grails.commons.DefaultGrailsApplication.class, ref("grailsResourceLoader"))
    }
                                                    
    appCtx = beans.createApplicationContext()    
    appCtx.servletContext = new MockServletContext()
    grailsApp = appCtx.grailsApplication

    grailsApp.initialise()
    def domainClasses = grailsApp.domainClasses

    if(!domainClasses) {
        println "Domain classes not found in grails-app/domain, trying hibernate mapped classes..."    
        try {
            def config = new GrailsRuntimeConfigurator(grailsApp, appCtx)
            appCtx = config.configure(appCtx.servletContext)                
        }
        catch(Exception e) {
            println e.message
            e.printStackTrace()
        }
        domainClasses = grailsApp.domainClasses
    }
    
    if(domainClasses) {
        def generator = new DefaultGrailsTemplateGenerator()
        domainClasses.each { domainClass ->
            if(generateViews) {
                event("StatusUpdate", ["Generating views for domain class ${domainClass.fullName}"])                
                generator.generateViews(domainClass,".")                                                        
            }                                                                                    
            if(generateController) {
                event("StatusUpdate", ["Generating controller for domain class ${domainClass.fullName}"])    
                generator.generateController(domainClass,".")            
            }
            event("StatusUpdate", ["Finished generation for domain class ${domainClass.fullName}"])            
        }
        event("StatusFinal", ["Finished generation for domain classes"])
    }
    else {
        event("StatusFinal", ["No domain class found"])
    }
}


Then just run grails uber-generate-all and watch!

I have only tested it for Groovy domain classes, but I think it will also work for Hibernate mapped classes. Enjoy.

Sunday, May 4, 2008

Ref Code plugin



Back in my days as Oracle Designer developer we had a nice CG_REF_CODES table in which we could store (semi)-static domains. You can think about these domains as simple code/description lookup tables; for example OrderStatus, OrganizationType, MaritalState etc. As these lookups only contained codes and descriptions it's not worth creating specific tables. That's why we had this CG_REF_CODES tables; we stored all these simple domains, and it's allowable values in 1 simple table.

As this is convienient for any application I created a simple Grails plugin which provides the same functionality. You can store all your simple reference codes in a single table, and use it to render dropdown boxes or validate user input in custom constraints. Have a look at http://grails.org/Ref+Code+Plugin.

Saturday, April 26, 2008

Grails wins 2nd prize in JAX Innovation Award



Just read that Grails has won the Second prize (5.000 euro) in the yearly JAX Innovation Award. And that after Groovy won the First prize a year earlier. As Grails developers we know the Grails/Groovy platform is truly innovative compared to other web frameworks, but it is good to see the recognition from such a public award.

The JAX Innovation Award were presented and awarded to the winners during the conferences JAX, SOACON and Eclipse Forum Europe. The three conferences are taking place at the same time in Wiesbaden and represent the most important meeting for professional information technology in Europe.

Thursday, April 24, 2008

Busy time in Grails plugin land: Announcing the OpenID plugin



It are busy times in Grails plugin land. This week the Searchable Plugin 0.4.1, Acegi Plugin 0.2.1, and the Authentication Plugin 1.0 were already released. And I've just added another one myself: the OpenID Plugin

While Marc Palmer was releasing his Authentication plugin, I was working one a OpenID plugin myself. When I was reading through the Authentication plugin documentation I really got inspired by some features of it. So I borrowed/copied some concepts of it to the OpenID plugin. Thanks Marc!

The OpenID plugin does all the plumbing to communicate with OpenID providers (using the OpenID4Java library) to authenticate/identify users for your website. The great thing is that you are in full control where the controller and the OpenID providers will redirect to in case of successfull login or error.

Here is an example:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="layout" content="main" />
<title>Login</title>
<openid:css />
</head>
<body>
<div class="nav">
<span class="menuButton"><a class="home" href="${createLinkTo(dir:'')}">Home</a></span>
</div>
</div class="body">

<h1>Login</h1>
<openid:hasLoginError>
<div class="errors">
<ul>
<li></li>
</ul>
</div>
</openid:hasLoginError>
<openid:form success="[action:'loggedin']">
<openid:input size="30" value="http://" /> (e.g. http://username.myopenid.com)
<br/>
<g:submitButton name="login" value="Login" />
</openid:form>
</div>
</body>
</html>



For full documentation see: http://grails.org/OpenID+Plugin

Friday, April 11, 2008

Update on Ext Scaffolding



I'm making some progress on the Ext Scaffolding for Grails.
Currently I can generate all CRUD functionality for a simple domain class with String properties.

It's done by overriding the default scaffolding templates (aka grails install-templates). So when finished the Ext plugin will contain a plugin to install these templates, which then can be used with the generate-all command.

See below some additional screenshots.



Friday, April 4, 2008

Sneak Preview: Ext Scaffolding for Grails



A short post just before the weekend. Have a look at the nice screenshots below, which are the result of Grails Ext Scaffolding templates I'am working on currently. I hope to include the templates in the Grails Ext plugin soon.