-
1. Re: Factory method is getting called so many times
asookazian Jul 27, 2009 6:10 PM (in response to hubaghdadi)What does
page request
mean exactly? Submission of a form (HTTP POST request) or actually PAGE scope? Show code.The @Factory method fires when the associated @DataModel List object, for example, is null. So if your List is going out of scope (and being destroyed by Seam container) or your Seam component is going out of scope and being destroyed, it's possible that the @Factory method will fire again. It happens also when you programmatically set the List object to null.
-
2. Re: Factory method is getting called so many times
cash1981 Jul 27, 2009 6:25 PM (in response to hubaghdadi)Maybe its because of the different JSF stages?
-
3. Re: Factory method is getting called so many times
asookazian Jul 27, 2009 7:22 PM (in response to hubaghdadi)The multiple calls to getter methods from rendered attributes applies to the above comment (JSF life cycle phases) but I don't think it's applicable for @Factory.
It's a matter of is the value for @Factory null or not. If it's null, the method will (re-)execute. Very simple.
-
4. Re: Factory method is getting called so many times
hubaghdadi Jul 28, 2009 9:47 AM (in response to hubaghdadi)@Name("groupManager") @Scope(ScopeType.CONVERSATION) public class GroupManager implements Serializable { @Logger private Log logger; @In private EntityManager entityManager; @DataModel private List<Group> groupList; @SuppressWarnings("unchecked") @Factory("groupList") public void loadGroups() { logger.info("Load Groups"); groupList = entityManager.createQuery("select grp from Group grp").getResultList(); logger.info("Done #{groupList}"); } }
The Group component is registered under the event scope.
-
5. Re: Factory method is getting called so many times
accless Jul 28, 2009 12:42 PM (in response to hubaghdadi)u never know how much/often the rendered-Attribute of jsf-componentns is called during the render-response-phase of the jsf-life-cylce.
U have to create some kind of cache. for your case u could achive this easily by doing this:@SuppressWarnings("unchecked") @Factory("groupList") public void loadGroups() { logger.info("Load Groups"); if (groupList == null) { logger.info("refresh groupList from db"); groupList = entityManager.createQuery("select grp from Group grp").getResultList(); } logger.info("Done #{groupList}"); }
-
6. Re: Factory method is getting called so many times
kukeltje.ronald.jbpm.org Jul 28, 2009 1:58 PM (in response to hubaghdadi)That should not be needed for @Factory annotated methods afaik. I think I read somewhere that there might be a 'clash' by having the datamodel field also named 'grouplist'.
And try changing the
logger.info("Done #{groupList}");
to
logger.info("Done #0", groupList");
-
7. Re: Factory method is getting called so many times
asookazian Jul 29, 2009 1:02 AM (in response to hubaghdadi)It is unnecessary to check for null with a @Factory method if you're simply checking the same variable. The method will exec if the associated List is null. Thus, the check is not required.
I do not see an @Begin anywhere in that component, is an LRC already running? If not, the component will be destroyed by Seam after it has rendered the JSF page (all temp conversations are cleaned up by Seam - add an @Destroy method to prove it).