Programming Thoughts
Struts 2 - Annotation-based Validation
Redesign Example
Actually reducing Struts 2's arcane configuration
Struts 2 is a popular MVC framework for Java-based web applications but its annotation-based validation doesn't properly work. So, an alternative was created. This article describes a working example.
Live example
A demonstration application can be accessed here. The start page looks like the following. It tests various policies in various conversion modes. If a form is rejected, the values are redisplayed. If successful, a message displays the converted values and the form reset.

Figure 1: Starting page
Download
Source code of annotation-based validation as a library can be downloaded here and a demonstration application can be downloaded here as zip files. They require the following.
- JDK 8 or better
- Maven 3
- Jakarta EE server, such as Tomcat 9
First, extract the Struts Commons files and run mvn
, which will install
name.matthewgreet/struts-commons-1.6.0.jar in your local repository. Then extract the Example 9 files and
run mvn
, which compiles into example9.war. Copy that into your Jakarta server run the
/example9
URL.
Next part
Continued in Form Formatting Redesign.