-
1. Re: POJO and context question
tom_goring Apr 17, 2008 11:31 PM (in response to marka4)i think your problem here is that customerDTO is an instance variable of your stateless session bean. that session bean will be shared between various http requests (from a pool).
In general it is a bad idea to have instance variables like this on a stateless component.
You could
- make CalculatorAction just a pojo that is conversation or event scoped
- try and also annotate customerDTO with @In(required=false) so the last values is removed
- Make CalculatorAction a @Statefull session bean
hope this helps.
-
2. Re: POJO and context question
marka4 Apr 18, 2008 11:16 PM (in response to marka4)Thanks Tom. Your ideas lead me to a fix and it's working now.
I needed to re-think the whole SLSB thing for Seam. Coming from a Struts background, we use a lot of SLSBs as session facades. I was trying to do what the Seam equivalent of that was but was thrown by the frequent use of instance variables with @In and @Out in SLSB examples in the Seam docs and books.
In general it is a bad idea to have instance variables like this on a stateless component.I would agree with that in a non-Seam environment, but in Seam it seems to be common -- at least from the many examples I've been seeing. I was just not going about it correctly, and am pretty sure I was still seeing values from the already-used SLSB before it was released by the container. Applying the @In(required=false) did fix it when I first tried it, but I had other problems too that needed to be resolved.
Since I didn't really need a SLSB at this point anyway, I converted CalculatorAction into a POJO, set it to event context and made some other tweaks once I had a better understanding of what was going on.
In addition to your comments, a couple of other things that helped me grasp this a bit better were these two quotes (in case others are trying to understand this better too):
From Seam reference docs (the last sentence here):
3.2.1. Stateless session beans
Stateless session bean components are not able to hold state across multiple invocations. Therefore, they usually work by operating upon the state of other components in the various Seam contexts. They may be used as JSF action listeners, but cannot provide properties to JSF components for display.From one of the Seam books:
BIJECTION WITH STATELESS SESSION BEANS
One thing that should be noted before we continue is that the bijection in Seam is actually very complex (in a good way). Case in point: how we deal with stateless session beans. If you have worked with them in the past, you are used to a simplistic model in which you send data to the SLSB, it performs some operation, and then you return data. You never have the SLSB access property-specific data on the SLSB. It is not safe to do so with SLSBs, unless the property is a global object such as a database connection or logger reference.
However, with Seam this methodology is thrown out the window a bit. Seam does not use a simplistic creation-time IoC. Instead the bijection happens at invocation. Therefore, the objects you are setting with @In or @Out to be injected or outjected are done at invocation, and when the method is complete, they are disinjected. This is what makes it safe for us in Seam to reference properties of the SLSB inside the methods.Those two sound a bit contradictory, but they both helped grasp the needed changes, along with your original comments. Thanks.