In Struts 1.3.8 you have the possibility to define a central
exception handler using the
<global-exceptions>
element of file
struts-config.xml
. The central exception handler
class must implement the interface
org.apache.struts.action.ExceptionHandler
. This
works very well and has access to the causing UI component.
A template method for the execute
methods you need only, if you want to handle other action related
issues centrally, e.g. transaction management.
See an example at the Central Exception Reporting Sample Application, site http://excrep.berlios.de/
One student group even implemented centralized exception
reporting for form field related exceptions. In Struts it is
possible to saveErrors
or
saveMessages
indicating the name of the
offending field of the form working on. This will place the message
in the appropriately marked position in the form.
In the central exception handler for Struts you can
specifically handle exceptions, which are related to a form field.
E.g. a FieldvalueExc
could port the
identifier of the related field, so that
UiAction
could put the exception message into
the good position.
Another idea is to find the place in Struts, where any
exception occurring in a setXxx()
method of
a form bean can be caught and reported into the form near to the
field xxx
.