If you have a common pattern, reducing it to a subclass makes sense. But if
you don't want to do that, here's some shortening:
object Validate {
def notEmpty(fi: FieldIdentifier)(value: String) =
List(FieldError(fo, Text("...")).filter(x => value.length == 0)
}
import Validate._
object name extends MappedPoliteString(this, 16) {
override def validations = notEmpty(this) _ :: super.validations
}
By importing the object, you save the text of retyping the "Validate." stuff
over and over again.
Thanks,
David
On Tue, Jun 9, 2009 at 6:40 AM, Magnus Alvestad
<[email protected]>wrote:
>
> Hi. In my lift application using Mapper, I'm doing this all the time:
>
> object name extends MappedPoliteString(this, 16) {
> override def validations = Validate.notEmpty(this) _ ::
> super.validations
> }
>
> where Validate is defined:
>
> object Validate {
> val valid = List[FieldError]()
> def notEmpty(fi: FieldIdentifier)(field: String) = {
> if (field.length == 0)
> List(FieldError(fi, Text("Field cannot be empty")))
> else
> valid
> }
>
> This code works, but is a bit verbose, especially when there are 10 or
> more strings in a class. I guess I could define a new class
> MappedPoliteNonEmptyString, but are there other (better) alternatives?
>
> -Magnus
>
> >
>
--
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
-~----------~----~----~----~------~----~------~--~---