Thursday, February 9, 2012

IDEA 11 and grails 1.3.7 / 2.0

Last week I gave IntelliJIDEA a shot at grails since we now have both, a new version of grails (2.0) and IDEA (11) which has a reputation for good grails support in the ultimate edition. Creating a new grails project with grails 2.0 was no problem at all. Although you have to inconveniently download and extract grails yourself, everything else works like a charm. IDEA has very good in-build support for grails, meaning you can install plugins via IDE etc. It provides a dedicated grails view for your projects and thus is offering kind of the same support as Springsource's own IDE called STS. A feature for building different kinds of grails classes is also given. What I particularly like is that you can create controller, views and tests directly via buttons offered on top of the domain class editor view. Just great :-)

But so far we haven't seen anything worth what Jetbrains charge for their software. This only becomes apparent if you use it for a little while. In the process you'll learn that code completion is by far superior to STS. IDEA always knows exactly what your domain classes look like and offers the right completion for dynamic finders à la findAllBy*. Cool stuff, but most convincing to me is actually the very good reaction time of IDEA compared to STS with mostly sluggish behaviour and an auto-update function that never worked for me. Bottom line for me was that I know decided to switch to IDEA.



For people moving from STS to IDEA, another thing will be most important. How difficult is it to move existing grails projects to IDEA? I mainly work on one project upgraded to grails 1.3.7 that involves a number of inplace-plugins. I told IDEA to create a new project from existing sources, selected the encompassing folder of all my projects and clicked next. IDEA recognized all my projects as grails/groovy projects, so I just had to select grails. Next, it asked for the SDK to use. Instead of using the 2.0 grails I added a new SDK pointing to the grails 1.3.7 folder of STS. After that, IDEA recognized all my plugins correctly (my former projects are now modules) and my application works out of the box with a normal startup (mainly thanks to using the same grails installation that already has downloaded all the necessary plugins). I was astonished how well that actually went :-)

Wednesday, November 2, 2011

obtain class with only short class name at hand

If you use packages in grails it's sometimes not easy to resolve a domain class, e.g. if you only have the short class name "gene" in your params when you would actually need "package.name.gene". Here is how I managed to resolve the problem:

grailsApplication.getArtefactByLogicalPropertyName("Domain", domainName.toString().toLowerCase())

Wednesday, August 25, 2010

how to ask user for confirmation before executing remoteLink

before:"if(!confirm('Are you sure?')) return false"

The trick is not to return "true". Credits go to this jira.

Wednesday, August 11, 2010

short reminder for stupid me

If the tag does not work, it is most probably because I forgot to add the braces to the variable:

 
never works!

 
usually does work!

Tuesday, August 10, 2010

grails and SVN

I added my grails projects to a SVN repository, in order to be able to work someplace else. When I tried to check my projects out however, they did not run.

I included .project and .classpath files as I already learned that they are needed for eclipse to recognize them as grails projects.

Problem: When I ran run-app I got error messages complaining that plugins could not be resolved (locally). Also the plugin manager in STS did not list any plugins. Nothing worked.

What I missed however was that you have to run grails upgrade to reinstantiate other missing files. Afterwards plugins are resolved correctly and downloaded from the internet. This solution was found here.

Wednesday, July 28, 2010

preventing grails-ui tooltip from disappearing

Today I tried to prevent the grails-ui tooltip from disappearing after 5 seconds when the mouse is not moved. From the YUI doc I knew I had to alter a parameter 'autodismissdelay', but I haven't found a way to pass this parameter with the taglib. Unfortunately the only way I succeeded was to alter the ToolTip.js in grails-ui-1.2-SNAPSHOT\web-app\js\grailsui where I changed the value from 5000 to -1.

Tuesday, July 20, 2010

making export plugin work with filterpane

The export plugin and the filterpane plugin for themselves work like a charm. If you try to export your filtered list however, you run into problems. The root of this problem has been recognized during an earlier discussion on the mailing list.

The problem: You have to extend the filter action to deal with the export. Therefore you have to apply the filterService.filter method with the same filter params as when you applied the actual filter.

The workaround (not a perfect solution): To solve this problem I save the filter params in the session. When export is applied on the filter action the filter params are retrieved from the session. That works well although I'm not very happy with storing so much information in the session permanently.

The Code:

Here I have modified the example from the plugin page. The export-part of the list action is extracted and gets its own export closure, which can then be used by the filter action as well. I also do not explicitly name the parameters as I am using this code in a scaffolded controller. Therefore a list is fetched of all properties, excluded those that are not really representative.

def export = {attrs ->
  
  def response = attrs.response
  println attrs.exportList
  
  def excluded = grails.persistence.Event.allEvents.toList() + ["mapping", "lastModifierId", "hasMany", "class", "belongsTo", "constraints", "searchable", "attached", "errors", "metaClass", "log", "object", "version", "beforeInsert", "beforeUpdate", "mappedBy", "springSecurityService", "type", "typeLabel"]
  List fields = ${className}.newInstance().properties.keySet().toList().findAll { !excluded.contains(it) && !isId(it)}

  response.contentType = org.codehaus.groovy.grails.commons.ConfigurationHolder.config.grails.mime.types[attrs.format]
  response.setHeader("Content-disposition", "attachment; filename=${className}.\${attrs.extension}")
  
  exportService.export(attrs.format, response.outputStream, attrs.exportList, fields, [:], [:], [:])
 }
 
 def isId(def label)
 {
  label.reverse().startsWith("dI")
 }

 def filter = {  
  if(!params.max) params.max = 10
  println "out:" +params
  if(params?.format && params.format != "html" && session.filterParams)
  {
   def exportList = filterService.filter( session.filterParams, ${className} )
   println "list:" + exportList
   export(response: response, extension: params.extension, format: params.format, exportList: exportList)
  }
  
  session.filterParams = params
  
  render( view:'list',
   model:[ ${propertyName}List: filterService.filter( params, ${className} ),
   ${propertyName}Total: filterService.count( params, ${className} ),
   filterParams: com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params),
   params:params ] )
 }

EDIT: Steve made me aware that it is easy to extract the necessary parameters with a helper method. One should therefore rather modify the export taglib to pass the correct parameters to the filter action. Also see Steve's comment below.

EDIT: Please forget about most of the crazy stuff I have done here :-) You can pass the filterParams with the export tag like this: