-
1. Re: PoJo postInitialization
ssachtleben.ssachtleben.gmail.com Jun 19, 2011 1:41 PM (in response to soitseams)If you want to inject your pojo class you will need a producer like this:
@ApplicationScoped public class PojoProducer { private Pojo pojo; @Produces public Pojo getPojo() { return pojo; } public void onStartup(@Observes @Started WebApplication webApplication) { pojo = new Pojo(...); } }
Btw you dont need @Named on this class because you can directly use
#{pojo}
in facelets. -
2. Re: PoJo postInitialization
ssachtleben.ssachtleben.gmail.com Jun 20, 2011 3:41 AM (in response to soitseams)Ah sorry false information. You can Inject without @Named, because it is a managed bean anyways if you dont at @Veto to the class. But if you want to use it in facelets you will need to add @Named to the @Produces method.
Thats it :)
-
3. Re: PoJo postInitialization
lightguard Jun 21, 2011 4:46 AM (in response to soitseams)You could do a Producer like Sebastian is saying, but I think what you're looking for is something like this (if you're looking for the post construct per bean):
@Named @ApplicationScoped public class MyClass { @Inject public void myMethodName(any injections wanted as params) { ... } }
Basically any method annotated with @Inject (probably should be void, not 100% if that's required though) will be use for post construct. Best practice should not to use constructors for setup as they'll be called twice due to subclassing.