xml file definition file not found exception

46 views
Skip to first unread message

Ram

unread,
Sep 15, 2014, 6:29:06 PM9/15/14
to valida...@googlegroups.com
I am new to ValidateThis.

I want to validate my form with validateThis framework 1.2. I  downloaded it into Cfwebroot and my project Person is in CFwwwroot/Person
I am working with framework one 2.5. I am using Windows7 and Coldfusion 11, NOT using ORM or other framework.

my form (persionadd.cfm) name is addPerson

i put the person.xml under model/config/

<?xml version="1.0" encoding="UTF-8"?>
<validateThis xsi:noNamespaceSchemaLocation="validateThis.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<objectProperties>
<property name="per_first_name">
<rule type="required" failureMessage="Please enter First name." />
</property>
<property name="per_last_name">
<rule type="required"  failureMessage="Please enter Last namet."/>
</property>
</objectProperties>
</validateThis>


In the controller
 
 component accessors=true { 
  property personService;
 
  function init(fw) {
variables.fw = fw;
return this;
  public function person(rc){

var ValidateThisConfig = {definitionPath="model/config/"};
 
  application.ValidateThis = createObject("component","ValidateThis.ValidateThis").init(ValidateThisConfig);
  var Result = application.ValidateThis.validate(rc,"person.xml");
//var Result = application.ValidateThis.validate(person);
writedump(Result);
  if (structKeyExists(rc,"addPerson")){
  variables.personService.savePerson( ); 
  }
  }
   }


I get the error like

Exceptions

12:30:33.033 - ValidateThis.core.externalFileReader.person.xml.definitionFileNotFound Exception - in C:/ColdFusion11/cfusion/wwwroot/ValidateThis/core/ExternalFileReader.cfc : line 100


I think it cannot read my xml file for validate() method. My question is what will be myObject that I pass to the validate() either as object or struct type.

I appreciate your help.
Thanks,
Ram

trojanfresh

unread,
Sep 16, 2014, 9:16:16 AM9/16/14
to valida...@googlegroups.com
what is your configuration file look like? 

trojanfresh

unread,
Sep 16, 2014, 9:18:09 AM9/16/14
to valida...@googlegroups.com
also not sure in your case but i never declare .xml 

i don't have the copy in front of my of my code but
var Result = application.ValidateThis.validate(objectType="person",theObject=rc,Context="SomeContext", locale="en_US");



On Monday, September 15, 2014 6:29:06 PM UTC-4, Ram wrote:

trojanfresh

unread,
Sep 16, 2014, 9:19:34 AM9/16/14
to valida...@googlegroups.com
sorry not declare but i never put the .xml at the end of the file. based on your config file you say either json or xml if you pick xml which i think you did then you don't need to put person.xml just person since it knows to look for xml files.

John Whish

unread,
Sep 16, 2014, 9:28:17 AM9/16/14
to valida...@googlegroups.com
You should be validating against the object or a struct.

So if you have a person object then you validate it like so:

ValidateThis.validate(person)

How ValidateThis finds your rules is documented here: 


If you want to specify a specific path to the rules then you can use the `definitionPath` config key

Cheers,

John




--
You received this message because you are subscribed to the Google Groups "ValidateThis" group.
To unsubscribe from this group and stop receiving emails from it, send an email to validatethis...@googlegroups.com.
To post to this group, send email to valida...@googlegroups.com.
Visit this group at http://groups.google.com/group/validatethis.
For more options, visit https://groups.google.com/d/optout.

Ram

unread,
Sep 16, 2014, 11:34:10 AM9/16/14
to valida...@googlegroups.com
Thanks everyone.

John,

if I say, var Result = application.ValidateThis.validate(person);

I get error like Variable PERSON is undefined.

In my controller, var ValidateThisConfig = {definitionPath="model/config/"}; 

tried like otherways  /model/config. 

All my validation code is in Controller, so I tried my person.xml.cfm file in under controllers.

 It is not able to find my person.xml. Is this 'person' my object? 

Here i am not creating any object. The method addPerson in the controller calls my person services.

 I tried like var ValidateThisConfig = {definitionPath="C:\ColdFusion11\cfusion\wwwroot\Person\model\config\"};

Do I need something like in the controllers?

variables.root = getDirectoryFromPath( CGI.SCRIPT_NAME ).replaceFirst( getContextRoot(), '' );

trojanfresh,

I changed my preson.xml file to person.xml.cfm.  where rules are there for required first name etc 

If I say

var Result = application.ValidateThis.validate(objectType="person",theObject=rc);

rc scope is availble in controller.

I don't get error but it is not validating my form if I don't enter first name. 

my application.cfc has

component extends="org.corfield.framework" accessors="true" {


this.name = "person";
this.datasource = "jis";
this.sessionmanagement = true;
this.clientManagement  = false;

variables.framework = {
action = "action",
usingSubsystems = false,
defaultSubsystem = 'home',
defaultSection = "personadd",
defaultItem = "personadd",
subsystemDelimiter = ':',
siteWideLayoutSubsystem = 'layouts',
error = "main.error",
reload = "reload",
password = "true",
trace = "true",
reloadApplicationOnEveryRequest = true
};
// setup (simple) bean factory:
function setupApplication() {
var bf = new framework.ioc( "model,model/config" );
setBeanFactory( bf );
}
}

trojanfresh

unread,
Sep 16, 2014, 11:46:54 AM9/16/14
to valida...@googlegroups.com
When you use this

var Result = application.ValidateThis.validate(objectType="person",theObject=rc);

make sure your person.xml and not .xml.cfm as i don't know if that would handle it.

For me my stock xml file is 

<?xml version="1.0" encoding="UTF-8"?>
<validateThis xsi:noNamespaceSchemaLocation="validateThis.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<conditions>
</conditions>
<contexts>
<context name="Content" formName="YOUR FORM VARIABLE" />
</contexts>
<objectProperties>
<property name="first_name" desc="first_name ID">
<rule type="required"  contexts="*">
</rule>
</property>
</objectProperties>
</validateThis>

try that

var Result = application.ValidateThis.validate(objectType="person",theObject=rc,Context="Content");

and cfdump result

and if it still doesn't work what is your RC structure like John said is it valid structure?

John Whish

unread,
Sep 16, 2014, 11:48:00 AM9/16/14
to valida...@googlegroups.com
Let me take a step back, so you are trying to validate the form struct?

Have a look at the form demo here - I think that should help you:

<cfset Result = application.ValidateThis.validate(objectType="User",theObject=form)>

Ram

unread,
Sep 16, 2014, 12:44:52 PM9/16/14
to valida...@googlegroups.com

I changed the person. xml adding context as your file. 

my cfdump and rc is attched.
person.docx

trojanfresh

unread,
Sep 16, 2014, 12:51:30 PM9/16/14
to valida...@googlegroups.com
I test Result like

<cfif Result.getIsSuccess()>

<cfelse>

</cfif>

Dean Lawrence

unread,
Sep 16, 2014, 2:26:58 PM9/16/14
to valida...@googlegroups.com
Ram,

Add the following to your Application.cfc's onApplicationStart() method:

public boolean function onApplicationStart() {
    var ValidateThisConfig = {definitionPath="/model/config/"};

    application.ValidateThis = createObject("component","ValidateThis.ValidateThis").init(ValidateThisConfig);

    return true;
}


The next thing to make sure of, is that the properties that you have rules for in your person.xml file match the name of the properties that you want to validate in your person.cfc file, not the form fields. In the sample person.xml file that you supplied, you are testing requiring "per_first_name"; is this the same name as the property in the person.cfc or is it just the name of the field on your form?

Once you have added the ValidateThis object in the application scope and have your person.xml file properly formatted, you then need to add it to your form processing page. Here are the steps that you would take:


  1. Create a new Person object.
  2. Set the Person object properties with the values submitted with the form.
  3. Pass the Person property to ValidateThis:
    Result = application.ValidateThis.validate(Person);
  4. Test the result:
    <cfif Result.getIsSuccess()>
        <!--- Person is valid, so save it --->
    <cfelse>
        <!--- Person is invalid, display warning messages --->
    </cfif>

Hopefully this will get you on the right path.


--
---------------------------------------------------------------------------
Dean M. Lawrence
INTERNET DATA TECHNOLOGY
p // 888.438.4381 ext. 701
w // www.idatatech.com
f // www.facebook.com/idatatech
t // www.twitter.com/idatatech

Social Marketing | SEO | Design | Internet Development

Ram

unread,
Sep 16, 2014, 6:48:25 PM9/16/14
to valida...@googlegroups.com
Thank a lot Dean!!!

I am on right path now. I did as you explained. It worked now after couple of days.

Though It is not finding the rules file from model/config but from controllers where I put the person.cfc and person.xml file.
In Application.cfc, setupApplication function I added like

Application.ValidateThisConfig = {definitionPath="controllers"};
Application.ValidateThis = createObject("component","ValidateThis.ValidateThis").init(Application.ValidateThisConfig); 

I appreciate your help.
Reply all
Reply to author
Forward
0 new messages