Exception handling in databinding [message #508129] |
Sat, 16 January 2010 11:40 |
|
Hi,
I'd like to understand the exception handling in the databinding, i.e.
what happens if an exception occurs in a Validator, a Converter, or
while getting or setting the value.
When a binding is created using the code below, I notice that an
exception thrown in the converter attached to the modelToTaget strategy
is reflected in binding.getValidationStatus().getException().
If I try the same in the opposite direction, i.e. with a targetToModel
converter, the exception is silently swallowed and the model update even
succeeds.
What is the rationale behind this behavior? Is there any document
describing databinding and exceptions?
Thanks, Ralf
DataBindingContext context = new DataBindingContext();
IObservableValue modelValue = PojoObservables.observeValue( model,
"value" );
IObservableValue targetValue = PojoObservables.observeValue( target,
"value" );
UpdateValueStrategy modelToTarget = new UpdateValueStrategy();
IConverter converter = new Converter( String.class, String.class ) {
public Object convert( Object fromObject ) {
throw new RuntimeException();
}
};
modelToTarget.setConverter( converter );
context.bindValue( targetValue, modelValue, targetToModel, null );
|
|
|
Re: Exception handling in databinding [message #508689 is a reply to message #508129] |
Tue, 19 January 2010 20:54 |
|
The problem I reported was on my side, I mixed up model and target in my
test. I'm sorry for the disturbance.
Obviously, exceptions thrown in validators or converters are generally
reflected in the validation status:
binding.getValidationStatus().getException()
So it seems to be a good practice to check this method.
Still I'd be happy to find some more documentation on this topic. Any
pointers?
Regards,
Ralf
Ralf Sternberg wrote:
> Hi,
>
> I'd like to understand the exception handling in the databinding, i.e.
> what happens if an exception occurs in a Validator, a Converter, or
> while getting or setting the value.
>
> When a binding is created using the code below, I notice that an
> exception thrown in the converter attached to the modelToTaget strategy
> is reflected in binding.getValidationStatus().getException().
>
> If I try the same in the opposite direction, i.e. with a targetToModel
> converter, the exception is silently swallowed and the model update even
> succeeds.
>
> What is the rationale behind this behavior? Is there any document
> describing databinding and exceptions?
>
> Thanks, Ralf
>
>
> DataBindingContext context = new DataBindingContext();
> IObservableValue modelValue = PojoObservables.observeValue( model,
> "value" );
> IObservableValue targetValue = PojoObservables.observeValue( target,
> "value" );
> UpdateValueStrategy modelToTarget = new UpdateValueStrategy();
> IConverter converter = new Converter( String.class, String.class ) {
>
> public Object convert( Object fromObject ) {
> throw new RuntimeException();
> }
> };
> modelToTarget.setConverter( converter );
> context.bindValue( targetValue, modelValue, targetToModel, null );
|
|
|
Powered by
FUDForum. Page generated in 0.03220 seconds