Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Build Status

This plugin is now part of official Struts2 release and no longer being maintained independently. Please refer to bean-validation-plugin for more detail


JSR-303 standardizes validation constraint declaration and metadata for the Java platform. Using this API, you annotate domain model properties with declarative validation constraints and the runtime enforces them. There are a number of built-in constraints you can take advantage of. You may also define your own custom constraints.

To illustrate, consider a simple PersonForm model with two properties:

public class PersonForm {
    private String name;
    private int age;

JSR-303 allows you to define declarative validation constraints against such properties.

public class PersonForm {

    private String name;

    private int age;


When an instance of this class is validated by a JSR-303 Validator, these constraints will be enforced.

A JSR-303 Bean Validation Plguin for Struts2. This Plugin works as a bridge between Struts2 request flow and JSR-303 Compliant bean Validator like Hibernate Validator.

This plugin itself do not provide JSR-303 Specific validationn but will use underlying validator to perform bean validation.

For general information on JSR-303, see the Bean Validation Specification. For information on the specific capabilities of the default reference implementation, see the Hibernate Validator documentation.

Bitdeli Badge

<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-12895099-2', 'github.com'); ga('send', 'pageview'); </script>


Getting Started

This tutorial will give you introduction as how to use Struts2-jsr303 validation plugin.I am assuming that person has basic understanding about bean Validation API and its specifications.

Step: Install

We need to install Struts2 JSR303 bean validation Plugin.You can either download plugin jar manually from download page and include reference implementation and validation-api version 1.0.0.GA from download validation-api 1.0.0 you can also use maven to take care of adding plugin to your Struts2 application.Add following to you pom.xml

Using Maven


Plugin as been tested with following reference implementations

  • Hibernate Validator
  • Apache BVal

However plugin will work with any reference implementations in accordance with bean validation 1.0 specifications.

How to use with Struts2

In order to use Plugin with struts2, all you need to extends your package with jsr303 and you are all set to use underling features of bean validation API like

 <package name="default" extends="jsr303">
    <default-interceptor-ref name="jsr303ValidationStack"/>
    // action mapping

Make sure to add Hibernate validator or Apache Bval in your Struts2 application.Plugin does not provide any validation itself but work as a bridge between Struts2 and Bean Validation API

Adding Bean validation API in your Application

Hibernate validator


Apache Bval validator


Plugin has been tested with 1.0 Specifications and not with 1.1, as Apache Bval 1.1 implementation is still under development.

Validation Error Messages

Plugin utilize Struts2 Message resolving algorithm. You can create action specific files or can create single file for entire application. You can even pass messages directly in the validation annotation.

@Size(min=10, max=10, message="mobile.number") private String mobile;

in above example mobile.number will work as key and plugin will search messages with given key in underlying resource bundles with help of Struts2. You can directly provide messages in validation constraints itself

@Size(min=10, max=10, message="Please provide a valid mobile number") private String mobile;

In case of no message, plugin will fall back to default messages provided by Validation API.

Configuring Provider Class

Plugin try to work and search in class path about Bean validator provider, but you can always provider your prefered Bean Validator by setting struts.jsr303.beanValidator.providerClass in struts.xml file or in property file

 <constant name="struts.jsr303.beanValidator.providerClass" value="org.hibernate.validator.HibernateValidator"/>

Please note that setting struts.jsr303.beanValidator.providerClass constant is not required,however in case you have multiple provider in your classpath and want your prefreed bean validator, you can always set it by struts.jsr303.beanValidator.providerClass constant in your struts.xml file.

For your convience, here is the list of provider.

Hibernate validator


Apache Bval validator


You can always look inside META-INF/services/javax.validation.spi.ValidationProvider.