[JBoss Seam] - Re: Bug? Outjected boolean changes value mid-template
by tomstrummer
Hi Pete -- thanks for your reply.
"pete.muir(a)jboss.org" wrote : 1) If you have an @Stateless bean it can't have any fields on it. read about what @Stateless *really* means (this probably explains your values changing)
I understand that I can't keep state in my SLSB, but I thought the point was that you could biject stateful values into your SLSBs. See http://books.google.com/books?id=h1madTvupB8C&pg=PA162&vq=listing+6-2&sig...
"pete.muir(a)jboss.org" wrote :
| 2) This is because you are outjecting into EVENT scope. So, the process is this whilst rendering the page
|
| Try to access boolean value, not in context, so null and so on
| Render datatable, initialized by @Factory on seam component as boolean value. component does outjection including boolean value,
| Try to access boolean value, now in context.
I can understand that it is null at the beginning of the request (since there is no @Factory for it) but if the value is not explicitly set in an action, the value should remain null. That is, I would expect Seam's bijection mechanism to say "oh this value was set on a previous request so it is out of scope now" rather than suddenly finding the value when a totally different context variable is asked for from the context.
So I think I understand -- the SLSB is actually maintaining state even though bijection would make it seem that it is not so. It would seem to me that bijection is broken by design unless a factory is not specified for each and every bijected field. No?
This does happen just the same if the fields are PAGE scoped -- i.e. the value is set to true, go to a different page, come back, and the same behavior (null, then old stale value) appears. I imagine it would also happen as well for a SFSB -- Say you have a session-scoped SFSB, and say an @Out(scope=PAGE) List myList. If I don't have a factory for myList, and instead initialize the list on some action. Then leave this page and come back... I'll see the list again after something else wakes up that SFSB? If that is the case I would argue that it is broken.
More to the point, how would you get around this issue? How would you toggle a flag to show a simple form that you want to automatically reset if the user leaves the page or does something else?
* Put an auto-action in pages.xml to reset everything? That seems annoying but doable (I have a number of pages that use this pattern)
* Use a conversation? It seems like overkill for just one stateful flag. And if they do _anything_ else, I have to make sure that conversation ends, no? How do I make sure the conversation ends if they decide to do something totally unrelated to the conversation?
* Create a factory that simply returns null or false in order to reset the value? I'm guessing the factory will definitely be called when the value is re-referenced after it goes out of scope!?! But it turns out in my non-simplified, real world code I actually have two flags for different forms, and then two more flags for whether or not they are new or updated domain objects. So suddenly I have to create four factories just initialize a couple of boolean fields. This is annoying.
What if Seam had some sort of implicit "null factory" that would automatically reset bijected values that went out of scope? That would fix my problem.
What do you think? I'm dealing with such a simple state that all of Seam's state management mechanisms are overkill. It seems to be making things harder, whereas if I was using an MVC framework, I would just put a showForm:true flag in my model, which of course is gone after the response is rendered.
Suggestions?
Thanks.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4127486#4127486
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4127486
18 years, 2 months
[JBoss Seam] - Re: When to use @PersistenceContext vrs @In EntityManager (S
by kasim
"msystems" wrote : Use @PersistenceContext if you are using EJB3 and if you need a new transaction (@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) ) - Seam ref:
|
| anonymous wrote :
| | If you are using EJB3 and mark your class or method @TransactionAttribute(REQUIRES_NEW) then the trans-
| | action and persistence context shouldn't be propagated to method calls on this object. However as the Seam-
| | managed persistence context is propagated to any component within the conversation, it will be propagated to
| | methods marked REQUIRES_NEW. Therefore, if you mark a method REQUIRES_NEW then you should access the en-
| | tity manager using @PersistenceContext.
| |
|
| otherwise use SMPC.
|
What you are saying at the top part is true.
However i don't believe the doco is saying use SMPC all the time.
Take a look at the first paragraph of the section. It basically refers to if you are using the component outside of a Java EE5 environment or if you have many loosly coupled components. Which as long as they are all SB the PersisetnceCOntext should transfer. However the doco is 100% right if you are going to have a mix of SB and POJOS .... then yeah doing the EntityManager injection is the only way to go.
So you can stick with the @PersistenceContext in most situations. Its going to be a situation where you are wanting to transact against non-EJB components you will want to use the @IN EntityManger.
Of course that being said i am not sure the harm it would cause using the @In EntityManager more often.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4127483#4127483
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4127483
18 years, 2 months