留言板

Bean validation using primefaces

Muhammad Azeem,修改在8 年前。

Bean validation using primefaces

New Member 帖子: 16 加入日期: 15-1-14 最近的帖子
hi,
I am using hibernate validator with my bean as below

@NotEmpty
@Length(min=1,max=5)
private String myName;


Validation is working fine and default message is displayed. I need to provide custom messages based on my requirements, as I understand it can be provided in message attribute of the annotation but is it possible to use a key from language.properties for message e.g.
@NotEmpty(message="{my.test.err.msg}")
@Length(min=1,max=5)
private String myName;


where my.test.err.msg is defined in language.properties. I tried above code but it is not working and {my.test.err.msg} is displayed instead of error message.
thumbnail
Ravi Kumar Gupta,修改在8 年前。

RE: Bean validation using primefaces

Liferay Legend 帖子: 1302 加入日期: 09-6-24 最近的帖子
I am not familiar with primefaces but if you're showing this in jsp or some file like that, try using
<liferay-ui:message key="my.test.err.msg" />
Muhammad Azeem,修改在8 年前。

RE: Bean validation using primefaces

New Member 帖子: 16 加入日期: 15-1-14 最近的帖子
hi Ravi,
Thanks for your reply. Actually I am trying to use the property in java file. I figured it out that hibernate validator getting these values from ValidationMessages.properties file. I have defined the key in this file and message is displayed properly. Now hibernate validator also supports localization so I have created ValidationMessages_ar_SA.properties or ValidationMessages_ar.properties files in the classpath (as I have to display messages in Arabic if current locale is changed).

Here I am getting garbage characters. I have changed the properties file format to UTF8 but I believe hibernate is not picking up messages from my localized property file (as I also tried to give simple message in English).
For clarification I am attaching screenshot where one error message (@Length) does not have any custom key so it is displaying default message in English. For (@NotEmpty) I have defined a key from property file (as mentioned in my first post) but the message is not displayed correctly.



I am still struggling with it and will update if I found any solution.
Muhammad Azeem,修改在8 年前。

RE: Bean validation using primefaces (答复)

New Member 帖子: 16 加入日期: 15-1-14 最近的帖子
I have resolved the issue after defining my Arabic string in Ascii (Unicode Escaped) characters. I converted my arabic (UTF8) string to ascii from
http://www.rapidmonkey.com/unicodeconverter/
and it is working fine.
thumbnail
Vernon Singleton,修改在8 年前。

RE: Bean validation using primefaces

Expert 帖子: 315 加入日期: 13-1-14 最近的帖子
Hello Muhammed,

I just wanted to thank you for posting your solution to this above. Your solution was similar to the solution that I was going to suggest, but you posted it first. Many other folks benefit from your participation here in the forums, so, again, thank you.

- Vernon