groovy

In Groovy SwingBuilder, how do I attatch a closure to a JTable that fires when a cell is selected?

I have a JTable being constructed via Groovy's SwingBuilder. I'd like to attach a closure to the table that fires when a cell is selected, but I can't seem to find the right hook. How do I do that? ...

Is this NPE-related behavior expected for Groovy's safe navigation operator?

I came across an exception in our code today where trim() throws a NPE when doing something like someString?.toLowerCase().trim(). This got me curious, as I was under the impression that the safe nav op would break immediately upon null rather than continuing to call things in the chain. So tinkering a bit in command line groovy... groo...

Service method or domain static method in Grails?

Hi, This is a design question : when do I need to create/use a static method (in a domain class for instance) and when do I need to create/use a service instead? What is the difference between them ? Thank you. ...

How to call a Grails service in a view?

Simple question : I have a service class (let's say helpersService) and a method def constructURI(params). How can I call this method from a template view. I have tried the following code without success <% def helpersService = new HelpersService() // or def helpersService %> <img src="${helpersService. constructURI(params)}"/> But ...

Intercepting calls to properties

Hi, I'm trying to intercept all calls to properties on a Groovy class. Since this did not work as expected, I created the following example: class TestClass { def getProperty(String key) { println "getting property: " + key } def invokeMethod(String method, args) { println "invoking method: " + method }...

How do I undo meta class changes after executing GroovyShell?

For example, if I execute a Groovy script, which modifies the String meta class, adding a method foo() GroovyShell shell1 = new GroovyShell(); shell1.evaluate("String.metaClass.foo = {-> delegate.toUpperCase()}"); when I create a new shell after that and execute it, the changes are still there GroovyShell shell2 = new GroovyShell(); ...

Grails Application context

Hi! I have a grails / groovy application running under tomcat. For some reason I have to be able to change the application context dynamically. That is, I want to be able (at login time) to set this context. I know that this is doable via the Config.groovy but this is static. At login time I am getting a parameter which is the context...

Groovy: adding methods to instances and classes with metaClass doesn't work?

See the code below. Old instances of a class created before a method is added to the class using metaClass should not understand the method right? The assert statement below the 'PROBLEMATIC LINE' comment is executed when I think it should not be, as the old parentDir instance should not understand the blech() message. // derived from...

Missing taglib when using GroovyPagesTemplateEngine

G'day all, I've been processing dynamic GSP content via tags in my own taglib which works just fine using code like: def GroovyPagesTemplateEngine groovyPagesTemplateEngine ... def processGSPContent(model, name, out) { log.debug("model is $model") Template t = groovyPagesTemplateEngine.createTemplate(model.conte...

Grails, Nimble and Blogito

Hi, I tried to run the sample application of Nimble 0.2 (blogito) downloaded here : http://github.com/intient/blogito but unfortunately I got stuck with 2 major issues: When running grails run-app, I got 2 times out of 3 the following error : 2009-10-24 14:38:15,198 [main] ERROR context.ContextLoader - Context initialization faile...

Can you give me examples of odd single line comments in C++?

I wrote a method to remove single line comments from a C++ source file: def stripRegularComments(text) { def builder = new StringBuilder() text.eachLine { def singleCommentPos = it.indexOf("//") def process = true if(singleCommentPos > -1) { def counter = 0 it.eachWithIndex { obj,i -> if((obj == '\'')...

Groovy GString issues

Hi, All! I'm want use $ macro in groovy GString. When i'm wrote this code ['cdata','tdata'].each { def sql = "select * from $it_1" } i'm get error unknown property $it_ ok, i'm rewrite it ['cdata','tdata'].each { def sql = "select * from ${it}_1" } then i'm get unwanted quotes in result string - "select * from 'cdata'_1" ...

recommendation for choosing a new web development stack

I work in a medium to small team ( 10 people ) developing and supporting several web enterprise applications. We have a dozen of them built with a house-made framework with asp-classic working against ms-sql server. We are evaluating the migration to a new development stack. We'd like it to be open (free) and simple. I've been look...

Variable Variable in Groovy

Hi everybody, I'm in a project using Grails, I user beanFields plugin where I'm changing the bean:inputTemplate into the following <bean:inputTemplate> <div class="prop ${hasErrors(bean:$beanName,field:'$fieldId','errors')}">${label} <span class="value">${field} </span> </div> </bean:inputTemplate> As you ...

Using Grails GORM standalone

I'm currently wondering how it is possible to use the Groovy ORM Layer from Grails standalone outside of the Grails Framework. There is a Documentation Entry for doing so, but the ZIP file only links to an empty page. I downloaded Grails 1.2-M3 but I couldn't find anything in the docs either. Does anybody know what the current state is...

which Java / Groovy library to overlay text on an image

I am working on a web application (using Grails) which will generate a gift certificate. I'm thinking of a workflow like this: The user will pick a template which will be stored as an image. Then the text (name, date, amount etc) will be overlaid on the image to make the final certificate. There is a set of co-ordinates associated ...

Groovy with Grape and AntBuilder classloader problem

I wanted to use groovy for a little ftp script and found this post http://www.hhhhq.org/blog/2009/05/01/ftp-using-groovy-and-ant/ Since there were several dependencies I wanted to use Grape. All dependencies are resolved and present in the cache. But I can't get Ant to find the optional tasks in the other libs. It always says Caught: : ...

Select string with comma (regex)

I need an regular expression which matches the following: '"test foo bar", "test"' => no match '"test, foo bar", "test"' => "test, foo bar" '"test, foo bar"' => "test, foo bar" '"test foo bar"' => no match '"test", "test, foo"' => "test, foo" '"test", ","' => no match '"test", 0, 0, "foo"' => no match the regex should match any string...

utf-8 decoding in java

I'm trying to pass parameters from a PHP middle tier to a java backend that understands J2EE. I'm writing the controller code in Groovy. In there, I'm trying to decode some parameter that will likely contain international characters. I am really puzzled by the results of my debugging this problem so far, hence I wanted to share it with ...

How to add a new closure to a class in groovy.

From Snipplr Ok here is the script code, in the comments is the question and the exception thrown class Class1 { def closure = { println this.class.name println delegate.class.name def nestedClos = { println owner.class.name } nestedClos() } } def clos = new Class1().closure ...