-
1. Re: One @Factory ?
wrzep Jun 18, 2008 1:42 PM (in response to nimo22)Heya,
This seems to be a bit weird requirement. Why not 2 factories? :)
Anyway, here:
nimo mayr wrote on Jun 18, 2008 13:20:... List<Person> aList; List<Product> bList; @Factory("init") public void initLists() { aList = entityManager.createQuery("from Person a").getResultList(); bList = entityManager.createQuery("from Product b").getResultList(); } ...
you have to provide a a name of the returned Seam Component in the @Factory attribute. So, it should be @Factory("aList"). You can't provide 2 names... The thing you can do is mark bList with @Out and have it outjected when the factory method for aList is triggered.
Cheers
-Pawel
-
2. Re: One @Factory ?
nimo22 Jun 18, 2008 2:18 PM (in response to nimo22)yes, indeed. It s really better to write 2 Factories!..(or one with an @Create-Annotation?) I guess, I take 2 Factories.
thanks:-)
-
3. Re: One @Factory ?
endyamon Jun 18, 2008 2:52 PM (in response to nimo22)what about using one @Create instead of many @Factories to initialize your component?
-
4. Re: One @Factory ?
jnusaira Jun 18, 2008 8:39 PM (in response to nimo22)FWIW the @Factory is only going to do a lookup when you actually use the item.
In your example you never call
init
inside the xhtml hence why it doesnt work.The @Create annotation according to the doco is really only for non Session Beans.
I had
kindof
the same problem as you.What i did i had the SLSB with a @PostConstruct on it.
Then the factories were tied to the retrieve methods of each item. Of course in my example the retrieves were necessary anyway since a non Seam EJB needed access to them.
-
5. Re: One @Factory ?
nimo22 Jun 20, 2008 8:40 AM (in response to nimo22)Okay, indeed, I use two @Factory-Methods and declared both with names:
.. @Factory("initListA") public void initListA(){..} .. @Factory("initListB") public void initListB(){..} ..
Now I can take an xhtml and referenced the factories in it. It works without problems:-)
But now, I will reach the same with an @Create-Annotation in a Stateful SB:
... List<SelectItem> selectListA = new ArrayList<SelectItem>(); List<SelectItem> selectListB = new ArrayList<SelectItem>(); @Create @Begin public void initSession() { selectListA = entityManager.createQuery("from TableA a").getResultList(); selectListB = entityManager.createQuery("from TableB b").getResultList(); } ...
Normally, the reference in xhtml should be like:
<!-- Select List A --> .. <h:selectOneMenu value ="#{listA.row}" id="row"> <s:selectItems value="#{selectListA}" var="a" label="#{a.row}" id="selectTeam"/> </h:selectOneMenu>
But the reference 'selectListA' does not work!
Why? Have I use the @PostConstruct?
-
6. Re: One @Factory ?
nimo22 Jun 20, 2008 8:57 AM (in response to nimo22)Oh, I forgot the GETTERS for the two Lists..now it works with the @Create-Annotation.
bye:-)