Wednesday, July 12, 2006

ResourceBundle bungle

Updated 7/13: used google pages as my online wysiwyg to generate valid html for xml files

We use SpringMVC and use the built-in validator support. I had a problem parsing in a parameter for an error message.

my applicationcontext contained:

<bean id="messageSource" class=""> <property name="basename"> <value>app</value> </property> </bean>

the line in my resource bundle,, was:
error_key=What's up, {0}?
the validator call was:
errors.reject(errorcode, new Object[] {"doc"}, defaultMessage);

My jspx file looked like this:

      <spring:hasbinderrors name="mycommand">
          <div class="error">
              <c:foreach var="error" items="${errors.allErrors}">
                  <li><spring:message arguments="${error.arguments}" code="${error.code}"></spring:message></li>

I expected this to show up in my final output: What's up, doc? Instead, the parameter was never parsed in. It only displayed: What's up, {0}?

Like always, the answer was found in the javadocs. The parameter binding is backed by java.text.MessageFormat and what happens is that a single quote, ' , stops any binding. So to solve the problem, use two quotes '' to represent a single quote.

No comments: