1

I am migrating an old JSF application to newer versions. I have the problem with the lazyDataModel of Primefaces


@Configurable
public class PerfilSeleccionLazyDataModel extends LazyDataModel<Perfil> {

    @Autowired
    private transient PerfilService perfilService;

Now these classes do not inject services and are null

My new project is with Spring Boot, JoinFaces 4 and Spring 5.

Can someone tell me what new strategy I should use or if I should add some extra confirmation, so that my services are injected well?

Melloware
  • 10,435
  • 2
  • 32
  • 62
Jose
  • 1,779
  • 4
  • 26
  • 50

2 Answers2

1

I am using JoinFaces and here is what my LazyDatatable looks like. Use JSF ViewScoped on the bean and use normal Inject to inject the bean you want.

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 config:

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
Melloware
  • 10,435
  • 2
  • 32
  • 62
  • it is still null, it has some configuration in the .yml files or some bean for JSF / JoinFaces. Thank you. – Jose Oct 26 '20 at 14:42
  • I added my JoinFaces YAML config. Note I am using CDI and Myfaces Starters for JoinFaces. – Melloware Oct 26 '20 at 14:47
0

I faced the similar issue while using Spring-Boot-2.5.4 and JoinFaces_4.5.4. My solution is to pass the dependency from outside.

public class LazyProductsDataModel extends LazyDataModel<Product> {

private static final long serialVersionUID = 1L;

private transient ProductRepository productRepository;

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

and then in you can initialize it like this:

@Named
@ViewScoped
public class ProductListView {

@Autowired
private ProductRepository productRepository;
private LazyProductsDataModel lazyProductsDataModel;

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

}
Ashish
  • 198
  • 3
  • 11