I would like to achieve this idealism :
- To have only 1 implementation for the JSF Bean container, like to use only Spring or Weld but not both. Currently i am using Spring for my backend, so i prefer Spring.
- To have only 1 annotation, to choose between @ManagedBean, @Named, @Model
- To be able to use all supported scopes, like @RequestScoped, @SessionScoped, @ViewScoped, @FlashScoped, maybe also @ConversationScoped
- The JSF Beans could be injected with spring-managed-services (The backend services), perhaps using @Inject or @Autowired
So far i've been finding no best combination to achieve these because as far as i know, please correct me if i am wrong, :
- @ManagedBean can not be injected with spring services ?
- @Named can be injected with spring services using @Inject, but @Named is using Weld. Can i just use spring to managed the @Named instead of Weld ?
- @Named doesnt support @ViewScoped and FlashScope ?
Please share your thoughts and experiences.
Thank you :-)
UPDATE 15 March 2011
Found an interesting page that describes how to replace Jboss Weld with Spring as the JSR 299 CDI implementation. So basically, the question number 2 is answered. Number 1 is also answered indirectly since i can now inject spring services.
But still, the number 3 question remains. I would find very helpful if i can use the @ViewScoped and Flash Scope in the @Named, something like this article. Flash scope implementation has yet to be seen, but the closest one i can get so far is this page.
Hopefully, replacing weld with spring as the jsr 299 implementation will still enable me to use @ConversationScoped.
Gotta test things now, wish me luck :-)
UPDATE 18 MARCH 2011
Successfully make use of Spring 3 instead of weld to do the @Named, @Inject. The important thing is to set the el-resolver in the faces-config.xml.
AFAIK, Spring 3 currently doesnt support CDI yet, so bye2 @ConversationScoped.
For the scoping, i must still use @Scope("request") or @Scope("session"), but if i prefer the @RequestScoped (javax.enterprise.context.RequestScoped) and @SessionScoped, i can make use of the bridge provided from this article.
The Scope("view") for spring from this article works like magic :-)
One problem remain though, how to pass objects between Scope("view")-beans .. Wish me luck !
update
Ahhh .. finally done .. Passing the variables using Flash provided by JSF2 really works like magic. I dont need an 3rd party implementation for that.
So basically, i can do without weld, but with spring, with the common scopes available, including the view scope, dan can pass between beans using the flash object.
One thing missing is the conversation scope, which isnt a major problem to me yet. Hopefully the future spring can support this conversation scope.
Cheers :-)