I'm using validation-api to validate if input field doesn't contain illegal characters: < > ' " etc. I'm using @Pattern annotation with custom message translated to something like this: The following signs < > " ' „ are not allowed. When this message is printed the single quote char is missing. I have: The following signs < > " „ are not allowed.
I've tried using \' and \u0027 and ' in the message.properties but with no success (in third case in the message there is fragment '). Messages are displayed using:
<p class="error" th:if="${#fields.hasErrors('company.name')}" th:errors="${company.name}">error</p>
Thymeleaf version: 2.1.3.RELEASE
Spring version: 3.2.8.RELEASE
Spring webflow version: 2.4.0.RELEASE
I don't know much about Thymeleaft. But be aware that you might need to escape single quotes (with two single quotes ('')) if you retrieve the message using MessageFormat and ResourceBundle.
If you are using Spring's ResourceBundleMessageSource (which uses ResourceBundle and MessageFormat internally) you have to do the same thing.
See MessageFormat javadoc:
Within a String, a pair of single quotes can be used to quote any arbitrary characters except single quotes. For example, pattern string "'{0}'" represents string "{0}", not a FormatElement. A single quote itself must be represented by doubled single quotes '' throughout a String. For example, pattern string "'{''}'" is interpreted as a sequence of '{ (start of quoting and a left curly brace), '' (a single quote), and }' (a right curly brace and end of quoting), not '{' and '}' (quoted left and right curly braces): representing string "{'}", not "{}".
Some time ago I wrote a blog post that provides some more details about exactly this topic: Single quote escaping with Java resource bundles
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With