Validate fields using property file and ResourceBundleMessageInterpolator

Posted: February 11, 2013 in web

xhtml

<p:inputText value="#{BBean.name}" />
<p:inputText value="#{BBean.email}" />

Backing Bean

...
@NotBlank(message = "{error.email.required}")
private String email;

@NotBlank(message = "{error.name.required}")
private String name;
....

MessageInterpolator.java

public class MessageInterpolator extends ResourceBundleMessageInterpolator {
    public MessageInterpolator() {
        super(new PlatformResourceBundleLocator("com.car.web.content"));
    }
}

Validation.xml (scr/main/resources/META-INF)

<validation-config
	xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.0.xsd">

	<message-interpolator>com.car.web.application.MessageInterpolator</message-interpolator>
</validation-config>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s