LookupField addValueChangeListener getValue() missing

I have just upgraded an application from v6.10.7 to v7.0.0. The following code is now broken:

@Inject
private LookupField companyLookup;

companyLookup.addValueChangeListener(e -> {
    currentCompany = (Company) e.getValue();
}

The getValue() call is generating the error “Cannot find Symbol”. I did see in the release notes that this method has changed, but I can’t figure out what it changed to.

How should I fix this?

Hi,

This change is mentioned in breaking changes of 7.0 release notes:

  1. Interface HasValue now has type parameter V - type of the corresponding value of UI component. Old code that uses untyped UI components, for instance TextField or LookupField might be broken.

You just need to specify type of value for your LookupField:

@Inject
private LookupField<Company> companyLookup;

It can be done automatically using intention provided by Studio.

Just set cursor on the field and hit Alt-Enter:

image

And now, you don’t need value casts anymore:

userField.addValueChangeListener(e -> {
    User user = e.getValue();
});