Injecting ResourceBundle via @ManagedProperty doesn't seem to work inside @Named

后端 未结 3 897
眼角桃花
眼角桃花 2020-12-11 08:16

How can I access messages bundle from java code to get message according to current locale?

I tried using @ManagedProperty like below:

@         


        
3条回答
  •  佛祖请我去吃肉
    2020-12-11 08:36

    In addition to BalusC's answer:

    Since JSF 2.3 it is also possible to inject a resource bundle defined in faces-config.xml without the use of a producer method. There is a new annotation javax.faces.annotation.ManagedProperty (note it is in the ...annotation package, not the ...bean package) that works with @Inject:

    // ...
    import javax.faces.annotation.ManagedProperty;
    // ...
    
    @Named 
    @SessionScoped 
    public class UserBean implements Serializable {
    
      // ...
    
      @Inject
      @ManagedProperty("#{msg}")
      private ResourceBundle bundle;
    
      // ...
    
    }
    

提交回复
热议问题