-
1. Re: How to get FacesContext in a @Asynchronous method call
ivan.indrawan Jan 21, 2010 1:34 PM (in response to rodrigo.uchoa)You can try using seam FacesContext to get the JSF Context.
org.jboss.seam.faces.FacesContext fc = Contexts.getApplicationContext().get("org.jboss.seam.faces.facesContex");
fc.getContext(); //this will return you the JSF Context.
If Seam FacesContext does not exist, you need to check whether the ApplicationContext has been populated. -
2. Re: How to get FacesContext in a @Asynchronous method call
kapitanpetko Jan 21, 2010 1:40 PM (in response to rodrigo.uchoa)Basically, Quartz jobs are not associated with a web or JSF request, so no FacesContext. You cannot get it. So the main question is: why do you need it?
-
3. Re: How to get FacesContext in a @Asynchronous method call
rodrigo.uchoa Jan 21, 2010 1:55 PM (in response to rodrigo.uchoa)
Nikolay Elenkov wrote on Jan 21, 2010 13:40:
Basically, Quartz jobs are not associated with a web or JSF request, so no FacesContext. You cannot get it. So the main question is: why do you need it?I knew someone would ask :) Anyway, here's the thing:
Our bussiness tier is tightly coupled to JSF and Seam. In a way that, everytime I call a business façade, we have an interceptor that intercept the calls and look for a FacesContext in the current thread (he calls FacesContext.getCurrentInstance().getExternalContext()).Thats when the problem arises. That async method needs to do some business processing, so it's logic that he gets a reference to a business facade where all the business logic is already implemented. But since there's no FacesContext, I'm unable to make calls to any business methods because they keep throwing
NullPointerException
inside that interceptor I just told you about.I know that our architecture probably needs to be reviewed, but that's gonna take some time. I was looking for a quick workaround.
If I could make a mock FacesContext and just associate it with the current thread, solves my problem.
-
4. Re: How to get FacesContext in a @Asynchronous method call
rodrigo.uchoa Jan 21, 2010 3:12 PM (in response to rodrigo.uchoa)
Ivan Sukianto wrote on Jan 21, 2010 13:34:
You can try using seam FacesContext to get the JSF Context.
org.jboss.seam.faces.FacesContext fc- Contexts.getApplicationContext().get(
org.jboss.seam.faces.facesContex
) fc.getContext(); //this will return you the JSF Context.
If Seam FacesContext does not exist, you need to check whether the ApplicationContext has been populated.Like you said, Contexts.getApplicationContext().get(
org.jboss.seam.faces.facesContex
) is returning null. Even If this really worked, I would also need that thejavax.faces.context.FacesContext
returned by the callfc.getContext()
be associated with the current thread. To avoid any calls to FacesContext.getCurrentInstance() from returning null.Can this work? How can I setup an ApplicationContext?
- Contexts.getApplicationContext().get(
-
5. Re: How to get FacesContext in a @Asynchronous method call
kapitanpetko Jan 22, 2010 2:12 AM (in response to rodrigo.uchoa)
Rodrigo Uchoa wrote on Jan 21, 2010 13:55:
I know that our architecture probably needs to be reviewed, but that's gonna take some time. I was looking for a quick workaround.
If I could make a mock FacesContext and just associate it with the current thread, solves my problem.Well, there is a MockFacesContext in the org.jboss.seam.mock package. It is used in SeamTest along with a few other mocks. You could probably use that, but since they are calling a static method, I don't see how you can inject it. Find the source of FacesContext, maybe you could use some reflection magic, but that might have unwanted side effects. Better have them rethink the whole architecture. At least make the FacesContext a parameter or something. If all else fails, you could just copy the code in one of your classes...
HTH