【问题标题】:JoinFaces @Configurable does not inject servicesJoinFaces @Configurable 不注入服务
【发布时间】:2021-02-08 12:54:03
【问题描述】:

我正在将旧的 JSF 应用程序迁移到较新的版本。 我对 Primefaces 的lazyDataModel 有问题


@Configurable
public class PerfilSeleccionLazyDataModel extends LazyDataModel<Perfil> {

    @Autowired
    private transient PerfilService perfilService;

现在这些类不注入服务并且为空

我的新项目是使用 Spring Boot、JoinFaces 4 和 Spring 5。

谁能告诉我我应该使用什么新策略,或者我是否应该添加一些额外的确认,以便我的服务注入良好?

【问题讨论】:

    标签: jsf primefaces joinfaces


    【解决方案1】:

    我正在使用 JoinFaces,这是我的 LazyDatatable 的样子。在 bean 上使用 JSF ViewScoped 并使用普通 Inject 来注入你想要的 bean。

    import javax.faces.view.ViewScoped;
    import javax.inject.Inject;
    import javax.inject.Named;
    
    @Named
    @ViewScoped
    public class PerfilDatatable extends LazyDataModel<Perfil> {
    
        @Inject
        private transient PerfilService perfilService;
    

    JoinFaces 配置:

    joinfaces:
      jsf:
        project-stage: Development
        state-saving-method: server
        facelets-refresh-period: -1
        facelets-skip-comments: true
        interpret-empty-string-submitted-values-as-null: true
        datetimeconverter-default-timezone-is-system-timezone: true
      primefaces:
        theme: babylon-bluegrey-accent
        font-awesome: true
        transform-metadata: true
        move-scripts-to-bottom: true
        submit: partial
      omnifaces:
        combined-resource-handler-cache-ttl: 3628800
        combined-resource-handler-disabled: true
      myfaces:
        support-managed-beans: false
        early-flush-enabled: true
        check-id-production-mode: false
    

    【讨论】:

    • 它仍然为空,它在 .yml 文件或 JSF / JoinFaces 的某些 bean 中有一些配置。谢谢。
    • 我添加了我的 JoinFaces YAML 配置。注意我正在使用 CDI 和 Myfaces Starters 进行 JoinFaces。
    【解决方案2】:

    我在使用 Spring-Boot-2.5.4 和 JoinFaces_4.5.4 时遇到了类似的问题。我的解决方案是从外部传递依赖。

    public class LazyProductsDataModel extends LazyDataModel<Product> {
    
    private static final long serialVersionUID = 1L;
    
    private transient ProductRepository productRepository;
    
    public LazyProductsDataModel(ProductRepository productRepository) {
        this.productRepository = productRepository;
    }
    } 
    

    然后你可以像这样初始化它:

    @Named
    @ViewScoped
    public class ProductListView {
    
    @Autowired
    private ProductRepository productRepository;
    private LazyProductsDataModel lazyProductsDataModel;
    
    @PostConstruct
    private void init() {
        lazyProductsDataModel = new LazyProductsDataModel(productRepository);
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2022-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-09
      • 1970-01-01
      • 2016-07-07
      • 1970-01-01
      • 2014-09-19
      相关资源
      最近更新 更多