grails-domain-class

Grails custom validator for domain class

空扰寡人 提交于 2019-12-04 13:08:24
I have a restriction so there could be no more than ConfigurationHolder.config.support.reminder.web.person.max object stored. I didn't find how to add a validator which doesn't relate on particular property. So for now I implemented it in this way. Do you guys have any ideas how to make it better? package support.reminder.web import org.codehaus.groovy.grails.commons.ConfigurationHolder; class Person { String firstName String lastName String email Date lastDutyDate static constraints = { firstName(blank: false) lastName(blank: false) email(blank: false, email: true) lastDutyDate(nullable: true

How to override the DomainClass.list() in GORM (Grails)

☆樱花仙子☆ 提交于 2019-12-04 12:45:12
People, I'm facing a problem with grails GORM , my Application is totally dependent of the DomainClass.list() method, it is in all of my create/edit GSPs, but now I need a particular behavior for listing objects. Being more specific I need to filter these lists (All of them) by one attribute. The problem is I'm hoping not to change all the appearances of these methods calling, so is there a way to customize the behavior of the default list() method ? I need it to function just the way it does, but adding an ending filter. Maybe you can use hibernate filter plugin (see here ). This will allow

Where should I place a transient domain class in a grails app?

血红的双手。 提交于 2019-12-04 11:17:08
问题 Where should I place a transient domain class in a grails app? Ie I have an Action class that will be passed about, and used, but never saved. Should this be in the grails-app/domain folder, or somewhere else? 回答1: grails-app/domain is for persistent domain classes, but not all of your application's domain-related classes need to be there, e.g. in this case where you want to use it as a value object. You can put these in src/groovy along with other classes that aren't considered Grails

Grails 2.4.2 - Dynamically referencing default datasource

余生颓废 提交于 2019-12-04 09:21:37
This question has been partly answered here but there is still an issue with referencing the default datasource dynamically. I'm working on an internal application that allows developers to modify configuration settings for one of our multi-tenant applications and push those settings from dev to testing, staging and production. Each one of these will have their own datasource, and the Grails app will be installed on each developer's computer. The local datasource will be the default one, and then dataSource_testing, dataSource_staging and so on will reference the appropriate environments. I

Setting default value for Date field in Grails Domain Class

寵の児 提交于 2019-12-04 08:57:19
I'm trying to set a default value for a Date field in a Domain class. I can use defaultValue in the mapping configuration but it doesn't work with Date fields (I've tried it on String and Integer and it works fine). This is an example: class Something { Date myField static mapping = { myField defaultValue: new Date() } } This code fails because the CREATE statement that Hibernate generates is incorrect. It is something like: ... my_field datetime default Mon Nov 25 17:59:08 UYST 2013 not null ... You can always initialize the field in the static initializer or set the value in the constructor:

Grails conditional nullable validation or custom validator with nullable option

你说的曾经没有我的故事 提交于 2019-12-04 06:42:31
I have a form to create a place. Depending of the country, the province (state, region) field is required or not. When is not required, I want to be null, not empty string. I have code that makes all empty form fields, null: def newparams = [:] place = new Place() params.each() { k, v -> if (v instanceof String && place.hasProperty(k)) { if (!v.trim().length()) { newparams[k] = null } else { newparams[k] = v } } } place = new Place(newparams) place.validate() Now, in the place domain, I have a validator on the province: province validator: {val, obj -> if (obj.country in obj

What is a good workflow for database migration in Grails?

落花浮王杯 提交于 2019-12-03 15:46:14
I want to use the database-migration grails plugin for database migration. When I start my Grails app the first time all the database tables are created automatically. The production setting in my DataSource.groovy is: production { dataSource { dbCreate = "update" url = "jdbc:mysql://localhost/myapp?useUnicode=yes&characterEncoding=UTF-8" username = "test" password = "test" dialect = org.hibernate.dialect.MySQL5InnoDBDialect properties { validationQuery = "select 1" testWhileIdle = true timeBetweenEvictionRunsMillis = 60000 } } } In my config.groovy I set: grails.plugin.databasemigration

dateCreated, lastUpdated fields in Grails 2.0

落花浮王杯 提交于 2019-12-03 12:17:14
I've got an application that was using Grails 1.3.7 which I've just migrated to Grails 2.0. The application makes use of the automatic dateCreated and lastUpdated fields to manage the timestamps associated with creation and modification of the objects. After upgrading, I get the following error: | Running Grails application | Error 2012-01-29 22:36:53,504 [Thread-8] ERROR util.JDBCExceptionReporter - ERROR: null value in column "date_created" violates not-null constraint | Error 2012-01-29 22:36:53,510 [Thread-8] ERROR events.PatchedDefaultFlushEventListener - Could not synchronize database

Where should I place a transient domain class in a grails app?

故事扮演 提交于 2019-12-03 06:58:30
Where should I place a transient domain class in a grails app? Ie I have an Action class that will be passed about, and used, but never saved. Should this be in the grails-app/domain folder, or somewhere else? grails-app/domain is for persistent domain classes, but not all of your application's domain-related classes need to be there, e.g. in this case where you want to use it as a value object. You can put these in src/groovy along with other classes that aren't considered Grails artifacts. If you want the classes to support validation, you can annotate them with @Validateable - see section

How to hide password fields from Grails scaffolding views?

余生长醉 提交于 2019-12-02 19:06:14
问题 According to the docs, Grails provides a number of constraints that "have no impact on persistence but customize the scaffolding". One of them is the password constraint. Here's how I use it: class User { String username String password static constraints = { username blank: false password blank: false, password: true } } In combination with scaffolding, this has the effect that the edit view uses a specialized password input for my password field (that's fine), but the index and show view