setOptionsEnum to different class causes Convert error

Hi,

I am trying to alter a drop down Enum option list depending on the incoming value to the edit screen. The drop down changes as expected when the screen displays, but when I select an option I get the following error (if it isn’t the first Enum list):

ConversionException: Unable to convert value of type com.solutiondomain.fieldsolution.entity.ElectricJobTypes to model type class com.solutiondomain.fieldsolution.entity.WaterJobTypes. No converter is set and the types are not compatible.

Source file attached.

Do I need to convert the field as well somehow when I set the different Enum class?

TaskEdit.java (2.2K)

Hello,

Could you share a screen XML descriptor and an Entity class?

An exception is thrown because you are trying to set a selected option to the tasktype field. Check that your enumerations are inheritors of a type of the tasktype property.

Best regards,
Daniil.

Hi,

I’m not sure I was trying to do something that was possible, essentially I want a property to be an Enum but depending on what is selected, only show a sub set of the Enum in the dropdown selector. E.g.

Option1
Option2
Option3
OptionA
OptionB
OptionB

If the user selects “numbers” only show Option1-3 in the dropdown and if they select “letters” show OptionsA-C

What is the best way of doing that? Is an Enum appropriate?

Hello,

You can use different enums as options for LookupField, but you can’t create an entity field that has some ‘parent’ enum type.

There are two ways:

  1. Store string representation of an enum value and write custom logic to determine which enum has this option
  2. Store all options in one enumeration, filter them and use the OptionsField#setOptionsList method.

Best regards,
Daniil.

Thanks, how would I filter them in option 2 you describe?

It depends on your business logic. General idea is to iterate over enumeration values, filter and collect them to some list. Then you can just invoke lookupField.setOptionsList(listWithFilteredOptions).