开发者

Help understanding JSF's multiple calls to managed bean

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 happen开发者_运维问答ing? If you need more code please ask. But that's the only place where I use that property.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜