开发者

Bind Same Seam Class to different Context Variables

I have a state class. I need two new state objects in session scope to be injected in two of my controllers. Whenever mycontroller is created, I want the state objected to be instantiated. When I use the syntax below, I get the same state object injected in both the controllers.

I want something equivalent to

session.setAttribute("myFirstControllerState", myScreenStateObj1);
session.setAttribute("mySecondControllerState", myScreenStateObj2);


@SuppressWarnings("serial")
@开发者_Go百科AutoCreate
@Name("myScreenState")
@Scope(ScopeType.SESSION)

public class MyScreenState implements Serializable {

}

@AutoCreate
@Name("myFirstScreenController")
@Scope(ScopeType.PAGE)
@SuppressWarnings("serial")

public class MyFirstController implements Serializable {
   @In(value="myScreenState")
   @Out(value="myScreenState")
   private MyScreenState myFirstControllerState;
}

@AutoCreate
@Name("mySecondScreenController")
@Scope(ScopeType.PAGE)
@SuppressWarnings("serial")

public class MySecondController implements Serializable {

    @In(value="myScreenState")
    @Out( value="myScreenState")
    private MyScreenState mySecondControllerState;
}


Figured this out. Add @Roles annotation to the state class.

@SuppressWarnings("serial")
@AutoCreate
@Name("myScreenState")
@Scope(ScopeType.SESSION)
@Roles({@Role(name="myState1", scope=ScopeType.PAGE),  
    @Role(name="myState2",scope=ScopeType.PAGE)})

public class MyScreenState implements Serializable {

}

In controllers just use

private MyScreenState myState1; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜