Does this struct show the validation rule that you defined in
studyInfo.xml? If so then we know that the framework is picking up
your file.
> however....
>
> when I call getValidationScript() method, it returns an empty string,
> i was hoping to see some client code for validating my 1 field created
> in studyInfo.xml
>
Right, you should get that.
> Similarly, I get nothing returned when I try to validate an empty
> Transfer object of this type, i was hoping to see something again
> relating to my one rule.
>
Again correct - if the data in your object would cause the rule that
you defined to fail, then the Result object returned from validate()
should include a failure message to that extent.
> I thought maybe the this due to my Transfer object name, I have tried
> creating a "studyInfo.studyInfo.xml" rules file, but this does not
> return even a contexts struct.
>
As you're using the ValidateThis Facade object (ValidateThis.cfc) the
name of your Transfer object is irrelevant. There is another way of
using VT, where you bake it right into your objects, and that _can_
rely on the object name, but that's not what you're attempting here,
so let's not worry about the object name.
> That's where I am at the moment, any help would be gratefully
> appreciated.
>
> In terms of server-side validation, I am assuming I can do something
> like :
> - newStudyInfoObj = transfer.new('studyInfo.studyInfo');
> - newStudyInfoObj .setProperty1(xxx); newStudyInfoObj .setProperty2
> (yyy); etc etc and then call
> - application.validateThis.validate(objectType="studyInfo",
> theObject=newStudyInfoObj) which would return to me appropriate
> validation issues
>
> Is this correct usage?
>
Yes, that's correct.
> Many thanks, I hope I haven't left out any important info, Tarek.
>
Just a bit ;-)
Could you please show me the contents of the studyInfo.xml file? And
the code where you're calling the validate() and getValidationScript()
methods?
Also, can you confirm that you're running on CF8.0.1? That's a
requirement for the framework to function.
Cheers,
Bob
--
Bob Silverberg
www.silverwareconsulting.com
No problem. That's what I'm here for.
> here's my very brief validation code :
>
> <contexts>
> <context name="newStudy" formName="studySummaryForm" />
> <context name="editStudy" formName="frmProfile" />
> </contexts>
> <objectProperties>
> <property name="studyCategory" desc="Study Category">
> <rule type="required" contexts="newStudy" />
> </property>
> </objectProperties>
>
OK, so you're defining one rule, and you've assigned it to a context,
namely "newStudy". That's part of the issue.
> the code t I am running to test this (as a proof of concept) is something
> like :
>
> <cfset st = application.objManager.transfer.new('studyInfo.studyInfo')>
> <cfdump var="ID=#st.getStudyID()#"> ----> (returns nothing as expected)
>
> <cfdump label="getAllContexts"
> var="#application.validateThis.getAllContexts(objectType='studyInfo')#"> :
> this does return struct with the validation rules as defined above. All good
> so far.....
>
>
> <cfdump
> var="#application.validateThis.getValidationScript(objectType='studyInfo')#">
> this returns ""
>
> <cfset result = application.validateThis.validate(objectType="studyInfo",
> theObject=st) />
> <cfdump var="#result.getFailures()#"> ----> this again returns an empty
> array
>
Right. The problem is that your calls to both getValidationScript()
and validate() are not passing the context as an argument. Because
the rule you have defined is assigned to the "newStudy" context, you
have to tell VT that you want it to use that context for those method
calls. So if you change your test code to:
<cfdump var="#application.validateThis.getValidationScript(objectType='studyInfo',context='newStudy')#">
<cfset result =
application.validateThis.validate(objectType="studyInfo",
theObject=st, context='newStudy') />
<cfdump var="#result.getFailures()#">
I think you'll find that it works.
When you assign a rule to a context that that rule only exists within
that context. When you call getValidationScript() or validate()
without passing in a context you're asking VT to only look at those
rules that have no context assigned. There are a couple of ways to
have a rule appear in this "no context" context. You can simply leave
out the context attribute like so:
<property name="studyCategory" desc="Study Category">
<rule type="required" />
</property>
Or you can assign a context of '*', which means all contexts, like so:
<property name="studyCategory" desc="Study Category">
<rule type="required" contexts="*" />
</property>
Any rules defined in one of those two ways will be used when you call
getValidationScript() or validate() without passing in a context.
I hope that makes sense. Please let me know if it doesn't.
>
> once again thanks for your help on this.
>
> VT is exactly what I am looking for, Tarek.
>
I'm glad you find it useful,