This content has been marked as final.
Show 5 replies
-
1. Re: One Seam component calling another
sebastiendeg Dec 31, 2007 6:29 AM (in response to breako)Hello,
As far I know, there are 2 ways :
1: use @In annotation. (recommended)
2: use Component.getInstance() (from non-seam component)
Have a look for options in booth technique.
Correct if I'm wrong.
Cheers, -
2. Re: One Seam component calling another
breako Dec 31, 2007 10:55 AM (in response to breako)"sdegardin" wrote:
1: use @In annotation. (recommended)
Thanks for your suggestion. I used the @In annotation but the problem is that the second Seam component does not get it's Seam managed EntityManager set up correctly.
Basically, I have two Seam components both involved in the same transacation. Both Seam Components have Seam managed EntityManagers and because there are involved in the same transaction, the persistence context should be propagated and shared.
First Seam Component:@Name("manager") @Scope(CONVERSATION) public class ManagerPojo { @In private EntityManager em; @In (required=false, value="instancegenerator", create=true) private InstanceGeneratorPOJO instanceGeneratorPOJO; @Begin(join=true, flushMode=FlushModeType.MANUAL) public void persist() { //... instanceGeneratorPOJO.getNextInstance("Person"); //... } //... }
Second Seam Component:@Name("instancegenerator") @Scope(CONVERSATION) public class InstanceGeneratorPOJO { @In private EntityManager entityManager; public Long getNextInstance(String type) { //... } }
When persist() is invoked I get:15:50:41,937 FATAL [application] org.jboss.seam.RequiredException: @In attribute requires non-null value: instancegenerator.entityManager javax.faces.el.EvaluationException: org.jboss.seam.RequiredException: @In attribute requires non-null value: instancegenerator.entityManager
Note: If I remove the create=true in the first Seam component, i.e.@In (required=false, value="instancegenerator") private InstanceGeneratorPOJO instanceGeneratorPOJO;
the instanceGenerator reference is null and I get a Null pointer exception in the persist() method
anybody got any ideas? -
3. Re: One Seam component calling another
gsegura Dec 31, 2007 5:17 PM (in response to breako)Hi,
it could be just the different variable name:private EntityManager em;
andprivate EntityManager entityManager;
regards -
4. Re: One Seam component calling another
sebastiendeg Dec 31, 2007 10:05 PM (in response to breako)"gsegura" wrote:
Hi,
it could be just the different variable name:private EntityManager em;
andprivate EntityManager entityManager;
regards
and if you don't want to use component name has field name, specify the component name in the "value" parameter of the In annotation@In(value="em") private EntityManager entityManager;
Cheers, -
5. Re: One Seam component calling another
breako Jan 2, 2008 5:50 AM (in response to breako)Thanks for the replies, you spotted my mistake.
Happy New Year!