The data collection provided is not recognized.

2 views
Skip to first unread message

Sir Rawlins

unread,
Apr 20, 2009, 12:15:13 PM4/20/09
to Validat
Hello Guys,

Back implementing Validat for the first time in a while, working with
MG:G and Transfer. I'm currently using CS and Brian Koteks wonderful
beanutils package to autowire a validate instance into my transfer
decorators, and then trying to validate the objects from within
themselves like so:

<!--- I validate the objects properties. --->
<cffunction name="validate" access="public" returntype="any"
output="false" hint="I validate the bean.">

<!--- Create A Temporary Local Structure --->
<cfset var LOCAL = structNew() />

<!--- Validate the bean against validat --->
<cfset LOCAL.ErrorCollection = VARIABLES.Instance.Validat.validate
("company", THIS).getErrors() />

<!--- Return the error collection --->
<cfreturn LOCAL.ErrorCollection />
</cffunction>

I'm sure I've used this method in the past without any woes, however
when running this code now I get the following exception thrown by
validat.

"validat: The data collection provided is not recognized. In order to
validate this data collection, you must provide an object that follows
the transformer interface and register that transformer object with
the data set."

Now this seems weird as I was sure Validat was able to transform
objects into structures it can validate, however it seems to be
struggling with this method.

Can anyone shed any light on the situation?

Thanks,

Rob

Dennis Clark

unread,
Apr 20, 2009, 12:43:38 PM4/20/09
to val...@googlegroups.com
Interesting. I didn't know about Validat transformers and how they worked until I looked at the source to check out your problem. It's given me an idea to write a transformer for Model-Glue's event content in my copious spare time.

Looking at your error message and the Validat source, it appears that Validat is not automatically detecting that your CFC is a bean for some reason. Try forcing it to use the bean transformer like this:

<dataSet name="myBean" transformer="transformBean">
   ...
</dataSet>

Let us know how that goes.

-- Dennis

Jeff Chastain

unread,
Apr 20, 2009, 12:44:23 PM4/20/09
to val...@googlegroups.com
The out-of-the-box object transformer will look at the meta data for the
object passed in and call any methods starting with the word 'get',
collecting the data returned into a structure and then validating that
structure as a data collection.

Is it possible that your 'this' object does not contain any getter functions
or possibly those functions are expecting arguments that are not being
passed in?

-- Jeff

Sir Rawlins

unread,
Apr 20, 2009, 12:57:26 PM4/20/09
to Validat
@Denis, I think you were correct for the first part of the problem, by
explicitly defining that its an objects seems to stop it throwing the
exception. :-)

However.....

@ Jeff, you seem to have hit the nail with the next problem, it now
seems that my object fails validation on every attempt because the
properties are not defined. I have to explicitly define a getFoo()
method in the bean for Validat to be able to help, this obviously
negates some of the lovely benefits for using Transfer, My Decorator
looks like this at the moment.

<cfcomponent displayname="company" output="false"
extends="transfer.com.TransferDecorator">

<cfproperty name="Company_ID" type="string" default="" />
<cfproperty name="Name" type="string" default="" />
<cfproperty name="Created" type="date" default="" />
<cfproperty name="Modified" type="date" default="" />

<!--- Set the validate data validation engine into this bean. --->
<cffunction name="setValidat" access="public" output="false"
returntype="void" hint="I set the validat data validation engine into
this bean.">
<cfargument name="Validat" required="true" type="validat.validat"
hint="I'm the validat data validation engine." />

<!--- Set the validt property --->
<cfset VARIABLES.Instance.Validat = ARGUMENTS.Validat />

<!--- Return Void --->
<cfreturn />
</cffunction>

<!--- I validate the objects properties. --->
<cffunction name="validate" access="public" returntype="any"
output="false" hint="I validate the bean.">

<!--- Create A Temporary Local Structure --->
<cfset var LOCAL = structNew() />

<!--- Validate the bean against validat --->
<cfset LOCAL.ErrorCollection = VARIABLES.Instance.Validat.validate
("company", THIS).getErrors() />

<!--- Return the error collection --->
<cfreturn LOCAL.ErrorCollection />
</cffunction>

</cfcomponent>

Can you think of any reason why the properties would'nt be visible to
validat? after all the decorator wraps the transfer object which has
the getter methods, I'm guessing they're not exposed to Validat in the
way which is needed.

This could be a bit of a bugger.

Rob

Jeff Chastain

unread,
Apr 20, 2009, 1:01:17 PM4/20/09
to val...@googlegroups.com
Rob,

That was just the way the default object transformer was written - to fit a
generically designed bean. You can easily write a transformer that would
work with a transfer object and use it the same way as the bean transformer.
The whole point of a transformer is to take a data collection is a given
form (an object) and pull all of the required properties/values into a
struct which can then be validated as a data collection.

Take a look at the default object transformer and you should find that it is
pretty basic and would be easy to duplicate.

Sir Rawlins

unread,
Apr 21, 2009, 4:05:13 AM4/21/09
to Validat
Morning Jeff,

I've managed to solve the problem for now. I didn't opt to write my
own transformer in the end, although I may venture to do so in the
future. I found a blog article by Bob Silverburg which explained the
best way to obtain a structure of properties from a transfer object:

http://www.silverwareconsulting.com/index.cfm/2008/6/17/Using-Transfer-Metadata-to-Create-a-Memento

I've not implemented this method into my decorators, and made a slight
modification to the validate method:

<!--- I validate the objects properties. --->
<cffunction name="validate" access="public" returntype="any"
output="false" hint="I validate the bean.">

<!--- Create A Temporary Local Structure --->
<cfset var LOCAL = structNew() />

<cfset LOCAL.DataCollection = structNew() />
<cfset copyToStruct(LOCAL.DataCollection) />

<!--- Validate the bean against validat --->
<cfset LOCAL.ErrorCollection = VARIABLES.Instance.Validat.validate
("company", LOCAL.DataCollection).getErrors() />

<!--- Return the error collection --->
<cfreturn LOCAL.ErrorCollection />
</cffunction>

This can now use the standard struct transformer to prepare the data
for validation and seems to work very nicely!!!! Thanks for your
pointers, you helped me understand the route of the issue.

Rob
Reply all
Reply to author
Forward
0 new messages