I've got two questions, here's the summary:
I'm doing validation in my domain objects. They kick back a map..
public class DomainObject {
public Map<String, String> validate() {...}
}
In my action's validate method, I just delegate to the domain object's
validate() method. Something like this...
public void validate() {
// Delegate validation
Map<String, String> errs = new LinkedHashMap<String, String>();
errs.putAll(account.validate());
errs.putAll(postalAddress.validate());
setFieldErrors(errs);
}
Here's my question...
As you can see from the above, when I get my errs Map back from my
domain object (it will always be non-null) I've just been replacing the
Action's field error map with my own...
setFieldErrors(errs);
It's working now but it seems like blasting the existing Action's
internal fieldErrors map with my own seems to be asking for trouble.
This option is compelling...
public void validate() {
getFieldErrors().putAll(account.validate())
getFieldErrors().putAll(postalAddress.validate())
}
But I have two problems with that. It assumes the internal fieldErrors
map will never be null (is that true?) and it also emits a warning (in
Eclipse) because the the internal FieldErrors map has not be genericized
(and my domain objects Map has). I could code around both of those, of
course, but then it's verbose enough to be not so compelling anymore.
Another option is to loop over error map generated by my domain object
and then add each of those to the Action's FieldError map via
addFieldError(). That seems the safest, presumably the addFieldError
method is doing null checks, new map setup if necessary, etc. But,
dang, that's a lot of code just to transfer some strings around.
Comments?
- Gary
P.S. My Action is extending ActionSupport, this is how I'm ensuring
that the Acition knows about things like FieldErrors.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]