2 Replies Latest reply on Jul 21, 2010 8:25 AM by pmuir

    How can I get instance from Bean?

    wuhaixing.wuhaixing.gmail.com

      Is there any way to get the underlaying object from the bean?
      I just try the portable extension's Wrapping an InjectionTarget,can I set field value in the processBean instead of processInjectionTarget?

        • 1. Re: How can I get instance from Bean?
          wuhaixing.wuhaixing.gmail.com

          ConfigTarget:


          @Model
          public class GalleryController {
               private @Inject Logger logger;
               
               private TreeNode root;
               private TreeNode selectedDocument;
               
               private @Configure String albumRoot;
               private @Configure Integer test;
          }




          ConfigExtension:


          public  <X> void processInjectionTarget(@Observes ProcessInjectionTarget<X> pit) {
                    final InjectionTarget<X> it = pit.getInjectionTarget();
                    InjectionTarget<X> wrapped = new InjectionTarget<X>() {
          
          
                      @Override
          
                      public void inject(X instance, CreationalContext<X> ctx) {
          
                          it.inject(instance, ctx);
                            for (Map.Entry<Field, Object> configuredValue : configuredValues.entrySet()) {
                                 try {
                                      configuredValue.getKey().set(instance,
                                                configuredValue.getValue());
                                 } catch (Exception e) {
                                      e.printStackTrace();
                                 }
                            }
          
                      }
          
          }




          exception :
          java.lang.IllegalArgumentException: Can not set java.lang.String field albumRoot to org.jboss.weld.extensions.log.LoggerProducer


          Is this a bug?

          • 2. Re: How can I get instance from Bean?
            pmuir

            Did you fix this, or still need help?