-
1. Re: JSF2 ViewScope in CDI
nickarls Dec 28, 2009 5:13 PM (in response to alexanderbell)Module to be
-
2. Re: JSF2 ViewScope in CDI
alexanderbell Dec 28, 2009 9:15 PM (in response to alexanderbell)thanks nicklas, looks good.
so for now I have to include seam2 or are there anyweld-ext
libraries?BTW what is the FlashScope?
Alex
-
-
4. Re: JSF2 ViewScope in CDI
verborghs Jan 7, 2010 12:17 PM (in response to alexanderbell)i wrote a small howto on how to create a custom context in CDI. As an example I ported the JSF ViewScoped annotation to CDI by means of a custom context. It is not really that hard to understand. If you have any questions just ask... The example might be useful until seam 3 gets released.
-
5. Re: JSF2 ViewScope in CDI
gavin.king Jan 7, 2010 7:08 PM (in response to alexanderbell)Looks good, I hope you can contribute the code to Seam3. I'll link this tutorial on our blog.
-
6. Re: JSF2 ViewScope in CDI
alexanderbell Jan 8, 2010 5:10 PM (in response to alexanderbell)pretty cool, thanks steven
-
7. Re: JSF2 ViewScope in CDI
nickarls Jan 11, 2010 8:09 AM (in response to alexanderbell)Is there any way to observe when the view has been destroyed so that the context is properly cleaned out?
There is a JSF 2 event fired when a custom scope is being destroyed but is that triggered on @ViewScope (the JSF variant)? You might be able to sneak in a bean which takes down the context in the @PreDestroy but that sounds a bit hackish. Does JSF call any @PreDestroy on context stuff when it deconstructs it? And does it require some hook with @CustomScoped?
The duplication of scopes and managed beans in JSF and CDI is a bit confusing at a quick glance.
-
8. Re: JSF2 ViewScope in CDI
verborghs Jan 14, 2010 10:25 PM (in response to alexanderbell)I had a quick look at the api and there seems to be a PreDestroyViewMapEvent. I assume that JSF calls the lifecycle callbacks on beans with the javax.faces.ManagedBean annotation(, but when using a CDI context and @Named annotation I would think this (should) get handled by CDI?)
-
9. Re: JSF2 ViewScope in CDI
macros14 Mar 2, 2010 9:02 PM (in response to alexanderbell)I tried using Steven Verborgh example of doing a port of the JSF viewscope. I have it almost working, but I am not sure on his last point of
All that we now need to do is provide a file with the name
javax.enterprise.inject.spi.Extension
in theMETA-INF/services
folder of you application in order to allow the java ServiceLoader that weld uses to load the extension.I created this file, but I didn't put anything in the file (does something need to be put in the file?)?
I end up getting the following exception.
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: No active contexts for scope type faces.ViewScoped
root cause
javax.enterprise.context.ContextNotActiveException: No active contexts for scope type faces.ViewScoped
note The full stack traces of the exception and its root causes are available in the GlassFish v3 logs.
-
10. Re: JSF2 ViewScope in CDI
jpleed3.john.leediii.minitmarkets.com Mar 2, 2010 10:57 PM (in response to alexanderbell)
I created this file, but I didn't put anything in the file (does something need to be put in the file?)?I have 4 files for implementing ViewScoped:
- the ViewScoped annotation
- ViewContext, which implements javax.enterprise.context.spi.Context.
- ViewContextExtension, which implements javax.enterprise.inject.spi.Extension
- META-INF/services/javax.enterprise.inject.spi.Extension, which contains the fully qualified class name of item 3 and nothing else.
-
11. Re: JSF2 ViewScope in CDI
verborghs Mar 9, 2010 9:57 AM (in response to alexanderbell)I put the code online at GitHub - Verborghs together with some other extensions I use in my courses (@ELValue [cfr. JSF @ManagedProperty], @FlashScoped, @Flash, ...). I tried integrating them in seam 3 but since the faces module didn't/doesn't compile at the time of trying I haven't contributed them yet but as far as I care you do what you want with them. If I find some time I'll add some unit tests.
-
12. Re: JSF2 ViewScope in CDI
asermej Mar 11, 2010 2:49 PM (in response to alexanderbell)Great post on ViewScope it worked for me! Any serious JSF 2.0 application using Weld is going to need this. Is the first time we are going to see an official release of this functionality going to be in seam 3, or might we see it earlier in some sort of portable extension release?
Just to be clear, the ultimate idea is that when using weld scopes, you shouldn't be using any of the JSF scopes, if you want injection to work properly? I think that because some JSF scope equivalents are missing from Weld, and I understand why, it is leading to confusion over there being two separate definitions of scopes: JSF's and Weld's.
I guess my recommendation is that there should be a separate portable extension jar for users who would like to use Weld with JSF 2.0 without having to wait for seam 3.0 or to use the entirety of seam 3.0 when it does get here.
-
13. Re: JSF2 ViewScope in CDI
lincolnthree Mar 16, 2010 9:35 PM (in response to alexanderbell)The preferred usage would be to avoid any and all JSF @...Scope annotations, certainly @ManagedBean should be avoided in all cases -- use @Named instead, but unfortunately with @ViewScoped and @FlashScoped, these are JSF specific features, and probably belong in the javax.faces namespace.
We're prototyping this functionality in Seam 3 now: Seam 3 Faces - Scopes Support
The Seam 3 Faces module will be completely portable and will not depend on the entirety of Seam 3's Modules - part of the new architecture for Seam 3, because people rarely need all of Seam at once -- it just does too much ;)
When you think of Seam 3, think of small, portable, modular extensions to bridge the gap between CDI, and other JEE technologies such as JMS, JSF, EJB, JPA, and other helpful things :)
I'm hoping to have a snapshot of this functionality out as soon as possible, since it should be just about done now. Keep your eyes peeled. Follow @jbossseam on twitter, or follow me @lincolnthree for updates -- or just keep your eyes peeled on seamframework.org :)
-
14. Re: JSF2 ViewScope in CDI
lincolnthree Mar 16, 2010 9:39 PM (in response to alexanderbell)Also, if any of you guys want to get involved in the development of said Seam 3 Faces module -- feel free, let me know! The SVN repo is located here(1) and should be buildable from now on ;) I had a little cleaning up to do when I took over / started over.
(1) http://anonsvn.jboss.org/repos/seam/modules/faces/trunk/
(2) http://seamframework.org/Documentation/Seam3FacesModuleDesignNotes