I'm migrating my Struts 1 app to Struts 2. In my Struts 2 app, I have an interceptor class that is meant to validate my error fields. It has this method to add action errors ...
There's already validation and workflow interceptors--are you using your own?
Dave Alvarado
Ranch Hand
Joined: Jul 02, 2008
Posts: 434
posted
0
Yes, I created my own because I have to validate the field using a custom algorithm. Here is what I have in my struts.xml file, but certainly let me know the correct way to do this if this is not it ...
Really, though, there's no reason to do that via a custom interceptor--you can write your own validators and plug them in to the existing system or use the validation logic in an action's validate() method where it'll work along with the existing framework validators. I don't know your needs, of course, but I have yet to encounter a situation where I had to write an interceptor just to do custom validation.
Dave Alvarado
Ranch Hand
Joined: Jul 02, 2008
Posts: 434
posted
0
Actually I want to try the way you suggested, but was curious ... do you mean adding a "validate" method to the action class with a String return type?
No, I mean adding a void validate() method to the action class, which is the signature expected by the interface.
If it's application-wide validation it'd be cleaner to create a validator.
Dave Alvarado
Ranch Hand
Joined: Jul 02, 2008
Posts: 434
posted
0
To put some closure to this thread, Im using s:actionerror, per David's suggestion ...
Thing is, I only want to display the above if there are action errors. If not, I would prefer that none of the above HTML be visible. How do I do this?