Validation framework thoughts

4 views
Skip to first unread message

Tom Chiverton

unread,
Jan 7, 2009, 1:01:42 PM1/7/09
to reacto...@googlegroups.com
Where and how would people imagine this would work ?

You'd write in your reactor.xml (and any addField() method):
<field alias="clientCode" name="client" validateAs="clientCode"/>

And then you'd be able to do:
<cfset UserRecord = Reactor.createRecord("User").load(userId=1) />
<cfset UserRecord.setClientCode(arguments.newCode)/>

and then
<cfdump var="#UserRecord.isValid('clientCode')#"/>
or maybe
<cfdump var="#UserRecord.isClientCodevalid()#"/>
and get a boolean ?

I'm also thinking a new <config> child element called
<validationClass> which gives the name of a CFC that implements a
particular CFInterface, and that will be used by Reactor to actually
do the check ?
--
Tom

Mark Drew

unread,
Jan 7, 2009, 1:11:52 PM1/7/09
to reacto...@googlegroups.com
That is nearly exactly what I was thinking

We should have a list of validations types (look at the isValid
function ) that we support, then we can add more to that (such as
ukpostcode)

You should be able to get a ValidationResult object which specifies
what is the result and which fields failed for example.

We could then add ValidationObjects as you said under
model/reactor/Validations that you can map via

<validation handler="/model/reactor/Validations/MyHandler"
name="DogHeadValidation" />

This would extend a reactor.core.validations.Validation and have a
"validate" method that you need to first super() to validate standard
then implement your validation

Pretty close too




Mark Drew

- Adobe Community Expert
- Reactor ORM Project Manager
- CFEclipse Project Lead Developer
Blog: http://www.markdrew.co.uk/blog/
LinkedIn: http://www.linkedin.com/in/mdrew

Tom Chiverton

unread,
Jan 7, 2009, 2:25:51 PM1/7/09
to reacto...@googlegroups.com
2009/1/7 Tom Chiverton <tom.ch...@gmail.com>:
> <cfset UserRecord.setClientCode(arguments.newCode)/>

> <cfdump var="#UserRecord.isValid('clientCode')#"/>

Should the 'default' behaviour be to throw an exception on the set,
for instance ?

It should also be easy to write a custom validator that checked the
'main' validator result, and threw an exception if it failed, so
people can use that pattern if they like.

--
Tom

Tom Chiverton

unread,
Jan 7, 2009, 2:37:40 PM1/7/09
to reacto...@googlegroups.com
2009/1/7 Mark Drew <mark...@gmail.com>:

> That is nearly exactly what I was thinking

\o/

> You should be able to get a ValidationResult object which specifies
> what is the result and which fields failed for example.

So UserRecord.isValid() that returns an array of ValidationResult
(fieldName,valueString,isValidBool) ?
As well as isFieldNameValid() ?

The former would follow easily from the latter of course, but choice
could confuse people.

> We could then add ValidationObjects as you said under
> model/reactor/Validations that you can map via
> <validation handler="/model/reactor/Validations/MyHandler"
> name="DogHeadValidation" />

And Reactor automatically pumps in a standard set of Validations ?
In which case Reactor might as well just find all CFC in
m.r.validators and create them without the need for a <validation>
tag, it occurs ... ?

> This would extend a reactor.core.validations.Validation and have a
> "validate" method that you need to first super() to validate standard
> then implement your validation

I assume r.c.v.V would be an interface, right ? So implements not extends ?
I'm not sure they'd be any common code to go in a super class (unless
you wanted to make a FooBarEmailValidator that extends the 'core'
EmailValidator).

I would imagine each Validator just needs a single method:
isValid(Record,fieldNameToCheck) ?

I can (one time) autogenerate a set of default validators that just
wrap isValid() fairly easily from that
(isValid('email',Record[fieldNameToCheck) etc. ).

As a PoC that the system is extensible, add some other ones that use ValidAt.
Until I actually find an example of how to use ValidAt, I'm not sure
if validators based on it should ship in the core or not.
Guess we'll see :-)

--
Tom

Tom Chiverton

unread,
Jan 7, 2009, 2:39:23 PM1/7/09
to reacto...@googlegroups.com
2009/1/7 Tom Chiverton <tom.ch...@gmail.com>:

>> We could then add ValidationObjects as you said under
>> model/reactor/Validations that you can map via
>> <validation handler="/model/reactor/Validations/MyHandler"
>> name="DogHeadValidation" />
>
> And Reactor automatically pumps in a standard set of Validations ?
> In which case Reactor might as well just find all CFC in
> m.r.validators and create them without the need for a <validation>
> tag, it occurs ... ?

Gah.
Reactor should locate all the 'default' validators using something
like that, maybe. But we still need a validation tag so users can add
ones from com.compantname.project.validators.Foo etc.

--
Tom

Reply all
Reply to author
Forward
0 new messages