Reputation: 4991
I'm using h:datatable, here's the revelant line of my code:
<h:dataTable value="#{account.latestIncomes}" var="mov" >
.....
</h:dataTable>
then I have a Request scoped managedBean with the getter for the latest Incomes:
public List<Movs> getlatestIncomes() {
if (incomes == null)
incomes = this.cajaFacade.getLatestIncomes(20);
return incomes;
}
this getter gets called 8 times, and I'm not using it anywhere else, only on the value for the dataTable. Why is this happening? If you need more code please ask. But that's the only place where I use that property.
Upvotes: 1
Views: 1725
Reputation: 1108712
It get called as many as JSF needs to access it. You should technically not worry about this.
However, with the given code snippet, it should be called at highest 3 times, all during the render response phase. Once during encodeBegin()
, once during encodeChildren()
and once during encodeEnd()
. Or does it contain input elements and did you count during a form submit?
Regardless, debugging the stack and the current phase ID in the getter should give some insights.
private List<Movs> latestIncomes;
private AtomicInteger counter = new AtomicInteger();
@PostConstruct
public void init() {
latestIncomes = cajaFacade.getLatestIncomes(20);
}
public List<Movs> getlatestIncomes() {
System.err.printf("Get call #%d during phase %s%n", counter.incrementAndGet(),
FacesContext.getCurrentInstance().getCurrentPhaseId());
Thread.dumpStack();
return latestIncomes;
}
(as you see, I moved the list loading to the right place)
Upvotes: 2