Issue of datatable

UI Components for JSF
Post Reply
zsuiqiang
Posts: 146
Joined: 13 Sep 2010, 03:52

13 Oct 2010, 05:48

PrimeFaces 2.1 glassfish 3.01 netbeans 6.9.1
I try the "Simple DataTable" example in showcase,and I found that the "getCarsSmall()" method was called six times.
Why? not one time?
primefaces:jakarta:12.0.0.jar,
primefaces-ext:jakarta:12.0.0.jar,
JSF Mojarra 3.0
glassfish-6.2.5,
netbeans 14
IDEA 2022.2.2
Browser: Edge

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

13 Oct 2010, 14:24

This is normal, and is not specific to the PrimeFaces datatable.

Although the JavaBeans specification is slilent on the matter of whether a getter method should have business logic, the Managed beans in a JSF application are supposed to have getter methods which simply return the requested value and do nothing else since they may be called many times during the JSF lifecycle.

If you need to initialize a list it can be done in a constructor or in a method annotated with @PostConstruct or in a method called by an action.

zsuiqiang
Posts: 146
Joined: 13 Sep 2010, 03:52

14 Oct 2010, 05:52

Thanks for quick answer.
I tried <h:datatable>, and got same result.The getter method is called in every life cycle.But i tried <h:inputText> also, and the getter method is called only one time.

According to "Life Cycle" specification of JSF, it sholdn't be called in every life cycle.Shold it be called in "Render Response" phase?
primefaces:jakarta:12.0.0.jar,
primefaces-ext:jakarta:12.0.0.jar,
JSF Mojarra 3.0
glassfish-6.2.5,
netbeans 14
IDEA 2022.2.2
Browser: Edge

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

14 Oct 2010, 14:21

Since JSF manages the bean it can instantiate and access the bean at will. It is supposed to be somewhat of an abstraction so that you don't have to worry about it too much. However, if you want to trace phases you can implement the PhaseListener interface. If you are using JSF 2 you can also listen for system events.

zsuiqiang
Posts: 146
Joined: 13 Sep 2010, 03:52

15 Oct 2010, 03:14

Thanks for quick answer.

This case is occurredI only on datatable, that's why i am so suprise.

I just don't understand why datatable performs different from other components(for example tree) ,so I think it is a issue of datatable but you don't think so.
Now i don't know how to understand the "Life Cycle".
primefaces:jakarta:12.0.0.jar,
primefaces-ext:jakarta:12.0.0.jar,
JSF Mojarra 3.0
glassfish-6.2.5,
netbeans 14
IDEA 2022.2.2
Browser: Edge

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

15 Oct 2010, 12:30

DataTable works different, in each phase usually it resets it's internal datamodel causing your getter called to be multiple times. Best practice with jsf is not using any logic in getters, getters should just return properties. For example if you want to load some data initially when page is opened, just use constructor, f:event or @PostConstruct ways.

zsuiqiang
Posts: 146
Joined: 13 Sep 2010, 03:52

18 Oct 2010, 03:43

Thanks a lot!
I'm sorry, i made a mistake. I trace phase and i found that "getter" method is called six times only at phase RENDER RESPONSE,not at every phase.

Thanks for help again!
primefaces:jakarta:12.0.0.jar,
primefaces-ext:jakarta:12.0.0.jar,
JSF Mojarra 3.0
glassfish-6.2.5,
netbeans 14
IDEA 2022.2.2
Browser: Edge

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 26 guests