0

For optimize the performance of an application I discovered an unexpected behavior in datatable during single row selection.

....                 
                     <p:dataTable
                        id="table"
                        var="object"
                        value="#{testBean.objects}"
                        rowKey="#{object.paramA}"
                        selectionMode="single"
                        selection="#{testBean.selectedObject}"
                    >
                        <p:ajax
                            event="rowSelect"
                            process="@this"
                        />
....

If i select a row the getters for all columns of all entries in table are called. Why does it behave like these?

And are they options to disable these?

I tried to use different process like '@none' but these also disable the setter for the selectionObject.

Thanks for any tips.

Edit: In use Primeface 6.0; JSF 2.0; JavaSE 1.6;

Edit2: executable Code

testpage.xhtml

           <h:form id="form">
                <p:dataTable
                    id="dtSelection"
                    var="object"
                    value="#{selectionTestBean.objects}"
                    selectionMode="single"
                    selection="#{selectionTestBean.selectedObject}"
                    rowKey="#{object.variableA}"
                >
                    <p:ajax 
                        event="rowSelect"
                    />

                    <p:column headerText="Variable">
                        <h:outputText value="#{object.variableA}" />
                    </p:column>
                </p:dataTable>
            </h:form>

Bean

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Named;

@WebSessionBean
@Named("selectionTestBean")
public class SelectionTestBean implements Serializable {
    private static final long serialVersionUID = 1L;

    private List<ObjectA> objects;

    private ObjectA selectedObject;

    @PostConstruct
    private void init() {
        System.out.println("PostConstruct Bean");
        this.objects = new ArrayList<ObjectA>();

        for(int i=0; i<20; i++) {
            ObjectA object = new ObjectA(i);
            this.objects.add(object);
        }
    }

    public List<ObjectA> getObjects() {
        System.out.println("getObjects");
        return this.objects;
    }

    public ObjectA getSelectedObject() {
        System.out.println("getSelectedObject");
        return this.selectedObject;
    }

    public void setSelectedObject(ObjectA selectedObject) {
        System.out.println("setSelectedObject");
        this.selectedObject = selectedObject;
    }
}

Object

public class ObjectA {

    private int variableA;

    public ObjectA(int variableA) {
        this.variableA = variableA;
    }

    public int getVariableA() {
        System.out.println("getVariableA:"+this.variableA);
        return this.variableA;
    }

    public void setVariableA(int variableA) {
        this.variableA = variableA;
    }
}

Output

// Step 1 load page
PostConstruct Bean
getSelectedObject
getObjects
getSelectedObject
getObjects
getVariableA:0
getVariableA:0
getVariableA:1
getVariableA:1
getVariableA:2
getVariableA:2
getVariableA:3
getVariableA:3
getVariableA:4
getVariableA:4
getVariableA:5
getVariableA:5
getVariableA:6
getVariableA:6
getVariableA:7
getVariableA:7
getVariableA:8
getVariableA:8
getVariableA:9
getVariableA:9
getVariableA:10
getVariableA:10
getVariableA:11
getVariableA:11
getVariableA:12
getVariableA:12
getVariableA:13
getVariableA:13
getVariableA:14
getVariableA:14
getVariableA:15
getVariableA:15
getVariableA:16
getVariableA:16
getVariableA:17
getVariableA:17
getVariableA:18
getVariableA:18
getVariableA:19
getVariableA:19
//---

//Step 2 click on row
getObjects
getObjects
getObjects
getObjects
getObjects
getVariableA:0
getVariableA:1
getVariableA:2
getVariableA:3
getVariableA:4
getVariableA:5
getVariableA:6
getVariableA:7
getVariableA:8
getVariableA:9
getVariableA:10
getVariableA:11
getVariableA:12
getVariableA:13
getVariableA:14
getVariableA:15
getVariableA:16
getVariableA:17
getVariableA:18
getVariableA:19
getObjects
getVariableA:0
getVariableA:1
getVariableA:2
getVariableA:3
getVariableA:4
getVariableA:5
getVariableA:6
getVariableA:7
getVariableA:8
getVariableA:9
getVariableA:10
getVariableA:11
getVariableA:12
getVariableA:13
getVariableA:14
getVariableA:15
getVariableA:16
getVariableA:17
getVariableA:18
getVariableA:19
getObjects
getObjects
getObjects
getObjects
getObjects
getObjects
getObjects
setSelectedObject
getObjects
getObjects
getObjects
//---

Like you can see in Output the selection cause the getter of each object in the table. Why? And are they options to prevent these?

SimonA
  • 9
  • 1
  • 6
  • [mcve] please... code you show can never be the cause of your problem. And post version info, see http://www.stackoverflow.com/tags/jsf/info – Kukeltje Jan 09 '17 at 20:28
  • See edit. The code can cause the described behavior. – SimonA Jan 10 '17 at 09:02
  • This is not really updating the rowData, it is calling getters multiple times. Calling getters is very, very inexpensive as long as you don't do any work in them. , http://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times. Some improvement could be: http://stackoverflow.com/questions/24725699/skip-processing-of-input-components-inside-pdatatable-when-a-button-is-pressed – Kukeltje Jan 10 '17 at 10:05
  • Try if adding `skipChildren="true"` to the `p:ajax` helps. If it does, I'll create an answer – Kukeltje Jan 10 '17 at 10:11
  • adding skipChildren="true" to p:ajax does not help. Still call the getter of each object. – SimonA Jan 10 '17 at 10:22
  • sorry for confusing using the wording 'Update' ;). – SimonA Jan 10 '17 at 10:24
  • But also for me still confusing why it call all getter of each object. In my application I have huge table with a lot of columns. Some of them columns contains simple backend logic. I know that should not be done, but was the simplest way for the implementation and of course i could use a wrapper for these. But I also think that the getter calls are unnecessary at a row selection – SimonA Jan 10 '17 at 10:32

0 Answers0