: getXxx() get called so many times, why?

前端 未结 1 1324
一生所求
一生所求 2021-01-03 13:32

Simple piece of code about dataTable. CentralFeed is SessionScoped Bean, and PostComment is RequestScoped Bean



        
1条回答
  •  执笔经年
    2021-01-03 14:22

    Yes, getters can be called multiple times during a request. It doesn't harm as long as it does its sole job properly: returning the bean property. However, in your example you're loading the list straight in the getter method! This should be avoided. Initializing/loading of the model should go in bean's constructor or @PostConstruct or any event based methods like the action method. They get called only once. The getters should only return model data and nothing more (apart from some trivial logging or lazy loading).

    See also:

    • Why does JSF call getters multiple times?

    0 讨论(0)
提交回复
热议问题