groovy

How to implement javascript's 'escape' function in grails

Is there an equivalent of JS 'escape' function in Groovy/Java? escape('hello world') => hello%20world I tried this class: http://commons.apache.org/lang/api/org/apache/commons/lang/StringEscapeUtils.html, but it didn't work. Or do i have to implement it? Thanks. ...

How to configure IntelliJ for running test with JUnit 4?

Should be simple but I couldn't figure it out. When running my unit test inside IntelliJ, I could not find a way to tell IntelliJ-9.0 that it should use JUnit4 instead of JUnit3. When a test fails, IntelliJ console displays: MyTests.testConstraints(MyTests.groovy:20) at ... com.intellij.junit3.JUnit3IdeaTestRunner.doRun(...

Groovy XmlSlurper

<div id="videos"> <div id="video"> <embedcode>....</embedcode> </div> </div> I need to grab the video embed code, and not just the text inside a XMl tag. Any idea how can I grab the snippet of XML using XmlSlurper? I need the whole line: <embedcode>....</embedcode> ...

Aside from performance concerns, why is Java still chosen over Groovy/JRuby etc.?

[This is an empirical question about the state-of-the-art: I am NOT asking if Java is cooler or less cool than the dynamic languages that work in the JVM.] Aside from cases where performance is a main decision factor, do companies/developers still willingly chose Java over Groovy, JRuby or Jython? Edit: If the answer is "yes," why? P...

Set thread priority for job in grails

I have a job running on a grails app that I need to run with lower priority. Is there a configuration to set that? ...

Grails domain class initialization

Hi, My Grails app has the following Spring bean defined in spring/resources.groovy calendarService(CalendarService) { bean -> bean.initMethod = "init" } This method looks something like: class CalendarService { void init() { User.findByEmail("[email protected]") } } When I call the dynamic finder findByEmail ...

Best way to code this, string to map conversion in Groovy

I have a string like def data = "session=234567893egshdjchasd&userId=12345673456&timeOut=1800000" I want to convert it to a map ["session", 234567893egshdjchasd] ["userId", 12345673456] ["timeout", 1800000] This is the current way I am doing it, def map = [:] data.splitEachLine("&"){ it.each{ x -> def object = x.s...

Adding exclusive filter for <static initializer> in findbugs

Hi all, I want my findbugs report not show the following error: DM_NUMBER_CTOR: Method invokes inefficient Number constructor; use static valueOf instead The problem is that this happens in groovy-generated code files, so I can't control the source code - that is why I want to exclude it and add it to my exclude filter. I do not want...

Grails: Dynamically inject service in domain class

I need to inject a service based on domain property, so far I came up with the following: ApplicationHolder.application.getServiceClass("package.${property}Service").clazz but loading it this way doesn't inject it's dependent services. Am I doing it wrong? ...

Reading Excel using scriptom for Groovy, producing XML

I got a program from http://kousenit.wordpress.com/2007/03/27/groovyness-with-excel-and-xml. But I got some very strange results: I can still print XML, but two records are not readable. I got exception suggesting something is missing What might go wrong? I copied the program and result below. import org.codehaus.groovy.scriptom.A...

could not initialize proxy - no Session

HI, I am using Grails 1.2.1 and I always got this message when I run my apps and leave it without anyone using the apps. org.hibernate.LazyInitializationException: could not initialize proxy - no Session at H__project_ilinkdev_grails_app_views_layouts_main_gsp$_run_closure2.doCall(H__project_ilinkdev_grails_app_views_layouts_main...

Groovy slow to load on first call from Java

I am using Groovy to do some calculations, within an RCP app. When I first click the button that calls the Groovy code, I get a bit of a delay, which doesn't exist on the next and subsequent clicks. Is there any way I can warm the cache (so to speak) ? ...

Shorter URL in Groovlet

Consider the following Groovlet: html.html { head { title("Groovy Test") } body { center { img(src:"getPlot.groovy?name=name&value=value") } } } Is there a better way to generate the URL? I'm looking to eliminate the explicit var/vals from the URL. ...

groovy while loop syntax assigning and checking a variable

I was reading a blog post and saw a groovy snippet that looked lik while ( entry = inputStream.nextEntry ) { // do something } In the while loop, is this groovy syntax that will cause the loop to break when entry is null? ...

POST with HTTPBuilder -> NullPointerException?

I'm trying to make a simple HTTP POST request, and I have no idea why the following is failing. I tried following the examples here, and I don't see where I'm going wrong. Exception java.lang.NullPointerException at groovyx.net.http.HTTPBuilder$RequestConfigDelegate.setBody(HTTPBuilder.java:1131) ... Code def List<String> se...

How to refer to another property in a custom Grails validator?

I have a property that can be nullable or required depending on the status of another variable. class Person{ name() civilStatus(inList:['Single','Married','Divorced','Widowed']) partnerOrSpouse() } the partnerOrSpouse property is nullable or not depending on the value of the civilStatus property. ...

Prevent Flash-Message showing up twice (on page with error and on next page)

If there is an error in a form my grails application this results in a flash message. If I then go to another page, the (old) flash message shows up again on the new page. How do I prevent this? ...

java.lang.NoClassDefFoundError: groovyx.net.http.HTTPBuilder

When I run my grails application locally under Tomcat, I get no errors. When I deploy my WAR on my remote web server, I get this exception when I try to make an AJAX request that uses HTTPBuilder. How could this be happening? ...

groovy call private method in Java super class

I have an abstract Java class MyAbstractClass with a private method. There is a concrete implementation MyConcreteClass. public class MyAbstractClass { private void somePrivateMethod(); } public class MyConcreteClass extends MyAbstractClass { // implementation details } In my groovy test class I have class MyAbstractClass...

How to force grails GORM to respect DB scheme ?

I have two domains : class CodeSet { String id String owner String comments String geneRLF String systemAPF static hasMany = [cartridges:Cartridge] static constraints = { id(unique:true,blank:false) } static mapping = { table 'code_set' version false columns { id column:'code...