gorm


Domain class auto validation in grails


I am fetching list of results from database but the list doesn't validates the constraints until i call "validate()" method for each objects.
def temp = ConfigInfo.where { projectId == project }.findAll()
//at this stage domain class is not validated
temp.each {
println "validate" + it.validate()
println "has error" + it.hasErrors()
}
//in the above code block validate() is called, I don't want to do this.
// is it possible to configure it happen automatically and i get the validated objects.
I don't want to invoke validate method.
is there any way or configuration in grails such that domain class get validated automatically.
Please help me in this.
Grails domain class objects get validated before save.
Use the following in your domain model to set the validation rules:
static constraints = {
// whatever you want to validate
}
Whenever you save an object it will be validated by the constraints you set. When the object is persistent in the database it has always been validated.
All you need to do is that just define all your validation in constraints closure.
e.g.
static constraints = {
id maxLength: 5
//etc...
}
at the time of saving object you just need to check object is validate or not!, it will return true/false.
look this: click here

Related Links

Neo4j and Mongodb as datasource in Grails
GORM (varchar .save(), non DATE): ORA-01861: literal does not match format string
GORM addTo methods not found in Spock test
spring-boot property exception while externalizing datasource properties and using actuator
Mapping hasMany relation and saving the related data
Method on class [] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails Correctly
What happens when two app servers in cluster start LiquiBase update (via Grails)?
use of mappedBy in Many to Many relationship in Grails
Domain class auto validation in grails
Grails Detached Criteria Query and “group by” and “having” clause
Script for saving large no of entries in mongodb
Does the multiple datasource feature of Grails 2.0 support relations?
How to avoid ImprovedNamingStrategy in joinTable in Grails
Grails 2 Show transient property that is an alias for id column
How to save GORM class with composite id made from its own field?
Grails - 2 domains and 1 form create/update/edit issues

Categories

HOME
osgi
cloud
fluentd
smarty
react-router
jsp-tags
rsync
programming-languages
jgroups
fancybox
indesign
append
contact
adfs
volttron
dtrace
sms-gateway
swingx
tar
csrf-protection
web-sql
kvc
mustache.php
pass-by-reference
zurb-foundation-6
wijmo
sparse-matrix
selectedindexchanged
phpfox
minitab
assistant
react-chartjs
ioio
protovis
phpfreechat
uiswipegesturerecognizer
plsql-psp
restlet
serve
gesture
document.write
streamreader
pdf-reactor
arena-simulation
keydown
skeleton-css-boilerplate
scrollable
pubmed
mu
recursive-datastructures
colorama
windows-mobile-6.5
pearson
python-cryptography
mcafee
quartz-composer
time-and-attendance
savon
player
gstreamer-0.10
testng-dataprovider
two-factor-authentication
lemon
thredds
cyclomatic-complexity
riak-cs
method-parameters
ami
pretty-print
facebook-graph-api-v2.4
balanced-payments
algebraic-data-types
typo3-neos
access-rights
spring-io
dotnetnuke-5
flash-builder4.5
flashvars
delphi-6
kyotocabinet
libstdc++
jspinclude
regsvr32
buildr
whoosh
coredump
disclosure
multiple-languages
wsdl.exe

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App