I have a legacy table in an application that looks like this:
create table code_control (
rec_type char(1), /* used to group codes for each field - codes for a field have the same rec_type */
code char(1), /* code within the field */
seq number, /* order to display the codes in a lookup field */
descr varchar2(20), /* text to display */
status char(1), /* A = Active (display it), I = Inactive (ignore it) */
constraint codecontrol$pk primary key on (rec_type, code)
);
I am looking for the best way to populate my lookup fields from these codes. I have set up a CodeControl Entity with a Composite Key. I have also set up a MANY_TO_ONE association inside an Entity that contains a code field. Unfortunately, this isn’t enough to get things working. The missing factors are:
- I have to only select the particular rec_types for the lookup field I’m associating with in each case.
- I have to only include code records with status = ‘A’
Will I have to create Eclipselink DescriptionCustomizer classes for each and every code lookup? Ref: EclipseLink/Examples/JPA/MappingSelectionCriteria - Eclipsepedia
If I select the data I need in a CollectionDatasource and set it as the optionsDatasource on my lookup field, I still have to somehow extract the chosen code out of the lookup to save to the item I’m editing.
And, to make matters more interesting, I’m doing this as an inline edit in a table. I’m using code like this to set up the lookup field:
@Inject
private CollectionDatasource<CodeControl, CodeControlCompKey> assignmentDs;
@Override
public void init(Map<String, Object> params) {
offersTable.addGeneratedColumn("assignment", new Table.ColumnGenerator() {
@Override
public Component generateCell(Entity entity) {
LookupField field = (LookupField) componentsFactory.createComponent(LookupField.NAME);
field.setDatasource(offersTable.getItemDatasource(entity), "assignment");
field.setOptionsDatasource(assignmentDs);
field.addValueChangeListener(e -> {
Offer offer = getItem();
offer.setAssignment(((CodeControl) e.getValue()).getId().getCode());
});
return field;
}
});
}
My ValueChangeListener on the embedded LookupField is not firing when I choose a value. Instead, I’m getting this error:
ConversionException: Unable to convert value of type com.paslists.rade.entity.CodeControl to model type class java.lang.String. No converter is set and the types are not compatible.
It appears the framework is trying to store my CodeControl entity directly to my entity, rather than the code field I would like to save.
In addition, when loading an entity that already exists, I’m 99% sure that the CodeControl value won’t be matched up, since I don’t have a true key to it in my entity and only have the code field. Something has to look up the description to go with the code to display it as the current value of the field.
Does anybody have a better way to do all of this?