grails-validation

Grails client side validation

巧了我就是萌 提交于 2019-12-06 01:31:10
问题 How do you (if you) manage client side validation with grails ? Do you use a plugin or do you mirror your constraints using a javascript framework ? Cheers 回答1: I haven't used them personally but these two plugins might help you out: http://grails.org/plugin/javascript-validator http://www.grails.org/plugin/remote-constraints 回答2: On Grails projects that I've been a part of, We haven't used a plugin but rather a mashup of javascript plugins and custom validators (jQuery plugins, Prototype,

How can I override the default error message in Grails?

大城市里の小女人 提交于 2019-12-05 13:12:13
问题 I have a Person object with a lastName field. The lastName field cannot be blank. When the user submits a form blank value in the lastName field, the error message that the user sees is: Property [lastName] of class [com.example.Person] cannot be blank This error message is lame. I want to customize it to something more user friendly, like "The Last Name field cannot be blank" How do I do that? 回答1: See Chapter 7 of the docs: http://grails.org/doc/latest/ You would change grails-app/i18n

grails validate nested command object not working

我怕爱的太早我们不能终老 提交于 2019-12-05 08:17:25
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 isRequired static constraints = { answer(validator: answerNotBlank, nullable: true) } static

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

半世苍凉 提交于 2019-12-05 04:08:17
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? It does make sense to me that validate would need to be called before asking an object whether it hasErrors (or

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

Grails Problem with custom error messages

穿精又带淫゛_ 提交于 2019-12-04 09:14:11
问题 I am currently trying to specify custom error messages in grails for the default constraints but so far all I get back is the default error message. I know that I have to edit the grails-app/i18n/messages.properties file If I change the following default error codes message, it will correctly display the new error message default.blank.message=Property [{0}] of class [{1}] cannot be blank However, this is not what I am trying to do. I need more granular error reporting and have more than one

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

Grails client side validation

只愿长相守 提交于 2019-12-04 05:10:20
How do you (if you) manage client side validation with grails ? Do you use a plugin or do you mirror your constraints using a javascript framework ? Cheers leebutts I haven't used them personally but these two plugins might help you out: http://grails.org/plugin/javascript-validator http://www.grails.org/plugin/remote-constraints On Grails projects that I've been a part of, We haven't used a plugin but rather a mashup of javascript plugins and custom validators (jQuery plugins, Prototype, Dojo, etc.) to achieve the client side validation. Its handy to provide instant field-level validation on

How can I override the default error message in Grails?

笑着哭i 提交于 2019-12-04 00:57:40
I have a Person object with a lastName field. The lastName field cannot be blank. When the user submits a form blank value in the lastName field, the error message that the user sees is: Property [lastName] of class [com.example.Person] cannot be blank This error message is lame. I want to customize it to something more user friendly, like "The Last Name field cannot be blank" How do I do that? See Chapter 7 of the docs: http://grails.org/doc/latest/ You would change grails-app/i18n/messages.properties and add person.lastName.blank=The Last Name field cannot be blank In Grails 3 you need to

Displaying Grails Field Errors

孤街浪徒 提交于 2019-12-03 06:10:09
Does anybody know how I could get the fieldError to print out in the example below. for each item with an error, I would like to print custom error messages that I have defined in the messages.properties file at the moment all this does is print the default error codes item.errors?.allErrors?.each{ println it.toString() } I have seen other examples where you can lookup an error code for a field e.g. it.getFieldError('title').code but I would like to convert the default message into my new error message and print that. You need access to the messageSource bean, e.g. with def messageSource in