You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jeff Kyser <kt...@comcast.net> on 2003/08/14 03:15:10 UTC
message resource bundles and client-side validation
Hey all,
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...
Re: message resource bundles and client-side validation
Posted by Jeff Kyser <kt...@comcast.net>.
Hey Steve,
Thanks for the response - I can certainly live with incorporating
the default error messages in my main app resource bundle until
the enhancement is available, and will switch to the use of the
errors.prefix/suffix.
thanks again!
-jeff
On Thursday, August 14, 2003, at 12:25 AM, Steve Raeburn wrote:
> Thanks for the clear and detailed description of your problem. You're
> not
> doing anything wrong, this is something that is not currently
> supported by
> the <html:javascript> tag which doesn't have a bundle attribute to
> enable
> you to select a custom bundle.
>
> There is a bug report relating to this
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=19396. (This bug has
> been
> closed in favour of a more general I18N enhancement request.)
>
> The plan is to move to commons-resources soon so that may be the best
> time
> to add the enhancement but I'll take a look to see if this can be
> added now.
>
> To add colour to your error messages, use errors.prefix and
> errors.suffix,
> e.g.:
> errors.prefix=<span style="color: #f00;">
> errors.suffix=</span>
>
> That way you don't include mark-up in your error messages.
>
> Steve
>
>> -----Original Message-----
>> From: Jeff Kyser [mailto:ktrails@comcast.net]
>> Sent: August 13, 2003 6:15 PM
>> To: struts-user@jakarta.apache.org
>> Subject: message resource bundles and client-side validation
>>
>>
>> Hey all,
>>
>> 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...
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: message resource bundles and client-side validation
Posted by Steve Raeburn <sr...@apache.org>.
Thanks for the clear and detailed description of your problem. You're not
doing anything wrong, this is something that is not currently supported by
the <html:javascript> tag which doesn't have a bundle attribute to enable
you to select a custom bundle.
There is a bug report relating to this
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=19396. (This bug has been
closed in favour of a more general I18N enhancement request.)
The plan is to move to commons-resources soon so that may be the best time
to add the enhancement but I'll take a look to see if this can be added now.
To add colour to your error messages, use errors.prefix and errors.suffix,
e.g.:
errors.prefix=<span style="color: #f00;">
errors.suffix=</span>
That way you don't include mark-up in your error messages.
Steve
> -----Original Message-----
> From: Jeff Kyser [mailto:ktrails@comcast.net]
> Sent: August 13, 2003 6:15 PM
> To: struts-user@jakarta.apache.org
> Subject: message resource bundles and client-side validation
>
>
> Hey all,
>
> 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...
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org