Refresh Datagrid from Non-Persisted Entity

I am binding a datagrid to a non persisted entity that is programmatically populated based on user input. I get an error a refresh load() of DataLoader (see below)

@Inject
private DataGrid<JobSchedule_Stage> jobScheduleGrid;

@Inject
private CollectionLoader<JobSchedule_Stage> jobScheduleStageDl;

private ArrayList<JobSchedule_Stage> jobScheduleStageLst; //the non-persisted entity bound 

@Install(to = "jobScheduleStageDl", target = Target.DATA_LOADER)
private List<JobSchedule_Stage> jobScheduleStageDlLoadDelegate(LoadContext<JobSchedule_Stage> loadContext) {
    return jobScheduleStageLst;
}
@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
    jobScheduleStageLst = new ArrayList<>(); //start datagrid as empty
    jobScheduleStageDl.load();
}

Public void RefreshDatagrid() {   
    jobScheduleStageLst.clear();
    . . . .load data into jobScheduleStageLst . . . .
      jobScheduleStageDl.load(); //This errors with:

//DataContext already contains an instance with null id: com.jsonedi.jediadmin.entity.nonpersisted.JobSchedule_Stage-null [new]
}

I fixed this myself but wanted to post a reply for others. In this use case using a DataLoader is pointless. Use the CollectionContainer without a DataLoader. Just @Inject a screen’s CollectionContainer and bind the List with the setItems(List) method as needed.

1 Like