Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

p:message change text of message

Tags:

jsf

primefaces

I created a form with an which is mapped to MyBean.beansField. I used the javax.validation.NotNull anotation to make sure it has to be entered. Everything works fine so far but the error message looks like:

beansField: can not be null.

Whatever I tried so far I couldn't remove the "beansField: " in front of the message.

Can anyone please tell me where this prefix comes from and how I can get rid of it?

like image 214
monty Avatar asked Mar 07 '11 09:03

monty


2 Answers

If you want to check if user entered data, you could alternatively use the required attribute of an input field in combination with the requiredMessage field, e.g. for an inputField:

<h:inputText value="#{myBean.beansField}" required="true" requiredMessage="Can not be null"/>

If you want to overwrite messages in general you have to edit or overwrite the messages.properties file:

  1. Add this to your faces-config.xml inside the application element:
<locale-config><default-locale>en</default-locale></locale-config>
     <message-bundle>/resources/messages</message-bundle>
  1. Put a file called messages_en.properties in your resources folder
  2. Add messages you want to overwrite in this manner:

    javax.faces.component.UIInput.REQUIRED=Field ''{0}'' cannot be empty.

like image 182
Matt Handy Avatar answered Sep 19 '22 02:09

Matt Handy


add ValidationMessages.properties in your classpath (WEB-INF/classes or resources if using maven structue)

add

myapp.custommessage.notNull=your custom message

and annotate like

@NotNull(message="{myapp.custommessage.notNull}")
like image 37
jmj Avatar answered Sep 21 '22 02:09

jmj