WELD-001303 No active contexts for scope type javax.faces.bean.ViewScoped
March 2, 2012 at 12:27 am #18186
My site used JSF1.2 and Mojara Scales in the past to deliver (basic) pretty urls. When migrating to JSF2+, wrapping the HttpServletRequest isn’t possible anymore. So I started using Rewrite.
My setup is Glassfish 3.1.2, Richfaces 4.1, JSF2.1, Weld 1.1.4, SeamFaces 3.1.0 and Rewrite Alpha11.
Besides for Rewrite, I use Seam Faces because it enables @ViewScoped to be CDI-managed. Actually @ConversationScoped doesn’t do everything I want and @ViewScoped is the closest to what a4j:keepAlive did in RichFaces 3.3 in the past. Easier migration for me.
With simple URLs, Rewrite works perfect.
The only issue I have is exception swallowing. I read other posts on this forum, and I @HandlesExceptions them now. Annoying but I’ll survive.
Now I’m trying to inject arguments:
The blogView is @ViewScoped. And that’s where it blows up. I’ve searched, I’m out of ideas. Lincoln, Christian, do you have any hint?
INFO: WELD-001303 No active contexts for scope type javax.faces.bean.ViewScoped
GRAVE: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.faces.bean.ViewScoped
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.Thread.run(Thread.java:662)March 2, 2012 at 6:41 am #22191
Yes. Rewrite operates in a ServletFilter, meaning that JSF has not yet begun its lifecycle, thus, the bean does not yet exist because as the exception suggests, the context has not yet been started.
You would need to add a deferred injection in order for this to work. In fact, that’s a feature we need. You’d have to cache the values to be injected, then do the injection in a PhaseListener. We should add this functionality to Rewrite JSF Integration.
Is this something you’d be interested in prototyping?
~LincolnMarch 2, 2012 at 6:46 am #22192
In fact, you can see how this was implemented for PhaseAction, because the PrettyPhaseListener already does the exact same type of caching. You could even add a feature that allows you to specify in which Phase you want the injection to occur!March 2, 2012 at 7:32 am #22193
Thank you. Of course. I remember the Rewrite code now…
Yes I’m interested in adding that feature, but for a ton of reasons including a small baby, my pull req might not show up as fast as expected… count me in.March 16, 2012 at 4:10 pm #22194
I’m on it. It took me some time…to find some time.
There’s (too) few comments but OK one can understand what does what in a decent time.
Now I’d prefer to ask you if you would do what I’m planning on doing. Not only do I know how some prefer to have the code designed in a specific way, but I may not have seen a more obvious way of doing it either.
First, having a mechanism like what RewritePhaseListener/PhaseAction do is piece of cake.
However it’s harder to find a way to “insert” the deferred behavior without changing some code in rewrite-servlet. I don’t want to touch the RewriteProvider#rewrite > Operation#perform > Binding#submit mechanic, neither duplicate it of course. So I’ve been thinking of having a “fake” ExpressionLanguageProvider which would defer params bindings till the “ad-hoc” PhaseListener kicks in, but the CdiExpressionLanguageProvider is already in the way…Yet I think I’ll need to modify both the Cdi and Faces integration projects anyway. So that may be a good approach.
What do you think?March 16, 2012 at 9:24 pm #22195
There’s actually a smarter solution…March 16, 2012 at 10:42 pm #22196
You shouldn’t need to change RewriteServlet at all – what are you trying to do that makes you think we should change code there?
Why not just add an
DefferredInjection,” which would add itself to a Request parameter – that could later be retrieved by
RewritePhaseListener, which would perform the injection during the right JSF phase.
I think that the Operation#perform() > Binding#submit mechanism is exactly what you want here, but you can re-use what was already done.
What is your smarter solution?
BTW. This code should all go in the integration-faces module, I think! Just take a look at what
PhaseActiondoes, then you can pretty much copy that and create
PhaseInjectionThoughts?March 16, 2012 at 11:22 pm #22197
My smarter solution is more or less what you’re describing.
Once the bindings are in the request, it’s piece of cake, as I said earlier.
What’s supposed to happen before was more problematic to me. I just couldn’t figure out initally how/where to instanciate the new operation nicely, so I was tempted to fall back on ambiguous solutions (either build some weird ExpressionLanguageProvider, or add some “defferred” test in the Bindings machinery…)
Thing is, at first I tried to embrace the code quickly to get started, but it took me a while to actually “wire” it. Things are getting better.
Thanks.March 19, 2012 at 1:14 am #22198
pull req done.March 19, 2012 at 4:08 am #22199
Woot! Will review tomorrow morning, need to sleep! Thanks very much
Pull requests are better than Christmas :p
~LincolnOctober 22, 2012 at 4:30 pm #22200
Hi Lincon and fabmars, I try to start project with rewrite on AS7, when try to run get
JBWEB000284: Exception starting filter OCPsoft Rewrite Filter: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped
please adviceOctober 22, 2012 at 4:44 pm #22201
Could you please start a new thread for this problem? It is related but different.
Your exception means that you are doing potentially non-threadsafe access of a request scoped bean.
-LincolnOctober 25, 2012 at 1:51 pm #22202
Tnahk you Lincoln, by the moment, I’m removed rewritte support in my project.October 25, 2012 at 2:41 pm #22203
Oh, shame on you. No, just kidding, you may not need it actually. But it’s a wonderful addon to many web-based appsOctober 25, 2012 at 10:55 pm #22204
This problem is easy to solve (I know the answer,) but all I ask is that you start a separate thread for your new topic
You must be logged in to reply to this topic.