users@javaserverfaces.java.net

Re: Problem calling HttpServletRequest authenticate() within preRenderView listener

From: Roger Kitain <roger.kitain_at_oracle.com>
Date: Thu, 11 Aug 2011 18:41:11 -0400

Where is your processEvent(SystemEvent event) method?

On 8/11/11 5:48 PM, ekraffmiller_at_hmdc.harvard.edu wrote:
> Hi,
> I'm getting an error when I call authenticate() within a preRenderView
> listener in a managed bean. It looks like a bug in Mojarra, but I just
> wanted to ask here before creating an Issue in Jira.
>
> Here is my code:
> public void preRender(ComponentSystemEvent event) {
> HttpServletRequest request =
> (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContex
> t().getRequest();
> HttpServletResponse response =
> (HttpServletResponse)FacesContext.getCurrentInstance().getExternalConte
> xt().getResponse();
> try {
> if (!request.authenticate(response)) {
> // can't call responseComplete() here, because
> FacesContext.getCurrentInstance() == null.
> // FacesContext.getCurrentInstance().responseComplete();
>
> }
>
> } catch (Exception e) { // may throw ServletException or
> IOException
> System.out.println("EXCEPTION calling authenticate");
>
> e.printStackTrace();
> }
>
>
> When the method is called I get this error:
>
> javax.enterprise.resource.webcontainer.jsf.context|_ThreadID=23;_Thread
> Name=Thread-3;|Exception when handling error trying to reset the
> response.
> java.lang.NullPointerException
> at
> com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.proc
> essEvent(EventHandler.java:126)
>
> I tried calling responseComplete() to fix the error, but after the call
> to authenticate(), the FacesContext.getCurrentInstance() returns null
>
> Is this a bug in Mojarra, or am I calling authenticate incorrectly?
>
> Thanks,
> Ellen


-- 
roger.kitain_at_oracle.com
https://twitter.com/rogerk09
http://www.java.net/blogs/rogerk