0

I have a problem with a LazyDataModel (list) in JSF. The problem is the next:

I have a xhtml with a search form and a list of results of that search. I do a first search and show on this pagined list, when I move on about the pages and I have, for example, in the fourth page:

enter image description here

If I realize a new search, in this new result, the list charge on page 4. The parameter first don't reset in every new search. Why?

enter image description here

  1. The bean has the annotations: @Component and @ViewScoped.
  2. The list with the results is a LazyDataModel and overwriting the methods: load, getRowKey and getRowData.
  3. The versions are: JSF 2.0, PrimeFaces 6.1 and Spring 4.0.3.RELEASE.
agu
  • 35
  • 5

1 Answers1

0

The problem is if you maintain the same datamodel. You need to create a new datamodel when refresh the list.

For example, the datamodel:

public class MyDataModel extends LazyDataModel<MyEntity> {
   // my datamodel
}

And the bean (in this case, CDI)

@Named
@ViewScoped
public class MyBean implements Serializable {

    private static final long serialVersionUID = 1L;    

    private MyDataModel myDataModel;

    //calling this method, a new datamodel is created and populated
    public void search() {
        List myList = new ArrayList(); //load from database
        loadDatamodel(myList);  
    }

    private void loadDatamodel(List myList) {               
        myDataModel = new MyDataModel(myList);
    }

    public MyDataModel getMyDataModel() {
        return myDataModel;
    }
}

So, in every search, a new datamodel is created.

C.P.O
  • 1,213
  • 2
  • 11
  • 29