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?
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:
<locale-config><default-locale>en</default-locale></locale-config> <message-bundle>/resources/messages</message-bundle>
Add messages you want to overwrite in this manner:
javax.faces.component.UIInput.REQUIRED=Field ''{0}'' cannot be empty.
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}")
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