Giovanni Azua wrote:
hi,
I provided declarative XML validation for a form where the action
would expose primitive type properties. The problem is that a
primitive type property left blank in the form would never be caught
as not provided by the "required" validation. The property would
instead be set with the default value for such primitive type. When
the text field in the form is left empty the "required" validation
wont work but instead setExchangeRate would be called with 0.0 value,
same for int, boolean etc. The workaround is to using the
corresponding boxed type e.g. Double, Integer but e.g. Boolean would
not work like this.
TIA
regards,
Giovanni
I concur, but it's not a problem with validation. It's a combination of
factors:
1st, your action instance is instantiated. Primitives are initialised to
their default value.
2nd, the parameters interceptor is called and sets properties of your
action. It cannot set primitives to null, so it does not write to these
properties.
3rd, the validation interceptors are executed. They cals the getters of
your action instance and observe the default values for the primitives.
Personally, I never expose primitives as properties of an action because
null values are always legal over this interface. In the special case
of Boolean which can easily accidentally cause an NPE, I always make the
getter return false if the value is null..
eg.
Boolean getBooleanProperty() {
if (value != null) {
return value;
} else {
return false;
}
}
Hope that helps,
Jeromy Evans
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]