多个相同类型的@ManagedProperty

Multiple @ManagedProperty of same Type

我有一个托管 bean,我在其中使用了另一个托管 bean:

@ManagedProperty(value="#{tableActions}") 
private TableActions table1;    

效果不错。

现在我需要使用它的另一个实例:

@ManagedProperty(value="#{tableActions}") 
private TableActions table1;    

@ManagedProperty(value="#{tableActions}") 
private TableActions table2;    

但是,现在 table2table1 相同。如何创建单独的实例?

让它成为 @NoneScoped 个 bean。

您只需确保通过 #{yourParentBean.table1} 而不是通过 #{tableActions} 在视图中访问它。

另请参阅:

  • what is none scope bean and when to use it?
  • How to choose the right bean scope?