1

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


@Configurable
public class PerfilSeleccionLazyDataModel extends LazyDataModel<Perfil> {

    @Autowired
    private transient PerfilService perfilService;

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

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

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

4

2 回答 2

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
于 2020-10-26T14:02:36.030 回答
0

我在使用 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);
    }

}
于 2021-11-04T11:24:51.347 回答