1

I've been working on a web application that loads some xhtml files inside a jar. With this, I didn't have any problems.
I placed a faces-config.xml in each jar, placed the corresponding xhtml files and everything was working flawlessly with a customResourceResolver that does the search in the classpath. The problem came up when I added Spring into the equation, as the following example shows:

<managed-bean>
    <managed-bean-name>entityController</managed-bean-name>
    <managed-bean-class>com.test.EntityController</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
        <property-name>client</property-name>
        <value>#{client}</value>
    </managed-property>
</managed-bean>

Where client is an entity inside the Spring context.

I already have configured the corresponding listeners and web.xml for Spring, and for all the managed beans contained in the WAR the injection is working.

No error is being thrown at startup, and all the Spring beans are getting properly loaded. However, when I invoke the method of the managed bean that's contained in the jar, which has to access the managed property, I find that the property was not injected.

Am I missing something?

Let me know if further information is required.

Thanks a lot in advance!

LdSe
  • 334
  • 1
  • 3
  • 17
  • You can have plenty access to your spring context from JSF view, using @autowire annotation. [Have a look](http://stackoverflow.com/questions/8925170/jsf-2-inject-spring-bean-service-with-managedproperty-and-no-xml). – Aritz Jul 02 '13 at 19:52
  • Hi, thanks for your response. What if I'm doing the wiring via XML? – LdSe Jul 02 '13 at 20:50

1 Answers1

2

Been able to sort it out using JSF annotations instead of the configuration in faces-config.xml.

So my managed bean ended up pretty much like this one:

@ManagedBean(name="entityController")  
@SessionScoped
public class EntityController {

   @ManagedProperty("#{client}")
   private Client client;

Thanks everyone!

LdSe
  • 334
  • 1
  • 3
  • 17
  • That doesn't work for me with `@ViewScoped` beans. A workaround for me is to have an `@ApplicationScoped` bean which accesses the spring context (not using annotations, but loading the context and getting the bean programatically when application starts). Then, I just inject this bean as a property in all my view beans. I'm curious about if your solution loads the whole context per session once and again. Good luck! – Aritz Jul 03 '13 at 07:17
  • I just changed the scope of the bean in my example to @ViewScoped and the Spring bean got injected as well. I can certainly check if the whole context is getting loaded by session, any quick way to verify that? Thanks! – LdSe Jul 03 '13 at 13:10
  • If it gets injected with `@ViewScoped`, just check if spring if writing its initialization logs in your console every time you render your view. – Aritz Jul 03 '13 at 13:13