-
1. Re: Injection of SESSION POJO into event/session scoped POJO
cwash May 14, 2007 1:12 PM (in response to joeyxxx)Maybe a dumb question, but first one that pops in my head is... do you have getters/setters for the User on your component?
-
2. Re: Injection of SESSION POJO into event/session scoped POJO
joeyxxx May 14, 2007 1:45 PM (in response to joeyxxx)Thanks for your reply.
I do have the getters & setters. -
3. [Solved]: Injection of SESSION POJO into event/session scope
joeyxxx May 14, 2007 1:53 PM (in response to joeyxxx)I got it to work now.
Looks like the problem had to do with referencing the injected user object in the balance objects constructor. if the reference is done in a method other than the constructor, it works. -
4. Re: Injection of SESSION POJO into event/session scoped POJO
fernando_jmt May 14, 2007 2:06 PM (in response to joeyxxx)I will suggest you the following:
(The reasons I do this are in the Seam reference documentation)@Name("balance") @Scope(EVENT) public class Balance implements Serializable { private double totalMarketValue; private double cash; private double margin; private String userName; @In //it suppose the user already is in the session context (an instance) private User user; @Logger Log log; @Create public void initialize(){ this.setTotalMarketValue(0); this.setMargin(0); this.setCash(0); this.setUserName(user.getUsername()); } }
-
5. Re: Injection of SESSION POJO into event/session scoped POJO
cwash May 14, 2007 2:08 PM (in response to joeyxxx)I got it to work now.
Looks like the problem had to do with referencing the injected user object in the balance objects constructor. if the reference is done in a method other than the constructor, it works.
Ah, cool... yeah I'm pretty sure everything works off of setter injection. So the way the container injects your dependencies is by first creating a new instance through the default no-arg constructor and then injecting dependencies using setters for each @In annotation. That's probably why you were seeing problems. -
6. Re: Injection of SESSION POJO into event/session scoped POJO
joeyxxx May 14, 2007 2:23 PM (in response to joeyxxx)I do recall seeing initialize in a bunch of examples. I guess I better give the docs a once over and include an initialize skeleton in my templates.
Thanks again. -
7. Re: Injection of SESSION POJO into event/session scoped POJO
fernando_jmt May 14, 2007 2:33 PM (in response to joeyxxx)The name initialize does not matter. You can mane as you want, the most important thing here is the @Create annotation, which tells Seam to execute such method just after the component is successfuly initialized (all Seam components are available, ready to be injected).