我上州立大学的课。我需要会话作用域中的两个新状态对象注入到我的两个控制器中。每当创建mycontroller时,我都希望实例化对象的状态。当我使用下面的语法时,我在两个控制器中都注入了相同的状态对象。
我想要等同于
session.setAttribute("myFirstControllerState", myScreenStateObj1);
session.setAttribute("mySecondControllerState", myScreenStateObj2);
@SuppressWarnings("serial")
@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;
}发布于 2011-07-15 03:07:09
我想通了。将@Roles注释添加到状态类。
@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 {
}在控制器中只需使用
private MyScreenState myState1; https://stackoverflow.com/questions/6687536
复制相似问题