Hi,
I’m newby for Cuba Studio, I have a problem with the collection of Table item, the scenario is as follows:
main screen has one pickerField (pickerFieldA) and one table (tableB),
When the user select an element from pickerFieldA I would load data in the tableB depends from the value selected in the pickerFieldA.
To do this
@Inject
private Table<A> tableVariables;
@Subscribe("pickerFieldA")
public void onPickerFieldAValueChange(HasValue.ValueChangeEvent event) {
tableB.setVisible(true);
dataManager.load(A.class).query("select e from test_A e where e.id = " +
pickerFieldA.getValue());
List<A> lists= dataManager.load(A.class).list();
List<A> resultFinal = new ArrayList<>();
for (A obj : lists){
A variable = new Variable();
variable.setName(obj.getName());
variable.setDescription(obj.getDescription());
resultFinal.add(variable);
}
tableVariables.setItems((TableItems<A>) resultFinal);
}
}
The lists has three element and it’s correct.
I get the following error at this line
java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class com.haulmont.cuba.gui.components.data.TableItems (java.util.ArrayList is in module java.base of loader ‘bootstrap’; com.haulmont.cuba.gui.components.data.TableItems is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @a5b0b86)
You can use the query conditions to load data depending on the value in the PickerField component.
I gave an example of using:
The B entity has a Many-To-One relationship with A entity.
The screen contains the PickerField component for selecting an A entity and a table containing B entities that are associated with an A entity from the PickerField component.