首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JoinFaces @配置项不注入服务

JoinFaces @配置项不注入服务
EN

Stack Overflow用户
提问于 2020-10-26 17:10:09
回答 2查看 95关注 0票数 1

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

代码语言:javascript
复制
@Configurable
public class PerfilSeleccionLazyDataModel extends LazyDataModel<Perfil> {

    @Autowired
    private transient PerfilService perfilService;

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

我的新项目是Spring Boot,JoinFaces 4和Spring5。

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

EN

回答 2

Stack Overflow用户

发布于 2020-10-26 22:02:36

我使用的是JoinFaces,下面是我的LazyDatatable的样子。在bean上使用JSF,并使用normal ViewScoped注入您想要的bean。

代码语言:javascript
复制
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配置:

代码语言:javascript
复制
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
票数 1
EN

Stack Overflow用户

发布于 2021-11-04 11:24:51

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

代码语言:javascript
复制
public class LazyProductsDataModel extends LazyDataModel<Product> {

private static final long serialVersionUID = 1L;

private transient ProductRepository productRepository;

public LazyProductsDataModel(ProductRepository productRepository) {
    this.productRepository = productRepository;
}
} 

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

代码语言:javascript
复制
@Named
@ViewScoped
public class ProductListView {

@Autowired
private ProductRepository productRepository;
private LazyProductsDataModel lazyProductsDataModel;

@PostConstruct
private void init() {
    lazyProductsDataModel = new LazyProductsDataModel(productRepository);
    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64534203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档