This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Javascript error in range validation  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm new to Struts. It's convenient Struts provides validation for integer, required, etc. But I've problem with the range validation in Struts 1.1. Javascript error. Saying something about "intRange" error in javascript. Any help apreciated.
 
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It would probably help if you'd post the full error message and some relevant code snippets (the validation config file).
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just wonder why the Struts validation will lead to JavaScript errors. As if you have configured Struts well, when errors encountered after calling the method validate(), the original page will be shown.

Could you post the validate() method, as well as the validate.xml?

Nick
 
Lao Xu
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I enter an invalid range and try to submit the form, the error uccur. The non-javascript error msg <html:errors/> shows the right error msg though.

The javascript error msg in IE:
'intRange' is undefined

The javascript error msg in Opera:
Event thread: onsubmit
Error:
name: ReferenceError
message: Statement on line 479: Reference to undefined variable: No such variable 'intRange'


I think it has something to do with the line "oRange = new intRange();" in validator-rules.xml


This is what I use in validation.xml

<form-validation>
<formset>
<form name="someForm">
<field property="someNumber" depends="required,integer,range">
<arg0 key="some.number"/>
<arg1 name="range" key="${var:min}" resource="false"/>
<arg2 name="range" key="${var:max}" resource="false"/>
<var>
<var-name>min</var-name>
<var-value>11</var-value>
</var>
<var>
<var-name>max</var-name>
<var-value>20</var-value>
</var>
</field>
</form>
</formset>
</form-validation>
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what does your jsp look like? i don't think struts validation has anything to do with javascript...
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by john guthrie:
what does your jsp look like? i don't think struts validation has anything to do with javascript...

The Struts Validator component can generate client-side validation functions in JavaScript as well as server-side validation methods.

Lao, try this in your validation.xml:
 
Lao Xu
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I've tried using

<field property="someNumber" depends="required, intRange">

But the error is still the same. Am I the only one experience this? Other validation, like "required, integer" don't have problem though.
 
Lao Xu
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I meant

<field property="someNumber" depends="required, range">
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you also try "intRange" as the argX name (instead of "range")?
 
Lao Xu
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope, I tried "range"...
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not once have I seen client side javascript validation work.

I see problems currently and I am actually anchored to the struts april 2003.

What hope do I have of using client side javascript validation with the april 2003 struts 1.1 release ?

Can someone post a working sample ?

It does not work.

Can someone post something please that works.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"HockeyPlayer NewHampshire",

Please take a look at our naming policy and proceed to My Profile for updating your display name accordingly.

Thanks, and welcome to the JavaRanch!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!