3
<p:commandButton value="Get Name List" update="nameinfo"/>
<p:dataTable id="nameinfo" var="nam" value="#{namefinder.dofind}"></p:dataTable>
  • "namefinder" is managed bean [ @ManagedBean(name = "namefinder")]
  • "dofind" is the method which find the name list and it return the value as namefinder class object list

    Problem is: "dofind" method is call 7 times.

    why doing like this?

perissf
  • 15,979
  • 14
  • 80
  • 117
user3463207
  • 35
  • 1
  • 3

1 Answers1

3

Because this is the way JSF is working, and this is correct according to Java Bean principles. Getter can be called multiple times, as much as the caller wishes.

The value attribute of p:dataTable expects getter method and is calling that method multiple times. You can't guarantee how many times will a getter be called. Instead, you should do no logic in getter method.

Instead, provide the method that will be called by your p:commandButton and refresh the collection there. dofind should be the field of JavaBean with the list of rows, no logic should be done there.

Danubian Sailor
  • 1
  • 38
  • 145
  • 223
  • I already do that as alternate way. But I did not understand why this doing like this. Now I am cleared, thank you so much Lukasz. – user3463207 Mar 26 '14 at 13:41
  • Hum, it's strange! I've done something like and it only execute the value method only one time. – Cold Mar 26 '14 at 14:34
  • @ColdHack the getter is not guaranteed to be called one time, or 10 times, or whatever. Just consider, that JSF code doesn't care for preventing subsequent calls to the getter, therefore you should prevent using any heavy computations there. – Danubian Sailor Mar 26 '14 at 14:37