Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF Spring injection via XML or code

I've inherited some JSF Spring code, and can see instead of injecting the Spring beans via the faces-config.xml as

<managed-bean>

the team have done it in the code as

FacesContext facesContext = FacesContext.getCurrentInstance();
    ELResolver elResolver = facesContext.getApplication().getELResolver();
    MyClass myBean = (MyClass) elResolver.getValue(facesContext.getELContext(), null,ApplicationConstants.MY_BEAN_NAME);

I would prefer doing this in the xml - is there any advantage of that or is it no big deal at all?

Versions are JSF 1.2 and Spring 3

like image 899
JoseK Avatar asked Jul 16 '26 18:07

JoseK


1 Answers

Perhaps they just don't like XML?

Personally, I'd use annotation-based dependency injection wherever possible, instead of XML configuration or code.

However, there is one case where the code-based approach is the only one that works: when you have a managed bean with larger scope (e.g. session or even application) and it one of its actions need access to a managed bean with smaller scope (e.g. request).

like image 51
Michael Borgwardt Avatar answered Jul 18 '26 08:07

Michael Borgwardt