|
From: Daniel M. <mi...@pa...> - 2004-04-15 04:41:18
|
Karl,
Good point. That is a problem with the createMessage() function. I took your
suggestion and removed all of the "???" delimiters from the default
messages. I also changed the implementation of the getArgs() function to
observe the resource="false" so the argument fields will not try to resolve
a message when resource="false" is specified.
Oddly enough, the implementation of the Msg class in the Commons-Validator
(from what I can tell) totally ignores the resource="false" attribute in the
<msg> tag. Consequently, there is no way to detect if the message associated
with a Field is actually a message resource or a literal value. On the
brighter side, I don't know how I would implement this differently anyway.
It doesn't look like there is a way to invoke the Spring
Errors.rejectValue() function without an "errorCode" parameter (although it
may be possible to mangle the errorCode parameter in some way to ensure that
a message resource would never be resolved, but that sounds a bit too
hackish to me). The only possible disadvantage here is the possibility that
a message resource with a key that matches the literal message to be
displayed would override the value. For example the following configuration:
messages.properties
Required=Value
validation.xml
...
<msg name="required" key="Required" resource="false" />
...
would render the message as "Value" even if you wanted it to be "Required"
because the "Required" property in the messages.properties file would
override the literal value. Luckily this will not be a problem most of the
time because most message resources use a naming convention that is not very
user friendly and therefore most likely would not overlap with the actual
error messages that you would want to show to a user.
I have attached the updated Resources.java file. Let me know if it doesn't
solve the problem.
Thanks,
Daniel
P.S.
You can feel free to send any questions you have directly to the Dev list
and just CC me.
P.P.S.
Keith, please replace the old resources file with this new one. Thanks.
-----Original Message-----
From: Baum, Karl [mailto:Kar...@Ta...]
Sent: Tuesday, April 13, 2004 8:31 PM
To: 'Daniel Miller'
Subject: default error message
Hi Daniel. I am having some trouble displaying a string literal error
message. Basically I am supplying the error message from the formset
element and not using the message resource bundle. My msg element looks
like:
<msg name="validwhen" key="Are you currently working in the aquisition
field?" resource="false"/>
The error message when displayed however looks like:
???Are you currently working in the aquisition field????
I think the "???" are getting appended in the class
org.springframework.validation.commons.Resources in the method:
public static MessageSourceResolvable createMessage(Object obj) {
String[] codes = new String[] { String.valueOf(obj) };
String defaultMsg = "???" + codes[0] + "???";
MessageSourceResolvable msg =
new DefaultMessageSourceResolvable(codes, null,
defaultMsg);
return msg;
}
I think these "???" can be removed but I am unsure. Thanks aging for your
help. Talk to you soon.
Karl Baum
Work (212) 213-5199 X3408
Cell (917) 439-1791
|