just dont put data fetching in getter

i assume that user must click link or button to see your page with datatable. so, u can perform data fetching in action binded to that buttotn (or link) - that action returns string that is "maped" to your view.

your action does ".... bla bla populating array" and set bean's datamodel

getter ONLY gets that model


btw: your code wont work if user enter on same page second time
obviously if(array != null) is true so no "bla bla" is performed

Sławek Sobótka

Hello!

As I understand, MyFaces (and core JSF too) evaluates value getter for DataTable twice (or three times if preserveDataModel == true). If we are getting static data there is no problems, but if we'are populating data from SQL we get a big problems (as query are running twice). For the time present I found no another solution as:

public Collection getDatatableValue() {
        if(array != null)
                return array;
        array = new ArrayList();
        .... bla bla populating array
        return array;
}

Same may be done with DataModel. Want to know what other people doing in this sutiations? May be there is another solution?

With respect,
        Boris



Reply via email to