JSF 2 converters and Spring services
Updated: 2010-09-29
Problem:
I’ve a JavaServer Faces 2 converter (@FacesConverter) and I’ve to access a Spring service. The converter is managed by jsf and if I use @Service or a Spring bean I’ve a null pointer exception
Solution:
access the Spring service using FacesContextUtils. Ex:
@Override
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) {
...
if (personneService == null) {
personneService = (PersonneService) FacesContextUtils.getWebApplicationContext(facesContext).getBean("personneService");
...
}