groovy

Groovy literal StringBuilder/StringBuffer

Hi, Groovy supports a literal syntax for creating a StringBuilder/StringBuffer instead of the usual def sb = new StringBuilder() However, I can't seem to remember (or find on Google) the correct syntax. Thanks, Don ...

JSP PageContext from a Groovlet (Groovy Servlet)

I'm trying to use Groovlets in place of JSPs in an integration framework but one of the vendor's libraries relies on the javax.servlet.jsp.PageContext available in a JSP. I found the GroovyPagesPageContext class that's part of Grails for GSPs. Anyway to use Groovy in this situation and have a handle to the jsp PageContext? I have not...

Beginner Groovy Question:

Hi there, I'm following the code examples in 'The Definitive Guide to Grails' by Graeme Keith Rocher, and have come across a rather unusual stumbling block. Essentially, 2 domain classes exist - Bookmark & Tag. Bookmark: class Bookmark { static hasMany = [tags:Tag] URL url String title String notes Date dateCreated = new Date() } ...

How can I add common actions to controllers without using inheritance?

I need to add common actions to a number of my controllers without using inheritance. All our controllers extend an Abstract controller and the functionality I want to include does not make sense in the abstract controller. My initial idea was to use a Mixin, but it appears that actions, since they are closures, are not 'mixed-in' to th...

Groovy classloader bug?

I've encountered buggy behavior: import groovy.xml.DOMBuilder def filePath = "MestaXml.log"; def doc = DOMBuilder.parse(new FileReader(filePath)); def docElm = doc.documentElement; - $ groovy SaveTransformer.groovy Caught: java.lang.LinkageError: loader constraint violation: loader (instance of <bootloader>) previously initiated lo...

Groovy : Closures or Methods

Hi, I've got into the habbit of using Closures everywhere I can in place of regular methods, even when I don't need access to free variables. So, I will use this: def addNumbers = { left, right -> left + right } .. instead of this: def addNumbers (left,right) { left + right } Is this bad practice? I far prefer the extra power I get ...

Grails render as XML generates an unwanted class element

I am rendering a command class as XML via render foo as XML where foo is an instance of the command class. This successfully returns an XML for the objects value. However, the generated XML also contains a class element, e.g., my.package.ClassNameOfCommandObject This also happens when I do the same for a standard domain class, a...

Machine learning challenge: diagnosing program in java/groovy (datamining, machine learning)

Hi All! I'm planning to develop program in Java which will provide diagnosis. The data set is divided into two parts one for training and the other for testing. My program should learn to classify from the training data (BTW which contain answer for 30 questions each in new column, each record in new line the last column will be diagnos...

Groovyscript grails system commands

Hi, Is there a possibility of running my "grails run-app" command from my groovy script? I tried "cmd /c dir".execute() and it was working but "cmd /c grails run-app" doesn't seem to work :( Can anybody help me? I dont know how to see the output too :( ...

Call Groovy Closure from Java Class - Will it Compile?

I have some legacy Java code inside which I'd like to call a groovy Closure. Is this something that the Java / Groovy cross-compiler will be able to handle? I suspect it compiles Java first, but does it do another pass over the Groovy bytecode to resolve all the java references. Or do I need to compile the class with closure first...

Setting timeout for new URL(...).text in Groovy/Grails

I use the following Groovy snippet to obtain the plain-text representation of an HTML-page in a Grails application: String str = new URL("http://www.example.com/some/path")?.text?.decodeHTML() Now I want to alter the code so that the request will timeout after 5 seconds (resulting instr == null). What is the easiest and most Groovy wa...

Using HTML builders in grails instead of GSP

Hello, is there a way to use groovy builders to build JSP files in a Grails application keeping things enough integrated? To explain better: by default Grails uses gsp files that are nice but quite verbose.. <div class="clear"> <ul id="nav"> <li><g:link controller="snippets" action="list">Snippets</g:link></li> <li><g:link ...

Include Grails generated Java class into the grails project

How can I Include Grails generated java class into the grails project? How can I use the generated class by grails into a java class in the project. Use my Groovy class into a Java class of the Grails project. Accesing his methods, attributes, etc... Example: I have a Domain class like this: package es.prueba.domain class Author impl...

Is there a way to get the number of places after the decimal point in a java double?

I'm working on a Java/Groovy program. I have a double variable that holds a number that was typed in by a user. What I really want to know is how many numbers the user typed to the right of the decimal place. Something like: double num = 3.14 num.getPlaces() == 2 Of course, you can't do this with a double since that's using IEEE flo...

groovy XmlSlurper not parse my xml file

I have an xml, and I can't parse this file with xmlslurper. Here a copy of my xml file : <Entrezgene-Set> <Entrezgene> <Entrezgene_summary>The protein encoded by this gene is a plasma glycoprotein of unknown function. The protein shows sequence similarity to the variable regions of some immunoglobulin supergene family member proteins. [...

Hibernate: find duplicates

Hi, Assume I have the following Groovy class (or the equivalent in Java) class User { Long id String name } I would like to write a Hibernate query (either HQL or Criteria) which returns all the users that have at least one other user with the same name. Update The following query has been suggested select min(user.id), u...

How to configure grails classpath in order to add "src/groovy" folder ( in Linux environment)?

Hi, I am currently porting my development environment from Windows to Linux. Under Linux, I noticed a "No class found" compilation error related to my classes in the directory <PROJECT_HOME>/src/groovy. Under windows, it works fine. Is this "src/groovy" directory included in the CLASSPATH when running "grails run-app" ? Why does it ...

Create groovy xml with an "envelop" - add nodes in the middle of a xml structure

Hi all, (sorry for the weird title...) I want to use the groovy builder system to create a xml. My problem is that i want to have some kind of envelop around, which the user dont has to care about. An example: def builder = new groovy.xml.MarkupBuilder() builder.foo() { bar('hello') } this should create lets say <Something i...

How to read string from file using Groovy in QuickBuild

Please, some help to newbie in QuickBuild. I have a lot of versions stored in text files. To start build process I need to retrieve it and run some scripts in shell. My answer is, how to read from the file using QuickBuild environment? I know that it supports Groovy, MVEL and OGNL languages but I'm not familiar with no one of them. Tha...

how to check if a list contains a sublist

def l = ["My", "Homer"] String s = "Hi My Name is Homer" def list = s.split(" ") println list list.each{it -> l.each{it1 -> if (it == it1) println "found ${it}" } } I want to check whether big list (list) contains all elements of sublist (l) Does groovy have any built in methods to check this or what I hav...