Fórum

Bean validation using primefaces

Muhammad Azeem, modificado 8 Anos atrás.

Bean validation using primefaces

New Member Postagens: 16 Data de Entrada: 14/01/15 Postagens Recentes
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, modificado 8 Anos atrás.

RE: Bean validation using primefaces

Liferay Legend Postagens: 1302 Data de Entrada: 24/06/09 Postagens Recentes
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, modificado 8 Anos atrás.

RE: Bean validation using primefaces

New Member Postagens: 16 Data de Entrada: 14/01/15 Postagens Recentes
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, modificado 8 Anos atrás.

RE: Bean validation using primefaces (Resposta)

New Member Postagens: 16 Data de Entrada: 14/01/15 Postagens Recentes
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, modificado 8 Anos atrás.

RE: Bean validation using primefaces

Expert Postagens: 315 Data de Entrada: 14/01/13 Postagens Recentes
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