You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shale.apache.org by Jason Vincent <jt...@gmail.com> on 2006/11/01 00:42:37 UTC

NPE while getting ExternalContext in destroy.

Hi all,

I'm currently upgrading my shale version from a nightly build back in
January, to version 1.0.3.

In my destory method, when I call getExternalContext() I get a NPE.

java.lang.NullPointerException
	at org.apache.shale.view.AbstractFacesBean.getExternalContext(AbstractFacesBean.java:77)

I need the externalContext to get a hold of the response so that I can
delete a cookie, if needed. I also use the session and request to log
some metrics, which also comes from the ExternalContext.

Any Ideas?

THANKS.
Jason

Re: NPE while getting ExternalContext in destroy.

Posted by Jason Vincent <jt...@gmail.com>.
Oh dang.
Thanks - I commented out that cookie line, and checked the prerender
method...  and Woah! the call to delete the cookie was already there.
I guess it got left behind when it wasn't working when it was first
coded in the destroy.

Thanks for all your help Craig.  Your consistent, and rapid, support
is GREATLY appreciated.

Cheers,
Jason


On 10/31/06, Craig McClanahan <cr...@apache.org> wrote:
> On 10/31/06, Jason Vincent <jt...@gmail.com> wrote:
> >
> > Hi all,
> >
> > I'm currently upgrading my shale version from a nightly build back in
> > January, to version 1.0.3.
> >
> > In my destory method, when I call getExternalContext() I get a NPE.
> >
> > java.lang.NullPointerException
> >         at org.apache.shale.view.AbstractFacesBean.getExternalContext(
> > AbstractFacesBean.java:77)
> >
> > I need the externalContext to get a hold of the response so that I can
> > delete a cookie, if needed. I also use the session and request to log
> > some metrics, which also comes from the ExternalContext.
> >
> > Any Ideas?
>
>
> Unfortunately, destroy is called after the JSF response lifecycle has been
> completed, so there is no more ExternalContext at that point :-(.
>
> However, even if there was, I don't think it would do you much good.  Since
> destroy is called after rendering, the response will have already been
> "committed" (in the servlet sense), including the HTTP headers that include
> your cookies.  So, you would not be able to delete a cookie then anyway.
> I'd recommend trying this in prerender(), where you know you can get to the
> response object before the headers have been sent.
>
>
> THANKS.
> > Jason
> >
>
> Craig
>
>

Re: NPE while getting ExternalContext in destroy.

Posted by Craig McClanahan <cr...@apache.org>.
On 10/31/06, Jason Vincent <jt...@gmail.com> wrote:
>
> Hi all,
>
> I'm currently upgrading my shale version from a nightly build back in
> January, to version 1.0.3.
>
> In my destory method, when I call getExternalContext() I get a NPE.
>
> java.lang.NullPointerException
>         at org.apache.shale.view.AbstractFacesBean.getExternalContext(
> AbstractFacesBean.java:77)
>
> I need the externalContext to get a hold of the response so that I can
> delete a cookie, if needed. I also use the session and request to log
> some metrics, which also comes from the ExternalContext.
>
> Any Ideas?


Unfortunately, destroy is called after the JSF response lifecycle has been
completed, so there is no more ExternalContext at that point :-(.

However, even if there was, I don't think it would do you much good.  Since
destroy is called after rendering, the response will have already been
"committed" (in the servlet sense), including the HTTP headers that include
your cookies.  So, you would not be able to delete a cookie then anyway.
I'd recommend trying this in prerender(), where you know you can get to the
response object before the headers have been sent.


THANKS.
> Jason
>

Craig