aspose file tools*
The moose likes Struts and the fly likes Not able to understand some javascript written in validator-rules.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Not able to understand some javascript written in validator-rules.xml" Watch "Not able to understand some javascript written in validator-rules.xml" New topic
Author

Not able to understand some javascript written in validator-rules.xml

Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Hi i am a beginner in struts.
I was going through a validator-rules.xml in a book & i found the following sampel file whcih defines javascript inside a javascript tag.I know it has been consolidated to commons-validator project since struts1.2 but i would like to understand the thing i have marked in BOLD and ITALICS in the following code.I am not able to understand the thing ??



Regards,
Jignesh

The Art Of Life Is To Know When To Be Useless And When To Be Useful - CHUANG TZU
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
Form may contain text,textarea,listbox,radio buttons,etc..But in our validation.xml we simply specify the form name,property name and validation types to be done.

While doing validation validator first want to check the type of field(say whether property belongs to text or radio button or textarea) and then type of validation is done.

In our case,Bolded area code first checks for field type,then validation type(mandatory field),checked on the basis of type of field.
Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Yes that i understood but i want to know what is this array about & what is oRequired .And what the form[oRequired[x][0]],form[oRequired[x][1]] contains??

And this for loop argument (x in oRequired) how it works???

var fields = new Array();
oRequired = new required();
for (x in oRequired)
{
var field = form[oRequired[x][0]];
....
}
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Look under the heading "FOR/IN" in this link for an explanation of how the for/in loop works.

As for the statement:

oRequired = new required();

In JavaScript, you can create a new object simply by defining a function and using the keyword new with that function. So, elsewhere in the code or in one of the includes, you will find a function required(). That function most likely defines properties, something like this:

function required() {
this.property1 = 'abc';
this.property2 = 'xyz';
this.property3 = new Array();
this.property3[0] = 'foo';
this.property3[1] = 'bar;';
}

The for/in loop simply iterates through the properties of the "required" object.

The code you are analyzing is expecting the properties of the "required" object to be arrays.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to understand some javascript written in validator-rules.xml
 
Similar Threads
Struts Validator Framework: problem with Custom Validator
Validation
Struts Validator FrameWork = JavaScript Error
Error 'required' is undefined
Problem with validator-rules.xml JavaScript