Thanks for your reply. The problem I am trying to solve is - somehow enhance the MyFaces lifecycle with a feature to skip the browser during rendering (so user is never actually sent the HttpResponse containing the rendered jsp) that's why have I have 'doNOtRender' and instead immediately trigger an HttpServletRequest in the lifecycle to simulate the user clicking a button in the jsp and submit to faces servlet .
I am trying to actually doing this in ServletExternalContextImpl.dispatch() method. Thanks Asha On Sat, Oct 20, 2018 at 7:23 PM Hazem Saleh <haz...@apache.org> wrote: > Hi Surya, > > I think the problem is not clear, here are some questions to clarify: > 1. What does dispatch1(path) refer to do? Can you send the complete class > code? > 2. Where do you get NullPointerException? > 3. Why do you create un-managed thread in dispatch1(path)? > 4. What do you try to do? > 5. Do you have the complete source code for this? do you have the code > uploaded somewhere in a place like GitHub to give a look? > > Thanks > > On Fri, Oct 19, 2018 at 3:42 PM surya <suryagiri...@gmail.com> wrote: > > > 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 > > > > > -- > Hazem Saleh >