I am building a Spring MVC web application that uses JSR-303 validation. With the first form I created, I added a couple of validation annotations (including custom error message codes) to the form backing bean. I also created ValidationMessages.properties and ValidationMessages_en.properties files.
Everything seems to be working correctly with one exception: multi-byte utf-8 encoded characters are not displayed correctly (e.g., "ñ" is displayed as "ñ").
This is not a problem with my standard messages.properties and messages_en.properties files that I use for field labels and other text, so I'm assuming it's an issue with the hibernate validator code. Has anyone else had this issue and solved it? FYI, I'm using Hibernate version 4.3.0.Final.
Thanks,
Peter
In my properties files I must include special characters like this:
\u00F3 instead of ó
In that way they are shown well.
Hope it helps.
P.S.: Using ResourceBundleEditor from Eclipse also helps.
Related
I configured my web application as indicated in https://www.baeldung.com/spring-boot-internationalization#localeresolver
with setting Locale.ITALIAN as default locale for LocaleResolver bean.
I have two message files:
message.properties with italian messages
message_en.properties with messages in english
However, labels defined in messages_en.properties, when exists. For example with setting locale via lang=es request parameter, messages in english are shown.
The expected behaviour, if I understand, should be that if lang=en, message_en.properties should be used, where as for all other languages messages in message.properties should be used.
Suggestions?
If you use the latest version of Spring Boot (2.5.3 at the moment), the tutorial isn't as up-to-date. For example, with the latest Spring you must do additional, but simple config to override LocaleResolver bean.
Depending of your implementation, you may need to add in the application.properties file the line spring.messages.fallback-to-system-locale=false or if you overridden the "messageSource" bean, you must set messageSource.setFallbackToSystemLocale(false); in your own bean.
This way the app should work as expected, with all languages except EN using message.properties.
I am new in Java EE and I am building a web application with maven, spring mvc
and hibernate.
I have a problem with the jsp. I can not show the data of object with the expression / jstl
language. In console doesn't show any error. Any suggestions?
Pom.xml:
Controller:
Inicio.jsp:
I guess in the controller you are setting the object with key
model.addObject("usuario", usuarioo);
The first character is small 'u'.
And in your jsp you are trying to access using Usuario. Thus the value is not getting printed.
Kindly use something like
${usuario.nombre}
I got this problem, that I got from my friend a annotation code that checks if input data is proper VIN number. Annotation works fine, however when number is wrong it should render a default message:
String message() default "{validator.nrVINBad}";
I dont't know where to put this message, I tried my *.properties files but it's not that. Everywhere I look, there's always instructions how to make message from *.properties files, but as I know now, you can't put in those files error messages.
This is not part of JSF. This is part of Bean Validation (BV, also known as "JSR303"). Both JSF and BV are part of Java EE. JSF just happens to have builtin recognition and delegation for BV.
To localize BV messages, just follow the instructions in chapter 4.3.1.1 of JSR303 specification. In a nutshell, create a ValidationMessages.properties file in the classpath root (there where your Java source code also is, so that it ultimately ends up in /WEB-INF/classes) with he following content:
validator.nrVINBad = Your message here
See also:
Internationalization in JSF, when to use message-bundle and resource-bundle?
I am building an application using spring mvc and jpa using jboss7 and mysql in eclipse ide. I am having a strange problem. All my jsp pages are encoded with charset: utf8, which I think is working correctly. But whenever I try to post a data from the jsp to the controller, my data gets encoded with a different encoding style. I tried to look for the header using firebug and was astonished to see that the post request has a header with content-type : "text/plain;charset=ISO-8859-1". I have already configured the SetCharacterEncodingFilter for UTF-8 in my web.xml (it is the first filter). But still the problem exists.
I also set "org.apache.catalina.connector.URI_ENCODING" to value="UTF-8".But in vain .
Also I have added bean messageSource with property defaultEncoding set to "UTF-8".
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource" >
The problem still exists. Please help
Thanks in advance.
The request header is set by the browser, so your application can't control it. Usually, in your HTML form you could put an accept-charset=utf-8 attribute to specify the encoding, but that doesn't necessarily work. See this question Setting the character encoding in form submit for Internet Explorer.
you should need to set the encoding of the JVM like follow :
-Dfile.encoding=UTF-8 -Dfile.io.encoding=UTF-8 -DjavaEncoding=UTF-8
thus there wont be any doubt at all.
We're trying to use Struts 2 Validation w/ Annotations and we've ran into a weird problem. We have a method that we have specified a string validation for. When we run that method we get a NullException in the AnnotationValidationConfigurationBuilder on line 580. We took a look and it appears that the validationFactory is null. We traced that back and can't find a reason why it would be null though we did notice an #Inject annotation on the setValidatorFactory.
As a side note we're also using Spring 2 in the mix and calling it from the jQuery plugin.
Has anyone run into this before? We've looked at all the docs and none of them talk about needing to register a bean with Spring or anything like that.
Thanks,
Shane
We found the answer. Apparently if you have a validators.xml you need to specify everything in the base validators.xml. This has changed since we used this in the past without needing to do this.