Pojo or stateful EJB destroyed immediatly if using conversat
ktof0001 Jun 9, 2006 7:21 PMI can travel sucessfully through a tree, by using a stateless EJB(BrowseAction) action that updates a named Pojo(State). keeping the state. Everything session scope (!).
In order to allow multiple windows browsing at the same time, I am trying to use conversations(!). A quick solution without changing much code: action starts up a conversation in the state object.
***BrowseAction:***
@Stateful //tried stateful too
@Name("treeSelector")
public class BrowseAction implements Browse{
//@Out(scope=ScopeType.CONVERSATION)
@In(scope=ScopeType.CONVERSATION, value="#{state}") @Out(scope=ScopeType.CONVERSATION)
private State state;
public String changeTree() {
state.startConversation();
...
state.setNode(new-node-id);
return nextPage();
}
and
***State: ***
@Scope(ScopeType.CONVERSATION)
@Stateful
@Name("state")
@Conversational(ifNotBegunOutcome="home")
@Interceptors(SeamInterceptor.class)
public class StateSB implements Serializable, State{
...
@Begin
public void startConversation() {
System.out.println("state:startConversation:"+this);
}
@End
public void endConversation() {
System.out.println("state:endConversation");
}
public StateSB() {
super();
System.out.println("....Creating State:"+this);
}
@Remove @Destroy
public void destroy() {System.out.println("+++++++++ destroying state" );}
With this code or all small alternatives (See @In attribs) I tried, I notice that when I use "Scope.conversational", my state object is being destroyed after my changeTree is being called & executed correctly. I.e. the state seems to be never really saved back into the context (so, I got fresh page each time). I thought the destroy is maybe inited from the BrowseAction, which is why I tried that one to be stateful... If I change state to SESSION again, everything works fine, no destructions (but then 2 windows are not browsing independent)
Same thing did not work leaving the State object as a POJO (cfr. 'numberguess'example Seam doc, but then without using pageflow attrib. (is this required?) )
By the way, is it correct to use stateful EJB versus named POJOs when there is more functionality than getters&setters?
This was intended to be a quick enhancement.. but I can't get it working :(