File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Javascript error in range validation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Struts
Reply Bookmark "Javascript error in range validation " Watch "Javascript error in range validation " New topic
Author

Javascript error in range validation

Lao Xu
Greenhorn

Joined: Apr 06, 2004
Posts: 12
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.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11945
Hi,

It would probably help if you'd post the full error message and some relevant code snippets (the validation config file).


Author of Test Driven (Manning Publications, 2007) [Blog] [HowToAskQuestionsOnJavaRanch]
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Lao Xu
Greenhorn

Joined: Apr 06, 2004
Posts: 12
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>
john guthrie
Ranch Hand

Joined: Aug 05, 2002
Posts: 124
what does your jsp look like? i don't think struts validation has anything to do with javascript...
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11945
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

Joined: Apr 06, 2004
Posts: 12
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

Joined: Apr 06, 2004
Posts: 12
Sorry, I meant

<field property="someNumber" depends="required, range">
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11945
Did you also try "intRange" as the argX name (instead of "range")?
Lao Xu
Greenhorn

Joined: Apr 06, 2004
Posts: 12
Nope, I tried "range"...
HockeyPlayer NewHampshire
Greenhorn

Joined: Jun 02, 2004
Posts: 3
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

Joined: Jan 23, 2002
Posts: 11945
"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!
 
jQuery in Action, 2nd edition
 
subject: Javascript error in range validation
 
Threads others viewed
Struts Validation using Struts Framework
Client side Javascript validation in JSF?
how we return error in javascript message box ?
Validator framework
Struts Validator FrameWork = JavaScript Error
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com