0

I am certain I have got this working in the past, but it doesn't want to work today.

Example:

@FacesConverter(value = "inputConverter")
public class InputConverter implements Converter {


    private InputRepository inputRepository;

    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {

        List<Input> allInputs = inputRepository.findAll();

        for(Input input : allInputs) {
            if(input.getInputName().equals(arg2)) {
                return input;
            }
        }
        return null;
    }

    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
        Input input = (Input) arg2;
        return input.getInputName();
    }


    public InputRepository getInputRepository() {
        return inputRepository;
    }

    @Inject
    public void setInputRepository(InputRepository inputRepository) {
        this.inputRepository = inputRepository;
    }

}

Result:

Null pointer exception on the itemRepository.findAll() call - the @Inject didn't set it.

8bitjunkie
  • 12,793
  • 9
  • 57
  • 70

1 Answers1

1

Answer found on another post: ManagedProperty not injected in @FacesConverter

As I am using @Inject and the injected JPA Repository is managed by Spring, it was neccessary to use @Component("itemConverter"), @Scope("session") instead of @ManagedBean.

Community
  • 1
  • 1
8bitjunkie
  • 12,793
  • 9
  • 57
  • 70