4 Replies Latest reply on Jun 30, 2007 11:14 PM by fhh

    How does one @In(ject) a component from components.xml?

    Troy Tarrrant Newbie


      I'm new to this but wouldn't have thought that this should proove to be so difficult.

      I have a seam component that requires the services of a components.xml object that implements the interface called PaymentService.

      Now when my seam app is deployed it recognizes the component as the following is output to the server console:

      17:18:22,310 INFO [Component] Component: paymentService, scope: APPLICATION, type: JAVA_BEAN, class: second_seam.MockPaymentService

      Now I wanted to use the payment services in my business object, so I did the following

      private PaymentService paymentService;

      Thinking that seam would find the object called paymentService and inject it into my business component. But it can't:

      First of all when I request a page that uses this buisness object, other properties on the object start reporting errors, like I've also got an expiryMonth field on the business object and seam reports this error relating to it

      17:18:23,845 ERROR [STDERR] Jun 30, 2007 5:18:23 PM com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View[/addcardPOJO.xhtml]
      javax.faces.el.EvaluationException: /cardfieldsPOJO.xhtml @51,106 value="#{cardFundingPOJO.expiryMonth}": Exception getting value of property expiryMonth of base of type : second_seam.CardFundingPOJO_$$_javassist_44

      And finally about three pages of stack trace you get..
      17:18:23,874 ERROR [DebugPageHandler] redirecting to debug page
      org.jboss.seam.RequiredException: In attribute requires non-null value: cardFundingPOJO.paymentService
      at org.jboss.seam.Component.getValueToInject(Component.java:1919)
      at org.jboss.seam.Component.injectAttributes(Component.java:1368)
      at org.jboss.seam.Component.inject(Component.java:1195)

      when I change the injection annotation to the following
      @In(value="paymentService", required=false)
      private PaymentService paymentService;

      it works of course until I need to use the paymentService because its null in value. (i.e. I did this to proove that the one change was causing the errors on the monthExpiry field)

      How does one simply inject a component from components.xml or is there another way to do this? (like I experimented with @Factory, but didn't have much luck with that either)

      Seam 1.2.1
      JBoss 4.0.5