JoseK
JoseK

Reputation: 31371

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

Upvotes: 3

Views: 486

Answers (1)

Michael Borgwardt
Michael Borgwardt

Reputation: 346327

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).

Upvotes: 5

Related Questions