3

I cannot seem to be able to inject a Seam component inside the @Create method. I cannot find in the documentation any hint that this is not possible, which would verify whether I am making a mistake or not.

Is it possible to inject inside the @Create?

Cheers!

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Markos Fragkakis
  • 7,499
  • 18
  • 65
  • 103

1 Answers1

5

Yes, you can. It's in the constructor that you can't use it.

import org.jboss.seam.Component;
import org.jboss.seam.annotations.*;
import org.jboss.seam.log.Log;

@Name("foo")
@AutoCreate
public class Foo {
    @Logger Log log;
    @In Bar bar;

    @Create
    public void init()  {
        log.info("Init: #0", bar);
        log.info("Init: #0", Component.getInstance("bar"));
    }
}




import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;

@Name("bar")
@AutoCreate
public class Bar { }

And you're right, apparently in the seam documentation it's not written. But I think supporting injection is the main reason why the @Create annotations has been created.

Sometime a simple prototype is what you need :)

Luca Molteni
  • 5,230
  • 5
  • 34
  • 42
  • Another undocumented caveat: **Make sure the method annotated with `@Create` is *not* `final`.** That keyword may lead to inconsistencies if you have `private` properties and other stuff. Just avoid it altogether. – acdcjunior Sep 09 '13 at 12:44