Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Struts and the fly likes Validation in struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation in struts 2" Watch "Validation in struts 2" New topic

Validation in struts 2

pallavi bawa

Joined: May 22, 2014
Posts: 1

In struts2, I want to validate address 1 input value on 4 different pages. I dont want to copy the regex in 4 different action_name-validation.xml. Can I create a global validation.xml where I can define a variable and is use it in other action_name-validation.xml files? Please provide an example.
Joe Ess

Joined: Oct 29, 2001
Posts: 9069

Welcome to the JavaRanch.
The best solution would be to create your own validator and use it in your XML files where necessary. Here is a tutorial but I've never done this myself, so I can't speak to how good the tutorial is.
Personally, when I have to do anything more complex than a make sure a required field is filled in, I use the Validateable interface (built in to ActionSupport) and do the validation programmatically.

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: Validation in struts 2