1

Ok so I am really stuck now. I have a h:datatable and the only way to get the row details seems to be DataModel#getRowData(). Unfortunately ListDataModel which is needed to wrap the necessary data is NOT serializable so will not work on GAE, and I really need it to work! Does anyone have any idea about any workaround or some way to make it function. Help much appreciated!

Bogdan Glosz
  • 107
  • 2
  • 8

1 Answers1

1

Mark the property transient (so that it will be skipped during serialization) and introduce lazy loading in the getter.

E.g.

private List<Item> itemList;
private transient DataModel<Item> itemModel;

public DataModel<Item> getItemModel() {
    if (itemModel == null) {
        itemModel = new ListDataModel<Item>(itemList);
    }

    return itemModel;
}

There are by the way alternate ways to retrieve the current row. See also How can I pass selected row to commandLink inside dataTable?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • perfectly perfect thx a lot. I just have one more question, as I used your answer and modified a bit, In fact I did not use "List" I directly did: private transient DataModel model; public DataModel getModel() { if (model == null) { model = new ListDataModel(list of people); } return model; } Regarding different ways of passing params in my case those appeared not to be working maybe due to my lack of knowladge but I would say it was because I used selectonemenu with ajax so it appears not to cooperate with options you presented. – Bogdan Glosz May 15 '12 at 15:35
  • Your concrete problem is not clear, but I think that you need to recreate the `itemModel` based on the new items inside the ajax action listener method. – BalusC May 15 '12 at 15:38
  • well there is actually no problem I just wanted to show you that it worked without itemModel whatsoever, and just wanted to know if there are any drawbacks in that solution. – Bogdan Glosz May 15 '12 at 15:45
  • You mean, without the `itemList` property? Well there are not directly drawbacks, but if you ever need to add/remove items, then you'd need to recreate the `itemModel` everytime. With a backing `itemList` this is not necessary. – BalusC May 15 '12 at 15:50
  • Thanks a lot, thats exactly what I wanted to know! – Bogdan Glosz May 15 '12 at 15:54