JSF 2 converters and Spring services

29 09 2010

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");
...
}

Advertisement

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.