-
1. Re: How can session beans share objects?
amarkhel Mar 12, 2010 8:32 AM (in response to peterlen)1. ExceptionMessageHandler has @Name annotation?
2. You can use @In(require=false, create=true) ExceptionMessageHandler messageHandler;
-
2. Re: How can session beans share objects?
peterlen Mar 12, 2010 9:14 AM (in response to amarkhel)Andrey - Thanks for the reply. I am unsure about what your reference to a @Name annotation is. I don't list a @Name annotation. Are you saying that I should? For #2, I had declared it earlier like:
@In(create=true) ExceptionMessageHandler messageHandler;
But I get the same error. I am wondering if both beans need the @In and @Out annotations but, again, an unsure about how these annotations really work in my scenario.
-
3. Re: How can session beans share objects?
amarkhel Mar 12, 2010 2:55 PM (in response to peterlen)Every component, that you wan't put in any Context(request, session etc..) by @Out annotation, should have @Name annotation. Are your ExceptionMessageHandler bean has this annotation?
And can you try @Autocreate annotation on your ExceptionMessageHandler? This annotation tell Seam, that component should be created by demand.
And what scopes you use for all that beans(beanA, beanB, ExceptionMessageHandler)?
-
4. Re: How can session beans share objects?
peterlen Mar 12, 2010 3:16 PM (in response to amarkhel)Andrey,
This is where it is confusing to me. Let me explain it a little better then I previous did.
Two of my beans (Bean A and Bean B) are session beans and each uses the @Name annotation. Each of these beans are "connected" to my facelets page (my .xhtml file). Depending on what the user does on the page, Bean A might be called or Bean B might be called. These are typically a4j type calls. I have a third bean which is also a session bean with a @Name annotation. This third Bean (UtilityBean) is where I declared my
@Out
ExceptionMessageHandler messageHandler;
ExceptionMessageHandler is just a POJO with a couple of getters/setters.
My goal was trying to find a way that allowed these session beans to share a common object (ie the messageHandler). I thought that the @In and @Out annotations were used for this purpose, but I am thinking that those annotations are for injection/outjection between a given bean and the client web page rather than for one bean to set a value on an object that is accessible in another bean.
Maybe I should never have listed the @In and @Out annotations in my original posting to keep any confusion out. So, do you know if the @In and @Out annotations can be used to "pass" object values between session beans? Essentially this would give access to one instance of a variable to different beans to set/get values.
- Peter
-
5. Re: How can session beans share objects?
amarkhel Mar 15, 2010 10:06 AM (in response to peterlen)Hi, Peter.
To solve your problem your shouldn't use MessageNandler as one of fields of other session bean. Why you won't use messageHandler as undependent component(with @Name and @scope annotation)? Then you could inject it in all other beans through @In, and if you change state of messageHandler @Out annotation?
Simple Use case..
@Name("messageHandler")
@Scope(SESSION)
@AutoCreate
public class MessageHandler
....
@Name("beanA")
@Scope(SESSION)
BeanA{
@In MessageHandler messageHandler(only @In annotation if you won't change the state messageHandler)
....
public String getInfo(){
return messageHandler.getInfo();
}
@Name("beanB")
@Scope(SESSION)
BeanB{
@In @Out MessageHandler messageHandler(in case where you want change the state messageHandler)
public String getInfo(){
return messageHandler.getInfo();
}
public void setInfo(String info){
messageHandler.setInfo(info);
}
NOTE: @In and @Out annotation on class work after call on each method of this class.
So, after call beanB.setInfo(info), when you change state of messageHandler, @Out annotation push your messageHandler in session context.
-
6. Re: How can session beans share objects?
peterlen Mar 15, 2010 12:20 PM (in response to amarkhel)Andrey,
Part of my problem was not fully understanding the usage of the @In and @Out. I just tried what you listed in your last reply and it works just fine. I appreciate your time and effort in helping with this.
Thanks - Peter