How to inject entire managed bean via @ManagedProperty annotation?

后端 未结 1 894
栀梦
栀梦 2020-12-09 04:44

I\'m trying to inject entire JSF managed bean into another managed bean by means of @ManagedProperty annotation (very similar to Possible to inject @ManagedBean

相关标签:
1条回答
  • 2020-12-09 05:25

    You need to add setters and getters

    @ManagedBean
    public class Foo {
      @ManagedProperty(value = "#{bar}")
      private Bar bar;
      //add setters and getters for bar
      public Bar getBar(){
          return this.bar;
      }
      public void setBar(Bar bar){
          this.bar = bar;;
      }
    }
    

    When the FacesContext will resolve and inject dependencies it will use setters injection so appropriate setters/getters should be there.otherwise it won't find the property

    0 讨论(0)
提交回复
热议问题