• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ??

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]];
....
}
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You firghten me terribly. I would like to go home now. Here, take this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic