0

I have the following to display data.

<p:dataGrid
            id="employeeList"
            var="employee"
            rowIndexVar="rowIndex"
            value="#{sampleController.employeeRecords}"
            columns="1"
            layout="grid"
            rows="10"
            paginator="true"
            emptyMessage="No items to display..." > ..... </p:dataGrid>

and my controller(sampleController) has the following getter setter

private List<EmployeeVo> employeeRecords;
public List<EmployeeVo> getEmployeeRecords()
{
    return employeeRecords;
}

public List<EmployeeVo> setEmployeeRecords()
{
    return employeeRecords;
}

and have one more method which sets the value to employeeRecords like the following

public void loadEmployee(){
     
    List<EmployeeVo> list = //call to DB
    setEmployeeRecords(list);
    
    }

and everything works fine except the pagination. Whenever I click on the page numbers, the control goes to getter method (setEmployeeRecords()) more than once and the values in the list gets manipulated and final results are not proper.

Why does clicking on page number takes me to getter method and is it not managed in the client level?

Note I have not done anything the getter or setter. They are plain getter and setter. setting the values is done only once in the following:

public void loadEmployee(){
         
        List<EmployeeVo> list = //call to DB
        setEmployeeRecords(list);
        
        }

and the call never goes there too whenever I click on the page numbers.

halfer
  • 19,824
  • 17
  • 99
  • 186
Joe
  • 4,460
  • 19
  • 60
  • 106
  • 1: because that is how the component is implemented. Working examples are in the PrimeFaces showcase (with the assumption you need basic jsf knowledge) and correct your post. A getter is not called setXxx. And read this https://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times – Kukeltje Mar 28 '18 at 06:32
  • 1
    Possible duplicate of [Why JSF calls getters multiple times](https://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times) – Kukeltje Mar 28 '18 at 06:35
  • @Kukeltje it changes the value which is there in VO too – Joe Mar 28 '18 at 06:59
  • No idea what you mean by this – Kukeltje Mar 28 '18 at 07:50
  • @Kukeltje The value in the list is getting changed when the getter is called multiple times – Joe Mar 28 '18 at 07:59
  • 1
    Then read my 'possible duplicate'... Please... Things are posted for a reason – Kukeltje Mar 28 '18 at 09:24
  • @Kukeltje, Yes after reading that only i have posted the above comment. I dont do anything in the getter/setter.... setting value also is done in different method. appreciate all your support and answers – Joe Mar 28 '18 at 16:38

0 Answers0