How to custom print actionErrors / fieldErrors with Velocity on Struts2


Just a quick code snippet, that couldn’t find anywhere on the net as an example and my colleague Aggelos offered to me 🙂

#if( $actionErrors.size() > 0 )
#foreach( $msg in $actionErrors )
[$msg]<br />

Same for fieldErrors. Use them instead of the default #sactionerror , #sfielderror etc to produce custom html. If you only need css formatting, override your css as described in the comments on this webpage. Of course, you can always override the default freemarker template for errors on the struts jar file, to provide uniform handling of error formatting