-
1. Re: jsFunction data executing backing bean function twice
healeyb Aug 14, 2012 6:28 AM (in response to garagoth)I don't think it's intended that the data attribute value should be a method call, the only way I've ever used this is where
it references a String in a backing bean, and you know what JSF is like with calling getters loads of times.
I'd suggest using an action routine (not actionListener, unless they've fixed the bug where the actionListener executes
before the a4j:param setter) to setup the data which will then be retrieved by the data attribute getter. I'm not sure
what data types are supported but you could experiment.
Regards,
Brendan.
-
2. Re: jsFunction data executing backing bean function twice
snjv180 Aug 14, 2012 10:12 AM (in response to healeyb)Yes I have a same kind of problem and have used a flag to check if data has been already loaded and Brendan is absolutely correct about JSF calling the getters. Mine queried the database nearly 4 to 5 times before displaying the result. I would very much appreciate a concrete and stable solution if there is one.
-
3. Re: jsFunction data executing backing bean function twice
healeyb Aug 14, 2012 10:18 AM (in response to snjv180)The golden rule is simply never access the database from a getter, or you'll have serious performance problems.
-
4. Re: jsFunction data executing backing bean function twice
snjv180 Aug 14, 2012 10:21 AM (in response to healeyb)So how should this be implemented. Are you suggesting binding or any other way through which this would be possible. I mean if I need data and there are just so many records and I need to extract a subset of these record what should I do to resolve this problem.
-
5. Re: jsFunction data executing backing bean function twice
garagoth Aug 14, 2012 10:26 AM (in response to healeyb)Hi,
With calling action and data as property, it still gets called twice (getter for data that is).
Even stranger, it calls: getter for data, action method, getter for data (again)
Regards,
Marcin.
-
6. Re: jsFunction data executing backing bean function twice
healeyb Aug 14, 2012 10:34 AM (in response to snjv180)1 of 1 people found this helpfulI never need to use binding, in a backing bean have a List<Something> mylist and <rich:dataTable value="#{bean.mylist}" ...>. So
then you need to populate this list somehow. Often I will use a f:event preRenderView event listener to load the data when the page
loads.
Other times the dataTable may be in a tabPanel (not the first tab) so I'll load mylist in a tab change listener. Or maybe the user has
to make some selections before the data can be dislayed in the table in which case the data may be loaded in a value change
listener or an action method.
It's really just a case of leaving the loading of the data to the last possible moment. Care needs to be taken to ensure that the list
is reloaded after any changes are made to the underlying data (obvious but I often forget!).
Regards,
Brendan.
-
7. Re: jsFunction data executing backing bean function twice
snjv180 Aug 14, 2012 10:39 AM (in response to healeyb)Thank you Brendan,
Yes I see now. Thank you for a wonderful answer and sharing your idea. I hope I can implement it the same way if possible and make my application faster.
-
8. Re: jsFunction data executing backing bean function twice
healeyb Aug 14, 2012 10:39 AM (in response to garagoth)If you output this in the getter using a logger or System.out.println it will show which phase it's being called
in which may or may not shed some light in what's going on (probably not in fact):
FacesContext.getCurrentInstance().getCurrentPhaseId().toString()