将相同的Seam类绑定到不同的上下文变量

时间:2011-07-14 01:32:27

标签: jsf seam

我有一个州级。我需要会话范围中的两个新状态对象注入我的两个控制器中。每当创建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;
}

1 个答案:

答案 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; 
相关问题