Skip to main content

Posts

Showing posts from November, 2017

6. JSF: Weld CDI and Reflection. Using reflection on injected objects.

0. Introduction Weld and Reflection are not good friends. When you inject a bean into another, Weld CDI makes a proxy of the injected object. So when you want to obtain information using Reflection, you cannot see the original injected object. BalusC gives us the clue to introspect a Weld proxy bean. He uses BeanInfo Interface from the Java Beans API . By means of this Bean API, we can retrieve the original object from the proxy object. It is stored in the attribute  targetInstance . Once we have this original object, we can use reflection.  Note: To use Weld with Tomcat, we must include this dependency in the pom.xml file <!-- https: //mvnrepository.com/artifact/org.jboss.weld.servlet/weld-servlet-shaded --> < dependency > < groupId > org . jboss . weld . servlet </ groupId > < artifactId > weld - servlet - shaded </ artifactId > < version > 3.0 . 5 . Final </ version > </ dependency > 1. A