File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 9189

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
It's not a secret anymore!