validatethis+transfer : blank validationScript returned, setup issue?

1 view
Skip to first unread message

tarekac

unread,
Sep 11, 2009, 10:17:27 AM9/11/09
to ValidateThis
Hi,

I'm just starting out with plugging in VT into my current fusebox/
Transfer configuration, I have the following setup within my app (just
1 object layed out here):

1. All object live within /cfc, so within /cfc/studyInfo I have
studyInfo.cfc, studyInfoGateway.cfc and studyInfoService.cfc - all
generated by Illudium code generator, cfc path =
cfc.studyInfo.studyInfo

2. In /cfc/studyInfo, I have also placed studyInfo.xml - rules
definition file which currently only contains one very simple required
rule on just one field/property of my object

3. I can create the validateThis facade object by calling :
validateThisConfig = {JSRoot="/poem/assets/js/", definitionPath="/
cfc/"};
application.validateThis = createObject
("component","ValidateThis.ValidateThis").init(validateThisConfig);

4. I can see the initializationscript text returned to me fine

5. I am also able to a results struct by calling :
application.validateThis.getAllContexts(objectType='studyInfo');

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

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.

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.

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?

Many thanks, I hope I haven't left out any important info, Tarek.

Bob Silverberg

unread,
Sep 11, 2009, 10:48:10 AM9/11/09
to valida...@googlegroups.com
On Fri, Sep 11, 2009 at 10:17 AM, tarekac <ta...@auniquedomainname.com> wrote:
>
> Hi,
>
> I'm just starting out with plugging in VT into my current fusebox/
> Transfer configuration, I have the following setup within my app (just
> 1 object layed out here):
>
> 1. All object live within /cfc, so within /cfc/studyInfo I have
> studyInfo.cfc, studyInfoGateway.cfc and studyInfoService.cfc - all
> generated by Illudium code generator, cfc path =
> cfc.studyInfo.studyInfo
>
> 2. In /cfc/studyInfo, I have also placed studyInfo.xml - rules
> definition file which currently only contains one very simple required
> rule on just one field/property of my object
>
> 3. I can create the validateThis facade object by calling :
>    validateThisConfig = {JSRoot="/poem/assets/js/", definitionPath="/
> cfc/"};
>    application.validateThis = createObject
> ("component","ValidateThis.ValidateThis").init(validateThisConfig);
>
> 4. I can see the initializationscript text returned to me fine
>
> 5. I am also able to a results struct by calling :
>    application.validateThis.getAllContexts(objectType='studyInfo');
>

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

Tarek Abou-Chanab

unread,
Sep 11, 2009, 5:20:44 PM9/11/09
to valida...@googlegroups.com
Hi Bob,

thanks for the swift reply, I really appreciate that.... I am running 8.01, 8.0 fails because of the onMissingMethod() omission.

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>


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


once again thanks for your help on this.

VT is exactly what I am looking for, Tarek.

Bob Silverberg

unread,
Sep 11, 2009, 8:16:56 PM9/11/09
to valida...@googlegroups.com
On Fri, Sep 11, 2009 at 5:20 PM, Tarek Abou-Chanab
<ta...@auniquedomainname.com> wrote:
> Hi Bob,
>
> thanks for the swift reply, I really appreciate that.... I am running 8.01,
> 8.0 fails because of the onMissingMethod() omission.
>

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,

Tarek Abou-Chanab

unread,
Sep 14, 2009, 5:10:54 AM9/14/09
to valida...@googlegroups.com
Hey Bob,

fantastic all works really well.

Lessons learned : always start with a basic example first, should have left out the contexts...

Thanks again, Tarek.

2009/9/12 Bob Silverberg <bob.sil...@gmail.com>



--
Is your website performing as it should?  Contact us for a no fee website evaluation.
----

Bob Silverberg

unread,
Sep 14, 2009, 8:04:08 AM9/14/09
to valida...@googlegroups.com
Glad to hear it.

To all: Sorry about the spam yesterday. Somehow someone got around
Google's "first post moderation" system. I have no idea how, and I
hope it doesn't become an ongoing problem.

Cheers,
Bob
--
Bob Silverberg
www.silverwareconsulting.com
Reply all
Reply to author
Forward
0 new messages