If dontRender is set, I do not want to send the response to client, instead I
want to create a HttpServletRequest message that matches whatever the
browser would normally send when the user clicks save button in test1.jsp 
and then  send that to the Faces servlet The page is not sent to browser,
but I want the same page to be sent with save button clicked . I am getting
NullPointer exception. 

public void dispatch1(String path)
                {
                        HttpServletRequest request = 
                            (HttpServletRequest).getRequest();
                        boolean dontRender = false;
                        if(request.getSession().getAttribute("dontRender") != 
null){
                                dontRender =(boolean) 
request.getSession().getAttribute("dontRender");
                        }
                        RequestDispatcher requestDispatcher
                            = request.getRequestDispatcher(path);
                        HttpServletResponse response = 
(HttpServletResponse)getResponse();
                        ServletResponse response = response;
                        
                        FacesContext facesContext = 
FacesContext.getCurrentInstance();
        
                        
                                   
                        
                        try
                            {
                                if (response.isCommitted())
                                    {
                                        
requestDispatcher.include(request,response);
                                    }
                                else
                                    {
                                         if (!dontRender) 
                                         {
                                        
                                                 
requestDispatcher.forward(request,response);
                                                 
                                         }
                                         else {         
                                                 // Dont render response        
  
                                                 // create a new httpservlet 
request  with savebutton clicked and send
to faces servlet                        
                                                            Runnable runner  = 
new Runnable() {
                                                               public void 
run() {
                                                                   
HttpServletRequest req = 
                                                                                
    (HttpServletRequest).getRequest();
                                                                            
HttpServletResponse resp =
(HttpServletResponse)getResponse();
                                                                    
req.setAttribute("Save", "Submit Q");
                                                                    
req.setAttribute("action","/test2.jsf");
                                                                  
                                                                    try {
                                                                                
        req.getRequestDispatcher("test1.jsf").forward(req, resp);
                                                                        
                                                                                
} catch (IOException e) {
                                                                                
        // TODO Auto-generated catch block
                                                                                
        e.printStackTrace();
                                                                                
} catch (ServletException e) {
                                                                                
        // TODO Auto-generated catch block
                                                                                
        e.printStackTrace();
                                                                                
}
                                                                    
                                                               }
                                                            };
                                                            Thread thread = new 
Thread(runner);
                                                            thread.start();
                                                        }
                                         
                                    }
                            } 
                            
                        catch (ServletException e)
                            {
                                e.printStackTrace();
                                throw new FacesException(e);
                            }
                    }
                        
                
        test1.jsp       
                <form name="test1"  action="test2.jsf"
enctype="application/x-www-form-urlencoded" method="post" target="">
                
                <input name="Save" id="Save"  type="submit" value="Submit Q">





--
Sent from: http://myfaces.10567.n7.nabble.com/MyFaces-Users-f57691.html

Reply via email to