Pages

Wednesday, December 5, 2012

Migration from JSF 1.x to JSF 2

This is one of the things you have to change when migrating your JSF-Spring application from JSF 1.x to JSF 2.

In JSF 1.x, to get access to a spring bean in a backing bean or in a converter, you would do:

FacesContext context = FacesContext.getCurrentInstance();
MyService myService = (MyService) context.getApplication().createValueBinding("#myService}").getValue(context);

In JSF 2 this is replaced by:

FacesContext context = FacesContext.getCurrentInstance();
MyService myService = (MyService) context.getELContext().getELResolver().getValue(context.getELContext(), null, "myService");


Another way to do it would be:

FacesContext context = FacesContext.getCurrentInstance();
String remoteUser = context.getApplication().evaluateExpressionGet(context, "#myService.currentUser}", String.class);




3 comments: