Server-side validation works fine for me, but I'm having a little trouble with client-side validation as follows:
Because lots of different web apps use the 'default' messages, I placed them in a separate file, ValidatorResources.properties:
errors.byte={0} must be a byte. errors.double={0} must be a double. (etc.)
My struts-config.xml file declares a second resource file: <message-resources parameter="torch.webapp.sandbox.ValidatorResources" null="false" key="VALIDATOR_BUNDLE"> </message-resources>
I reference the bundle when I display the error message associated with a validation error (on my jsp):
<html:text property="byteField" />
<html:errors property="byteField" bundle="VALIDATOR_BUNDLE"/>
And my validation.xml rule file contains a reference to the message:
<field property="byteField" depends="byte" > <arg0 key="validateForm.byteField.errorname"/> </field>
Finally, my ApplicationResources.property file lists the property:
validateForm.byteField.errorname=<span class='formErrorMessage'>Byte field</span>
(where class formErrorMessage is declared in a css file...)
WITHOUT client-side validation, if I enter an invalid value for the byte field,
I get a message like:
Byte field must be a byte.
Cool - everything works.
Now, when I turn on client-side validation, the fun begins. First, leaving everything alone except adding the <html:javascipt>:
<html:javascript formName="validateForm"/>
<html:form action="/validate" onsubmit="return validateValidateForm(this);">
I get the following popup with an invalid entry:
JavaScript: ???en_US.errors.byte???
and yes, inspecting the javascript function ByteValidations() reveals that it contains that exact string.
If I move the definitions for:
errors.byte={0} must be a byte
from ValidatorResources.properties to ApplicationResources.properties, (my default resource bundle) then I get the following popup:
JavaScript: <span class='formErrorMessage'>Byte field</span> must be a byte.
(in other words, it has displayed my stylesheet instead of using it to format, since the string is being displayed in a JavaScript dialog rather than as HTML).
In summary,
1. I don't seem to be able to pull in the resources into the JavaScript
when they come from something other than the default resource bundle,
and
2. I wanted to have nicer (like bold red) markup on the error messages
when only server-side validation is present (like the client turned off javascript),
but I get the explicit markup in the JavaScript dialog when client-side validation
is off.
Yes, I suppose I could include the ValidatorResources.properties messages
into every ApplicationResources.properties file and only have a single (default)
message bundle, and yes, I could have a plainer message, but I wondered if
anyone saw a problem with what I'd done or had a better solution.
TIA,
-jeff
BTW, one screw-up on my part that made me think validation wasn't working -
I initially declared my error messages with double quotes:
validateForm.byteField.errorname=<span class="formErrorMessage">Byte field</span>
and they got incorporated into the JavaScript inside double quotes:
"<span class="formErrorMessage">Byte field</span>"
and of course, I got absolutely nothing... good old JavaScript...