Grails GORM does not persist abstract domain classes to the database, causing a break in polymorphic relationships. For example:
abstract class User {
String email
String password
static constraints = {
email(blank:false, nullable:false,email:true)
password(blank:false, password:true)
}
static hasMany = [membership:GroupMembers...
Packaging Controllers, Services,etc. i.e.
- com.company.controllers
- com.company.services
Is this a good practice or should be avoided by all means??
Another worth mentioning problem I encountered is in naming services Example
SomthingGatewayService.groovy can't be initialized in both these ways
- SomthingGatewayService somtinggatew...
I am using a string "username" as the primary-key of a table,
But when saving and getting the column with the username id I want the case to be ignored so that new users can't try to impersonate another user.
e.g. When registering a new user
username = Daxon
username = DaXoN //this should not be allowed
When getting the unique user...
I have a domain class, in which I've defined some methods which give the object a score based on different algorithms (eg. popularity).
I now want to retrieve a list of these objects sorted by one of these scores (eg. descending by popularity score).
Is there a way to do with with GORM?
Example class:
class SomeObject {
String ti...
Hi,
as I am new to Grails and dynamic languages, I do have some 'hopefully simple' question.
I installed the taggable plugin which works fine. There is an array coming in with tags. I collect for every tag the set of data with findAllByTag. After that I randomise it and pick one entry. Works great. Now I decided not to take all objects...
I have Grails 1.1.1 and Groovy 1.6.3 on Leopard. Will I have any issues with this combo: Snow Leopard + Grails 1.1.1 + Groovy 1.6.5?
...
I am trying to set a variable for the current user (a POJO) in all views so I can get things like the user name and check their role on every view (including the default layout). How can I setup something (e.g. currentUser) in grails so that it is accessible in every grails view like so:
<div>${currentUser.name}</div>
or like this:
<...
This works as expected in a GSP-page:
<td>${Foo.findAllByBar(bar)}</td>
But when adding a collect statement the code breaks ..
<td>${Foo.findAllByBar(bar).collect { it.name }}</td>
with
Error 500: Could not parse script [...gsp]: startup failed,
...: 129: expecting '}', found ')'
@ line 129, column 196. 1 error`.
I wa...
My development environment (Mac OS 10.6) uses JDK 1.6 while production relies on 1.5. Upgrading the prod to 1.6 isn't an option at the moment so I followed the steps to install 1.5 on my machine. However, after I set the correct JAVA_HOME version to 1.5 with Grails 1.1, I get the error message:
2009-11-12 09:20:34,881 INFO [STDOUT] 09:...
I'm trying to follow the grails tutorial here.
When I create a new controller using create-controller XXX.Card and modify it to use scaffolding as per the tutorial:
package XXX
class CardController {
def scaffold = Card
}
I get the following exception when I click on XXX.CardController:
org.codehaus.groovy.runtime.InvokerInvo...
Hey People of Groovy,
I am looking for a way to modify/change an existing closure. However, I do not wish to overwrite it; instead I would like to enhance it.
Here is a quick example. Let's say we have an Address object:
class Address {
String street
String city
String state
String zipCode
static constraints = {
...
I don't see anything in the official documentation about unsupported persistence data types, so I'm working under the assumption that types available in the Groovy language should be handled. However, for the following domain class:
class DocGroupPermissions {
Workgroup workgroup;
Document document;
BitSet permissions = new BitSet(2)
p...
class Address {
static hasMany = [addressGroups: AddressGroup]
...
}
class AddressGroup {
static belongsTo = Address
static hasMany = [addresses: Address]
String notation;
...
}
I try to fetch all Addresses for a given AddressGroup.
My code:
def params = [max: 10]
def addressGroup = AddressGroup.findByNota...
Which setting do I now use to produce logging output with 'log.info' statements within my own controllers?
Here's what I've setup in config.groovy and I thought placing my domain under the info level would do the trick but it doesn't. Neither does placing the groovy.grails.web.* packages under info section..
log4j = {
error 'org.c...
In Grails, there are two mechanisms for modularity in the view layers : template and taglib.
While I am writing my own Grail app, I am often facing the same question when I need to write an UI component : do I need to use a template or a tagLib ?After searching the web, I didn't find a lot of best practices or rules of thumb concerning ...
The Grails Config.groovy setting grails.views.default.codec specifies the default codec used to encode data within ${...} in Grails views.
This config setting can take any of the values none (no filtering required), html (to avoid XSS-attacks) and base64 (has no real-world use-case that I know of).
The Grails default is none (no filter...
Assume the following code in a Grails controller:
def action = {
ClassName o = ClassName.findByFoo(params.foo)
if (o) {
o.counter += 1
}
}
By default Grails uses optimistic locking via the version column added by default to all GORM database tables. However, if a sufficiently large number of multiple concurrent requests are ...
My system has 2 subsystems. Each subsystem has different set of users. Each user has an extra field "SystemName" that can be used to know which system this user belongs to.
In the login forms (1 form for each subsystem) I added a hidden field specifying the type of the form (containing the SystemName value).
Generally, the check is rat...
Removing an element from a list isn't working, which doesn't make any sense. Am I missing some special semantics peculiar to dealing with a Grails domain object list?
In controller:
def userCreate = {
def workgroupInstance = new Workgroup()
workgroupInstance.manager = authUserDomain
flash.message = User.list().toString()
...
Almost every controller action looks up one or more entities based on some user input. For some time I've been wanting to remove some of this boring, dry-breaking, boilerplate code:
def show = {
def entity = null
if (params.id && params.id.isLong() && params.id.toLong() >= 0)
entity = Book.get(params.id.toLong())
if (!e...