Question

I want to receive typed List via RPC and then link it to ListDataProvider. Then ListDataProvider must show this list in CellTable. But List, which I get from RPC, doesn't show up in CellTable. I created a simple List without RPC and linked it to ListDataProvider. This List showed up successfully. With help of debugger I found difference between these 2 Lists (variables):

  • Structure of variable got from RPC is elementData->[0],[1],...
  • Structure of variable with simple List is list->elementData->[0],[1],...

Here I send List via RPC:

public List<Pravform> greetServer(String input) throws IllegalArgumentException {
...
TypedQuery<Pravform> query = em.createQuery("SELECT p FROM Pravform p",Pravform.class);
List<Pravform> categoryList = query.getResultList();
return categoryList; 
}

Here I link List to ListDataProvider.

public void onSuccess(List<Pravform> result) {
List<Pravform> listPf = dataProvider.getList();
listPf = result;        
}

Please tell me, what did I do wrong?

Was it helpful?

Solution

The problem is the way DataListProvider works. You basicaly just asks for its List of data and then you modify this List. So in onSuccess you ask dataProvider to give you its List, in which it stores its data. You store the reference to that List in listPf. But afterwards, you assign to listPf completely different List. So before this step, listPf pointed into same data that are stored into table (listPf -> List with data in the table). But after that it points to data from RPC (listPf -> result). So obviously, you see no changes to your data in CellTable, because you didn't change them.

The solution should be, set to DataListProvider your new list in onSuccess (I must admit I didn't tried that)

dataProvider.setList(result);

Or work just with provided list from your dataProvider (as I do it)

public void greetServer(String input, List listFromDataProvider) throws IllegalArgumentException {
...
TypedQuery<Pravform> query = em.createQuery("SELECT p FROM Pravform p",Pravform.class);
listFromDataProvider.addAll(query.getResultList());
}

And when you call this method from RPC use

greetServer("someInput", dataProvider.getList())
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top