Converter error on readOnly TextField

I have a TextField with readOnly PropertyDataSource. It means the value will never convert the presentation string to model type and in fact there is no commit in the application. But there is still error marker in the GUI ‘Cannot convert value to MyObject’. Why?

Of course I can use Label but my application is generic, the writable flag is dynamic and I would like to avoid switching between Label and TextField depending on the readonly status.

The fact that you have validation causes the error. Validation calls getConverter().convertToModel(…) and it’s performed already for the initial value you set to the field. Your TextField needs to have a converter that can convert the value to MyObject for the validation to pass. If you are using a FieldGroup you need to have that converter set before you call fieldGroup.bind(…).

No fieldGroup, just simple, readOnly Property instance. The sequence is

TextField tf = new TextField();

[/code]It means there are no validators and the property is readOnly. And even when not removed why the Validator tries to convert the Presentation to Model when the model is readonly? What’s the reason to validate anything that never will be written / converted to model?

IMO readonly TextField should behave like a Label. I never understood why the Label does not implement Field interface. Label is for me a Field with no Editor, it’s only a Viewer.

Actually, removing all validators there doesn’t really do anything since the validators, if any, would be set in the setPropertyDataSource() – if the dataSource is Validatable that method attempts to add all validators from the dataSource to the field. Of course I’m still only guessing here since your example is rather limited and you haven’t mentioned which version of Vaadin you are using etc. In my quick test on Vaadin 7 with BeanItem-type dataSource of something non-convertable with no converter given I got the error from the convertFromModel already, as expected, so you are clearly doing something different to get as far as convertToModel. And easy way to get there would be for example to add a converter that throws UnsupportedOperationException() for convertToModel, but your example doesn’t have that (nor should it).