Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Exception handling in databinding
Exception handling in databinding [message #508129] Sat, 16 January 2010 06:40 Go to next message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1290
Registered: July 2009
Senior Member

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 15:54 Go to previous message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1290
Registered: July 2009
Senior Member

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 );
Previous Topic:[CNF] Using CNF, SelectionProvider and property testers
Next Topic:GridData can"t be cast to FillData in PropertySection
Goto Forum:
  


Current Time: Wed Jul 30 21:34:08 EDT 2014

Powered by FUDForum. Page generated in 0.01811 seconds