Can't use Object in producer methods
agori Dec 30, 2009 11:49 AMI have this producer method:
@Produces @Param("") public Object getParamValue(FacesContext fc, InjectionPoint ip) { ... return new Integer(...); }
As you can see the return type is Object, but It can return an Integer or String or instances of other classes, based on some logic (I should use the injection point to coerce or convert to the right type).
Then I have an observer method like this:
public void action(@Observes ... myEVent, @Param("id") Integer id) { ... }
second parameter injection doesn't work because I get this exception:
javax.enterprise.inject.UnsatisfiedResolutionException: class java.lang.Integer; binding types = [@Param]Unable to resolve any Managed Beans at org.jboss.weld.BeanManagerImpl.getBean(BeanManagerImpl.java:996) at org.jboss.weld.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:966) at org.jboss.weld.injection.ParameterInjectionPoint.getValueToInject(ParameterInjectionPoint.java:84) at org.jboss.weld.injection.MethodInjectionPoint.getParameterValues(MethodInjectionPoint.java:268) at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:178) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:221) at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:196) at org.jboss.weld.BeanManagerImpl.notifyObservers(BeanManagerImpl.java:844) at org.jboss.weld.BeanManagerImpl.fireEvent(BeanManagerImpl.java:837) at org.jboss.weld.BeanManagerImpl.fireEvent(BeanManagerImpl.java:831) at agori.example.RestFacesPhaseListener.beforePhase(RestFacesPhaseListener.java:21) at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:212) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:95) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:311) ...
If I change the return type of producer method to Integer (matching the one in the observer method), everything works.
Why I can't use Object here?