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
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With