IllegalStateException: Unable to change component for bound FieldConfig

I have just upgraded to 6.5.0 and I’m updating my code to use the new FIeldGroup setup. I am trying to replace a text field in the FieldGroup with a LookupField. Here is my code:


LookupField recTypeLookup = (LookupField) componentsFactory.createComponent(LookupField.NAME);
recTypeLookup.setOptionsMap(codeService.getCodes("T"));
recTypeLookup.setDatasource(custFieldGroup.getDatasource(), "rtype");
custFieldGroup.getFieldNN("rtype").setComponent(recTypeLookup);

I get the error message in the subject. What is the correct way to override the default Text field created by the FieldGroup?

To answer my own question for the next user, I have to set:


custom="true"

in the XML for the fields where I want to override the implementation with setComponent(). It is in the documentation (https://doc.cuba-platform.com/manual-6.5/gui_FieldGroup.html) under the description of the “custom” property.

1 Like

Hi,

I’ve just noticed that you use:


(LookupField) componentsFactory.createComponent(LookupField.NAME);

It can be simplified to:


componentsFactory.createComponent(LookupField.class);

And you can skip unnecessary (LookupField) cast.