Using Property Annotations

30 views
Skip to first unread message

Richard Herbert

unread,
Mar 19, 2012, 11:44:51 AM3/19/12
to valida...@googlegroups.com
Hi,

I'm looking for some guidance on using Property Annotations rather than the traditional XML rules files.

Can't seem to find any doc's?

Where can I find some words to get me going?

Richard

Robert Rawlins

unread,
Mar 19, 2012, 11:48:52 AM3/19/12
to valida...@googlegroups.com
Hi Richard,

The syntax for these is the same as that for JSON (http://www.validatethis.org/docs/wiki/Sample_Rules_Definition_File.cfm) rules, you just pass the JSON rules string as a 'vtrules' attribute on the cfproperty tag, something like this:

property name='name' vtrules='[
{"type":"required"},
{"type":"rangelength",
"params" : [
{"name":"minlength","value":"1"},
{"name":"maxlength","value":"50"}
]
}
]';

Hope that helps.

Robert

--
You received this message because you are subscribed to the Google Groups "ValidateThis" group.
To view this discussion on the web visit https://groups.google.com/d/msg/validatethis/-/JCnkU6X4FeYJ.
To post to this group, send email to valida...@googlegroups.com.
To unsubscribe from this group, send email to validatethis...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/validatethis?hl=en.

Richard Herbert

unread,
Mar 19, 2012, 11:59:22 AM3/19/12
to valida...@googlegroups.com
Okay, I can see that working for server-side but does it provide the rules for client-side validation?

Bob Silverberg

unread,
Mar 19, 2012, 12:08:35 PM3/19/12
to valida...@googlegroups.com
It should. Once you have the rules defined, and recognized by the
framework, the format has no effect. If you are getting server-side
vals to work it should work as well for client-side. Perhaps you are
doing something wrong when asking for the client-side validations?

Bob

> --
> You received this message because you are subscribed to the Google Groups
> "ValidateThis" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/validatethis/-/6BW4Z_MmIakJ.


>
> To post to this group, send email to valida...@googlegroups.com.
> To unsubscribe from this group, send email to
> validatethis...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/validatethis?hl=en.

--
Bob Silverberg
www.silverwareconsulting.com

Richard Herbert

unread,
Mar 19, 2012, 12:38:13 PM3/19/12
to valida...@googlegroups.com
Okay, let me investigate further and come back to you.

Thanks for your time guys :-)


On Monday, March 19, 2012 4:08:35 PM UTC, Bob Silverberg wrote:
It should. Once you have the rules defined, and recognized by the
framework, the format has no effect. If you are getting server-side
vals to work it should work as well for client-side. Perhaps you are
doing something wrong when asking for the client-side validations?

Bob

On Mon, Mar 19, 2012 at 11:59 AM, Richard Herbert <ric...@infoweb.co.uk> wrote:
> Okay, I can see that working for server-side but does it provide the rules
> for client-side validation?
>
>
> On Monday, March 19, 2012 3:44:51 PM UTC, Richard Herbert wrote:
>>
>> Hi,
>>
>> I'm looking for some guidance on using Property Annotations rather than
>> the traditional XML rules files.
>>
>> Can't seem to find any doc's?
>>
>> Where can I find some words to get me going?
>>
>> Richard
>
> --
> You received this message because you are subscribed to the Google Groups
> "ValidateThis" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/validatethis/-/6BW4Z_MmIakJ.
>
> To post to this group, send email to valida...@googlegroups.com.
> To unsubscribe from this group, send email to


> For more options, visit this group at
> http://groups.google.com/group/validatethis?hl=en.

Richard Herbert

unread,
Mar 22, 2012, 5:50:30 AM3/22/12
to valida...@googlegroups.com
Okay, the question seems to be, how do I get VT to use the annotated entity properties instead the XML rules file?

When I have a rules file for the object to be validated in the nominated "definitionPath" location all is fine for client and server-side validation. When I remove that file and expect VT to fall back to the annotation in the entity both client and server-side validation are not applied.

Is there a setting I've not found to tell VT to use entity property annotation rules instead of an XML rules file?

Here's my simple entity...


component entityname="User" persistent="false" {
property name="username" vtRules='[{"type":"required","contexts":"*",failuremessage="A username is required."}]';
property name="password" vtRules='[{"type":"required","contexts":"*"}]';

John Whish

unread,
Mar 22, 2012, 8:08:24 AM3/22/12
to valida...@googlegroups.com
Hi Richard,

I don't use the annotations, but AFAIK it should just pick them up without you needing to explicitly state. Might be worth checking out the annotation demo:



To view this discussion on the web visit https://groups.google.com/d/msg/validatethis/-/kKVsXFoHR94J.

To post to this group, send email to valida...@googlegroups.com.
To unsubscribe from this group, send email to validatethis...@googlegroups.com.

Richard Herbert

unread,
Mar 22, 2012, 9:27:45 AM3/22/12
to valida...@googlegroups.com
Ah, I didn't know there was a demo of annotations. I'll take a look, thanks.
To unsubscribe from this group, send email to validatethis+unsubscribe@googlegroups.com.

Bob Silverberg

unread,
Mar 22, 2012, 2:02:04 PM3/22/12
to valida...@googlegroups.com
Unfortunately I've never used the annotations either, and I do think
it's supposed to work the way John described and you expect. I don't
think you can combine an xml file and annotations, though. You should,
theoretically, be able to have objectA described by an xml file and
objectB described using annotations, but I don't know that that has
ever been tested or attempted, so it's possible that something in the
framework precludes that. Is that what you're trying to do?

Bob

>>>>> > validatethis...@googlegroups.com.


>>>>> > For more options, visit this group at
>>>>> > http://groups.google.com/group/validatethis?hl=en.
>>>>>
>>>>> --
>>>>> Bob Silverberg
>>>>> www.silverwareconsulting.com
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "ValidateThis" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/validatethis/-/kKVsXFoHR94J.
>>>
>>> To post to this group, send email to valida...@googlegroups.com.
>>> To unsubscribe from this group, send email to

>>> validatethis...@googlegroups.com.


>>> For more options, visit this group at
>>> http://groups.google.com/group/validatethis?hl=en.
>>
>>
> --

> You received this message because you are subscribed to the Google Groups
> "ValidateThis" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/validatethis/-/fT0UbcCHjoYJ.


>
> To post to this group, send email to valida...@googlegroups.com.
> To unsubscribe from this group, send email to

> validatethis...@googlegroups.com.

Richard Herbert

unread,
Mar 23, 2012, 11:16:53 AM3/23/12
to valida...@googlegroups.com
I like the idea of storing the validation rules of an object in with the entity definition, a bit like CFWheels does but for unrelated reasons I think I'll be going back to using XML rule files.

That said, I'll try an revisit this approach in my own time.

Thanks Bob and John for your thoughts.


>>>>> > For more options, visit this group at
>>>>> > http://groups.google.com/​group/validatethis?hl=en.
>>>>>
>>>>> --
>>>>> Bob Silverberg
>>>>> www.silverwareconsulting.com
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "ValidateThis" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/​msg/validatethis/-/​kKVsXFoHR94J.
>>>
>>> To post to this group, send email to valida...@googlegroups.com.
>>> To unsubscribe from this group, send email to


>>> For more options, visit this group at
>>> http://groups.google.com/​group/validatethis?hl=en.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "ValidateThis" group.
> To view this discussion on the web visit
> https://groups.google.com/d/​msg/validatethis/-/​fT0UbcCHjoYJ.
>
> To post to this group, send email to valida...@googlegroups.com.
> To unsubscribe from this group, send email to


> For more options, visit this group at
> http://groups.google.com/​group/validatethis?hl=en.

John Whish

unread,
Mar 23, 2012, 11:19:58 AM3/23/12
to valida...@googlegroups.com
Hi Richard,

I like the idea of having the rules inside the object as well, but for practical terms I don't use it and prefer to use the XML. My reasons are:

- cfc meta data caches in ColdFusion, so you often have to restart the server to update rules
- The syntax is hard to read for comlicated rules
- There is no validation of your rules like you get by using the XML schema

Cheers,

John


To view this discussion on the web visit https://groups.google.com/d/msg/validatethis/-/F0u1mTWxmIMJ.

To post to this group, send email to valida...@googlegroups.com.
To unsubscribe from this group, send email to validatethis...@googlegroups.com.

Bob Silverberg

unread,
Mar 23, 2012, 11:34:59 AM3/23/12
to valida...@googlegroups.com
Thanks Richard and John. I'll add another reason to John's list:

Ideally you don't want to edit files that contain code. Any time you
open up a cfc or cfm to make a change you are potentially adding a
bug. If you can leave your cfcs untouched, and just define and change
rules in an xml file then there is less chance of introducing a bug.

Bob

>>> >>>>> > validatethis...@googlegroups.com.
>>> >>>>> > For more options, visit this group at
>>> >>>>> > http://groups.google.com/group/validatethis?hl=en.
>>> >>>>>

>>> >>>>> --
>>> >>>>> Bob Silverberg
>>> >>>>> www.silverwareconsulting.com
>>> >>>
>>> >>> --
>>> >>> You received this message because you are subscribed to the Google
>>> >>> Groups
>>> >>> "ValidateThis" group.
>>> >>> To view this discussion on the web visit
>>> >>> https://groups.google.com/d/msg/validatethis/-/kKVsXFoHR94J.
>>> >>>
>>> >>> To post to this group, send email to valida...@googlegroups.com.
>>> >>> To unsubscribe from this group, send email to

>>> >>> validatethis...@googlegroups.com.
>>> >>> For more options, visit this group at
>>> >>> http://groups.google.com/group/validatethis?hl=en.
>>> >>
>>> >>

>>> > --
>>> > You received this message because you are subscribed to the Google
>>> > Groups
>>> > "ValidateThis" group.
>>> > To view this discussion on the web visit
>>> > https://groups.google.com/d/msg/validatethis/-/fT0UbcCHjoYJ.
>>>
>>> >
>>> > To post to this group, send email to valida...@googlegroups.com.
>>> > To unsubscribe from this group, send email to

>>> > validatethis...@googlegroups.com.
>>> > For more options, visit this group at
>>> > http://groups.google.com/group/validatethis?hl=en.
>>>
>>> --
>>> Bob Silverberg
>>> www.silverwareconsulting.com
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "ValidateThis" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/validatethis/-/F0u1mTWxmIMJ.
>>
>> To post to this group, send email to valida...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> validatethis...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/validatethis?hl=en.
>
>

> --
> You received this message because you are subscribed to the Google Groups
> "ValidateThis" group.

> To post to this group, send email to valida...@googlegroups.com.
> To unsubscribe from this group, send email to
> validatethis...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/validatethis?hl=en.

--
Bob Silverberg
www.silverwareconsulting.com

Richard Herbert

unread,
Mar 23, 2012, 11:40:47 AM3/23/12
to valida...@googlegroups.com
Hi John,

Yes, I can see all those things would bite me on the bum with time!

My immediate reason is that the form I'm looking at is massive and I want to structure the form data by using a full-stop in the field name to get CF to create a structure out of the data. I can get the XML rules to support that but I think I'd have a game on to get property annotation to support it.

Richard
John


To unsubscribe from this group, send email to validatethis+unsubscribe@​googlegroups.com.

Richard Herbert

unread,
Mar 23, 2012, 11:41:45 AM3/23/12
to valida...@googlegroups.com
Ah yes, another very valid reason :-)

>>> >>>>> > validatethis+unsubscribe@​googlegroups.com.


>>> >>>>> > For more options, visit this group at
>>> >>>>> > http://groups.google.com/​group/validatethis?hl=en.
>>> >>>>>
>>> >>>>> --
>>> >>>>> Bob Silverberg
>>> >>>>> www.silverwareconsulting.com
>>> >>>
>>> >>> --
>>> >>> You received this message because you are subscribed to the Google
>>> >>> Groups
>>> >>> "ValidateThis" group.
>>> >>> To view this discussion on the web visit
>>> >>> https://groups.google.com/d/​msg/validatethis/-/​kKVsXFoHR94J.
>>> >>>
>>> >>> To post to this group, send email to valida...@googlegroups.com.
>>> >>> To unsubscribe from this group, send email to

>>> >>> validatethis+unsubscribe@​googlegroups.com.


>>> >>> For more options, visit this group at
>>> >>> http://groups.google.com/​group/validatethis?hl=en.
>>> >>
>>> >>
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> > Groups
>>> > "ValidateThis" group.
>>> > To view this discussion on the web visit
>>> > https://groups.google.com/d/​msg/validatethis/-/​fT0UbcCHjoYJ.
>>>
>>> >
>>> > To post to this group, send email to valida...@googlegroups.com.
>>> > To unsubscribe from this group, send email to

>>> > validatethis+unsubscribe@​googlegroups.com.


>>> > For more options, visit this group at
>>> > http://groups.google.com/​group/validatethis?hl=en.
>>>
>>> --
>>> Bob Silverberg
>>> www.silverwareconsulting.com
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "ValidateThis" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/​msg/validatethis/-/​F0u1mTWxmIMJ.
>>
>> To post to this group, send email to valida...@googlegroups.com.
>> To unsubscribe from this group, send email to

>> validatethis+unsubscribe@​googlegroups.com.


>> For more options, visit this group at
>> http://groups.google.com/​group/validatethis?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "ValidateThis" group.
> To post to this group, send email to valida...@googlegroups.com.
> To unsubscribe from this group, send email to

> validatethis+unsubscribe@​googlegroups.com.


> For more options, visit this group at
> http://groups.google.com/​group/validatethis?hl=en.

--
Bob Silverberg
www.silverwareconsulting.com

John Whish

unread,
Mar 23, 2012, 11:46:16 AM3/23/12
to valida...@googlegroups.com
That wasn't on my list as I never have bugs....

Matt Quackenbush

unread,
Mar 23, 2012, 11:55:22 AM3/23/12
to valida...@googlegroups.com
:-)

WINNER: Best Reply, 2012 Q1


--
You received this message because you are subscribed to the Google Groups "ValidateThis" group.
To post to this group, send email to valida...@googlegroups.com.
To unsubscribe from this group, send email to validatethis...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages