我有一个州级。我需要会话范围中的两个新状态对象注入我的两个控制器中。每当创建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;
}
答案 0 :(得分:0)
想出来了。将@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;