errors.reject not triggering a validation error in the view

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

errors.reject not triggering a validation error in the view

Jeff
This post was updated on .
I'm using errors.reject to add an error to my domain class. The problem I'm facing is that when the error gets triggered, it doesn't get rendered in the view. I tried manually setting the object to read only after adding the error as suggested in this post, but it didn't work. Here is the code snippet that I'm trying to get work:

if (!selectedAuthorities()) {
     user.errors.reject('user.roles.empty')
     GrailsHibernateUtil.setObjectToReadyOnly(user, sessionFactory)
}
if (user.hasErrors() || !user.save()) {
     render view: 'edit', model: buildUserModel(user)
     return
 }

Any help would be greatly appreciated.
Reply | Threaded
Open this post in threaded view
|

Re: errors.reject bot triggering a validation error in the view

sergiomichels
The post that you linked uses  rejectValue , have you tried this instead of reject?

On Mon, Aug 27, 2012 at 5:22 PM, Jeff <[hidden email]> wrote:
I'm using errors.reject to add an error to my domain class. The problem I'm
facing is that when the error gets triggered, it doesn't get rendered in the
view. I tried manually setting the object to read only after adding the
error as suggested in
http://athaphian.wordpress.com/2010/05/07/using-rejectvalue-to-show-validation-errors/
this  post, but it didn't work. Here is the code snippet that I'm trying to
get work:

if (!selectedAuthorities()) {
     user.errors.reject('user.roles.empty')
     GrailsHibernateUtil.setObjectToReadyOnly(user, sessionFactory)
}
if (user.hasErrors() || !user.save()) {
     render view: 'edit', model: buildUserModel(user)
     return
 }

Any help would be greatly appreciated.



--
View this message in context: http://grails.1312388.n4.nabble.com/errors-reject-bot-triggering-a-validation-error-in-the-view-tp4633849.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: errors.reject bot triggering a validation error in the view

Graeme Rocher
Administrator
In reply to this post by Jeff
It may be that your errors are being overridden by the call to save()?

On Mon, Aug 27, 2012 at 10:22 PM, Jeff <[hidden email]> wrote:

> I'm using errors.reject to add an error to my domain class. The problem I'm
> facing is that when the error gets triggered, it doesn't get rendered in the
> view. I tried manually setting the object to read only after adding the
> error as suggested in
> http://athaphian.wordpress.com/2010/05/07/using-rejectvalue-to-show-validation-errors/
> this  post, but it didn't work. Here is the code snippet that I'm trying to
> get work:
>
> if (!selectedAuthorities()) {
>      user.errors.reject('user.roles.empty')
>      GrailsHibernateUtil.setObjectToReadyOnly(user, sessionFactory)
> }
> if (user.hasErrors() || !user.save()) {
>      render view: 'edit', model: buildUserModel(user)
>      return
>  }
>
> Any help would be greatly appreciated.
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/errors-reject-bot-triggering-a-validation-error-in-the-view-tp4633849.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>



--
Graeme Rocher
Grails Project Lead
SpringSource - A Division of VMware
http://www.springsource.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email