grails-validation

How to access command objects from filter and is it possible at all?

[亡魂溺海] 提交于 2020-01-13 19:11:36
问题 I often write something like: def myAction{ MyActionCommand cmd -> if( cmd.hasErrors() ){ return render(status:HttpServletResponse.SC_BAD_REQUEST ); }else{ // actual action logic } So, I'd like to extract that common pattern into some reusable location. Filter looks like good candidate, but I can't find the way to get command object from the filter. Tryed something like this (in filters closure): formValidation( controller:'*', action:'*' ){ before = { cmd -> if( cmd.hasErrors() ){ response

How to access command objects from filter and is it possible at all?

纵然是瞬间 提交于 2020-01-13 19:11:11
问题 I often write something like: def myAction{ MyActionCommand cmd -> if( cmd.hasErrors() ){ return render(status:HttpServletResponse.SC_BAD_REQUEST ); }else{ // actual action logic } So, I'd like to extract that common pattern into some reusable location. Filter looks like good candidate, but I can't find the way to get command object from the filter. Tryed something like this (in filters closure): formValidation( controller:'*', action:'*' ){ before = { cmd -> if( cmd.hasErrors() ){ response

How to access command objects from filter and is it possible at all?

不羁的心 提交于 2020-01-13 19:11:06
问题 I often write something like: def myAction{ MyActionCommand cmd -> if( cmd.hasErrors() ){ return render(status:HttpServletResponse.SC_BAD_REQUEST ); }else{ // actual action logic } So, I'd like to extract that common pattern into some reusable location. Filter looks like good candidate, but I can't find the way to get command object from the filter. Tryed something like this (in filters closure): formValidation( controller:'*', action:'*' ){ before = { cmd -> if( cmd.hasErrors() ){ response

What is the connection between validate() and hasErrors()

為{幸葍}努か 提交于 2019-12-22 04:12:25
问题 This question comes from the problem of another question of mine. In that question, I come across a situation that hasErrors() function doesn't work for non-persistent domain class , even after all the things I did following the instruction, part 7.5 . Following Victor's way, I fixed the problem by calling validate(), but I don't understand why it works. The Grails documents seem to say nothing about you should call a validate() before hasErrors() function. How could this happen? 回答1: It does

Grails validation of a list objects

青春壹個敷衍的年華 提交于 2019-12-13 13:19:24
问题 I'm trying to get grails to validate the contents of a List of objects, might be easier if I show the code first: class Item { Contact recipient = new Contact() List extraRecipients = [] static hasMany = [ extraRecipients:Contact ] static constraints = {} static embedded = ['recipient'] } class Contact { String name String email static constraints = { name(blank:false) email(email:true, blank:false) } } Basically what i have is a single required Contact ('recipient'), this works just fine:

Grails unique test fails after interchanging attribute values

大兔子大兔子 提交于 2019-12-10 11:47:17
问题 Hello I am trying to implement a simple translation list, meaning I have a values and translations to this values. [Edit:] As this is part of my user interface and values and translations shall be exportable via xml, using the i18n files seams quite inconvinient for this proposition. Thats why I decided to store them in a database. I have one domain class for a value: class Value { String label static hasMany = [ translations: Translation ] } and one for translations with a unique constraint

grails validate nested command object not working

我的梦境 提交于 2019-12-07 03:39:56
问题 I'm using grails 2.2.1 and attempting to validate a nested command structure. Here is a simplified version of my command objects: @Validateable class SurveyCommand { SectionCommand useful SectionCommand recommend SurveyCommand() { useful = new SectionCommand( question: 'Did you find this useful?', isRequired: true) recommend = new SectionCommand( question: 'Would you recommend to someone else?', isRequired: false) } } @Validateable class SectionCommand { String question String answer boolean

Grails custom validator for domain class

China☆狼群 提交于 2019-12-06 08:01:27
问题 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 = {

How to access command objects from filter and is it possible at all?

人走茶凉 提交于 2019-12-06 06:42:49
I often write something like: def myAction{ MyActionCommand cmd -> if( cmd.hasErrors() ){ return render(status:HttpServletResponse.SC_BAD_REQUEST ); }else{ // actual action logic } So, I'd like to extract that common pattern into some reusable location. Filter looks like good candidate, but I can't find the way to get command object from the filter. Tryed something like this (in filters closure): formValidation( controller:'*', action:'*' ){ before = { cmd -> if( cmd.hasErrors() ){ response.sendError( HttpServletResponse.SC_BAD_REQUEST ); return false; }else{ return true; } } } Intersted in

Grails conditional nullable validation or custom validator with nullable option

与世无争的帅哥 提交于 2019-12-06 01:47:15
问题 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