views:

82

answers:

1

Hi all,

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!

+4  A: 

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 :)

volothamp