

JSF 2 converters and Spring services
source link: https://marco.dev/2010/09/29/jsf-2-converters-and-spring-services/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

java-version.com: What's new in Java 16? 15? Keep up to date!
JSF 2 converters and Spring services
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:
<br />
@Override<br />
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) {<br />
...<br />
if (personneService == null)<br />
personneService = (PersonneService) FacesContextUtils.getWebApplicationContext(facesContext).getBean("personneService");<br />
...<br />
}<br />
Author
Marco Molteni
Marco Molteni Blog
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK