• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Changing Domain object's constraints on the fly.

 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, I have a basic constraints for my domain class, that will allow a few fields to be nullable. But later in my app, for another use case, I will need them to be not nullable. Now I can't just set it to be not nullable, because the domain object is also used as my UserDetails object in Spring Security, and those fields need allow nulls at the time of registration.

Anyway, I created two sets of constraints and made a "submitValidation" closure that gets called to swap the constraints, then do a validate() call, but that doesn't seem to do the magic trick.




Does anyone have any other recommendations?

Thanks

Mark
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I *think* that your scenario is the reason for Command Objects.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gregg Bolinger wrote:I *think* that your scenario is the reason for Command Objects.



Ouch, I like always using my domain objects as Form backing beans. With the Command object, that would mean i need to create an adapter class to get the values from one "domain" object to another. I'd actually rather do a whole validation method in my controller rather than another domain object like a command object.

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually it isn't what command objects are for. ;)

Grails Command Objects provide a simple mechanism to validate form fields that do not map directly to domain objects.



1) Actually there isn't any form fields on the page that will do the submit.
2) If there were fields, they all map directly to my Domain object.

Basically the Band object has its own form, which the original constraints are for.

There is a link on my left nav that is a "submit to app store" link (can be clicked at any time on any page), that will take the user to a purchase page.
when they click the submit to app store link, the method behind it will get the Band object from the Spring Security Context, since I am using the domain object as my User object for Spring Security, then it will call validate on the Band object, in which the new constraints need to be used to validate.

Does this make sense? There is no form with fields or a backing object needed.

Thanks

Mark
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, I get what you saying. What you really need is some sort of conditional validation. I've looked high and low for something like that, but haven't been able to track anything down. Let me know if you find something.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW, Rails has Conditional Validation. Maybe hit the grails mailing list?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gregg Bolinger wrote:BTW, Rails has Conditional Validation. Maybe hit the grails mailing list?



Thanks for looking. I was also trying to avoid the grails mailing list because then I get 100 emails from it just saying that it doesn't know if my post even got sent to the mailing list, that it was still "waiting" and this goes on for a good month.

Mark
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is one reason I don't like model-based validation, which was one of my biggest beefs.

IMO it's solving a lower-level problem: in what states is this object completely invalid? But that stops working when the object is used in multiple contexts. Something like Costanza's Context-Oriented Programming makes sense--seems like a context could just throw something on top of an object that defines how it may be used depending on the current context.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic