You can validate on the record as well as individual fields. There are also a bunch of object lifecycle hooks in MetaMapper:
def beforeValidation: List[A => Any] = Nil def beforeValidationOnCreate: List[A => Any] = Nil def beforeValidationOnUpdate: List[A => Any] = Nil def afterValidation: List[A => Any] = Nil def afterValidationOnCreate: List[A => Any] = Nil def afterValidationOnUpdate: List[A => Any] = Nil def beforeSave: List[A => Any] = Nil def beforeCreate: List[(A) => Any] = Nil def beforeUpdate: List[(A) => Any] = Nil def afterSave: List[(A) => Any] = Nil def afterCreate: List[(A) => Any] = Nil def afterUpdate: List[(A) => Any] = Nil def beforeDelete: List[(A) => Any] = Nil def afterDelete: List[(A) => Any] = Nil /** * If there are model-specific validations to perform, override this * method and return an additional list of validations to perform */ def validation: List[A => List[FieldError]] = Nil Does this help? 2009/6/10 dflemstr <[email protected]> > > Hello everyone, > I am currently using the Mapper framework to create a very complex > data storage system. In this system, I have the need of changing one > or more MappedFields depending on another MappedField, for example: > > trait NonUserEditable > > object MyMapper extends LongKeyedMetaMapper[MyMapper] with CRUDify > > class MyMapper extends LongKeyedMapper[MyMapper] with IdPK { > def getSingleton = MyMapper > > object field1 extends MappedString(this, 64) with LifecycleCallbacks > { > override def beforeValidationOnUpdate {field2(is.capitalize); > super.beforeValidationOnUpdate} > } > > object field2 extends MappedString(this, 64) with NonUserEditable > } > > I am now looking for the most elegant way to do this; I need > validations on both fields above (which the above code doesn't allow), > and I would like to use CRUDify as much as possible (which might be > overkill but who knows). > So, the goal is to allow for the following process : > 1. The user submits a form containing data for field1 through CRUDify > (→ done) > 2. The data is stored in field1 by crudDoForm (→ done) > 3. field1 is validated, but not field2 (→ How would I do this? Do I > need to rewrite crudDoForm? Because now all fields are validated in > one go, without filtering) > 4. Some custom action in field1 is invoked that changes field2 (→ I > can do this with afterValidationOnUpdate if the above point succeeds, > but not otherwise) > 5. field2 is changed (→ done, in the custom action) > 6. field2 is validated (→ done) > 7. Any errors from validations are displayed to the user (→ Can this > be done? Specifically, can I validate field2 in the same cycle as > field1?) > > I have hacked CRUDify with a NonUserEditable trait as demonstrated > above (but my hacks are not ;) ) so that CRUDify doesn't include some > fields in its "create" form (dbIncludeInForm_? is BROKEN; the CRUD > "list" doesn't display the hidden field when overriding > dbIncludeInForm_?), so think of the field2 as completely hidden to the > user in the create form. The only problems remaining are the ones > listed above. > > Any suggestions on how to solve this would be greatly appreciated. > > > > -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---
