commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Chua" <oliverc...@softhome.net>
Subject [Validator] Javascript error when using validWhen
Date Tue, 12 Oct 2004 10:09:47 GMT
I have a select and a text field.
The validation is that the text field is required if the selected option
code is 'New'.
Below is an xml fragment of the declaration in validation.xml:

<field property="groupingName" depends="validwhen">
<arg0 key="Grouping Name" resource="false"/>
<arg1 key="${var:maxlength}" name="maxlength" resource="false"/>
 <var>
  <var-name>test</var-name>
                <var-value>((groupingCode!="New") or
(*this*!=null))</var-value>
        </var>

It produces a javascript function like this:
function AddUnitForm_maxlength () {
  this.a0 = new Array("groupingName", "Grouping Name can not be greater than
20 characters.",
  new Function ("varName", "this.maxlength='20';
  this.test='((groupingCode!="New") or (*this*!=null))';  return
this[varName];"));
}

Whether the part "New" is changed to 'New'(singel quotes), The Internet
Explorer javascript engine objects to it saying there should be a ; after
the quote.

The behavior in Internet Explorer is like this:
After entering invalid values, a popup window will appear.
After clicking Ok, there will be a javascript error and the page will be
submitted.
(This shouldn't be the case if javascript is on since the whole point of
javascript validation is to reduce roundtrips.)
Since the page has errors, the html:errors will be displayed.

I tried escaping String, like so:
 <var-value>((groupingCode!=\'New\') or (*this*!=null))</var-value>
but it turned out to become:
 this.test='((groupingCode!=\\'New\\') or (*this*!=null))';
and still causes errors during validation.

The Validator section of the Struts documentation says String literals in
single or double quotes
are legal values in the expression. Is this somehow a limitation og the
validwhen tag?
As I haven't been able to find an example of comparing fields with literal
Strings in the
, I have no idea if there is a workaround for this.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message