You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Mikael Andersson <ma...@gmail.com> on 2007/02/07 19:04:23 UTC

Programmatic forward in action,

Hi,
I have an action which performs a length operation, I'd like to get the
browser to redisplay the page while the process keeps running on the server.

I wonder how I perform a programmatic forward which in an action method,
which causes the browser to re-render the page while the action method is
still running.

Is there a way of doing this without spawning a new Thread?

I made the following futile attempt :

Managed bean:

public String longishRunningAction(){

  try{
    NavigationUtil.programmaticForward("/report/index.xhtml");
  }
  catch(Exception e){}

  doLongishRunningOperation();

  return null;
}


Some of the stuff in here were added just to see if the made a difference,
they didn't :)

public class NavigationUtil {

    /**
     * Force a forward programmatically
     *
     * @param viewId the viewId to forward to, ex. /report/index.xhtml
     * @throws ServletException
     * @throws IOException
     */
    public static void programmaticForward( final String viewId ) throws
ServletException, IOException{

        ExternalContext eCtx = FacesContext.getCurrentInstance
().getExternalContext();
        HttpServletRequest request = (HttpServletRequest)eCtx.getRequest();
        HttpServletResponse response =
(HttpServletResponse)eCtx.getResponse();
        RequestDispatcher dispatcher = request.getRequestDispatcher( viewId
);

        dispatcher.forward(request,response);

        FacesContext.getCurrentInstance().responseComplete();

        response.getOutputStream().flush();
        response.getOutputStream().close();

    }

}

Re: Programmatic forward in action,

Posted by Mikael Andersson <ma...@gmail.com>.
Yeah,
I guess I'll be going down the thread path after all :)

If anyone comes up with a nice solution, please post it, I'd be very
interested.

Thanks,
 Mike (the beginner one)

On 09/02/07, Paul Spencer <pa...@apache.org> wrote:
>
> Mikael,
>
> I suggest the action should spawn a thread or post a "todo" for another
> thread/process to do the actual work.  This way the action will return
> quickly.
>
> Paul Spencer
>
> Mikael Andersson wrote:
> > Hi,
> > I'm afraid I don't quite understand.
> >
> > First a little more on my problem:
> >
> > I have a page with at table where each row contains the status of a task
> > and
> > a commandLink to execute that task (a bit simplified). When ever that
> page
> > is refreshed it re-displays all tasks and their current status.
> > My problem now is that when I click the commandLink, the page hangs
> waiting
> > for the action method to finish. I was hoping for an easy way to just
> tell
> > tell the browser via the response to go to a page (the same page in this
> > case), without the action method finishing its execution.
> >
> > How can I have a refresh trigger a JSF action in plain JSF (without
> using
> > shale viewcontroller)?
> >
> > Thanks,
> > Mike
> >
> > On 09/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
> >>
> >> Right.   I'm saying that you only use the refresh as a one-time timer
> >> rather than an ongoing thing.
> >>
> >> You start at a page that is set to refresh.
> >> The refresh triggers a normal JSF action.
> >> The JSF servlet returns back an equivalent auto-refreshing page.
> >> Repeat until the action returns back a different page.
> >>
> >> On 2/9/07, Mikael Andersson <ma...@gmail.com> wrote:
> >> > The browser keeps waiting for the action method to finish (when
> >> submitting),
> >> > that is why I thought it might be possible to force a
> redirect/forward
> >> > programmatically so the action could do its length computation and
> the
> >> > progress page could be redisplayed (without starting a new thread).
> >> >
> >> > - mike
> >> >
> >> >
> >> > On 08/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
> >> > > If it were me, I'd look at having a meta-refresh tag submit a
> normal
> >> > action.
> >> > > The action would check the status of the background process, and
> >> > > either return the "in progress" page again or return the "action
> >> > > completed" page.
> >> > >
> >> > > You shouldn't need to anything strange like try to short-circult
> the
> >> > > JSF lifecycle or manually construct a response.
> >> > >
> >> > > On 2/8/07, Mikael Andersson < mail.micke@gmail.com> wrote:
> >> > > > Looking for some more suggestions :), I would prefer not to use
> >> ajax
> >> > since
> >> > > > it is quite a simple page.
> >> > > >
> >> > > > I have tried some more (hacky) stuff which didn't work either :(
> :
> >> > > >
> >> > > > The below changed the location URL, but don't load the page?? Any
> >> ideas.
> >> > > >
> >> > > > public static void programmaticForward2( final String viewId )
> >> throws
> >> > > > IOException{
> >> > > >         FacesContext faces = FacesContext.getCurrentInstance();
> >> > > >         HttpServletResponse response = (HttpServletResponse)
> >> > > > faces.getExternalContext().getResponse();
> >> > > >
> >> > > >         response.setContentType("text/html");
> >> > > >         response.setHeader("Location", "http://localhost:8080/dss"
> >> > > > +viewId);
> >> > > >
> >> > > >         faces.responseComplete();
> >> > > >         response.getOutputStream().flush();
> >> > > >         response.getOutputStream().close();
> >> > > >
> >> > > > }
> >> > > >
> >> > > > The below didn't do anything?
> >> > > >
> >> > > > public static void programmaticForward3( final String viewId )
> >> throws
> >> > > > IOException{
> >> > > >         FacesContext faces = FacesContext.getCurrentInstance();
> >> > > >         HttpServletResponse response = (HttpServletResponse)
> >> > > > faces.getExternalContext().getResponse();
> >> > > >         HttpServletRequest request =
> >> > > >
> >> > (HttpServletRequest)faces.getExternalContext().getRequest();
> >> > > >
> >> > > >         PrintWriter out = response.getWriter();
> >> > > >
> >> > > >         response.setContentType("text/html");
> >> > > >         response.sendRedirect("http://" +request.getServerName()
> >> +":"
> >> > > > +request.getServerPort() +"/dss" +viewId);
> >> > > >
> >> > > >         faces.responseComplete();
> >> > > >         out.flush();
> >> > > >         out.close();
> >> > > >
> >> > > > }
> >> > > >
> >> > > > Cheers,
> >> > > >  Mike no.2
> >> > > >
> >> > > >
> >> > > >
> >> > > > On 07/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
> >> > > > > Here's an ajax solution for a progress bar:
> >> > > > >
> >> > > > >
> >> > > >
> >> >
> >>
> http://weblogs.java.net/blog/edburns/archive/2005/05/ajaxian_faces_p.html
> >> > > > >
> >> > > >
> >> >
> >>
> https://blueprints.dev.java.net/bpcatalog/ee5/ajax/usingAJAXwithoutJSF.html
> >>
> >> > > > >
> >> > > > > Seems like there should be a way to solve this without ajax,
> >> though.
> >> > > > > Maybe using a meta refresh.
> >> > > > >
> >> > > > >
> >> > > > > On 2/7/07, Mikael Andersson < mail.micke@gmail.com> wrote:
> >> > > > > > Hi,
> >> > > > > > I have an action which performs a length operation, I'd like
> to
> >> get
> >> > the
> >> > > > > > browser to redisplay the page while the process keeps
> >> running on
> >> the
> >> > > > server.
> >> > > > > >
> >> > > > > > I wonder how I perform a programmatic forward which in an
> >> action
> >> > method,
> >> > > > > > which causes the browser to re-render the page while the
> action
> >> > method
> >> > > > is
> >> > > > > > still running.
> >> > > > > >
> >> > > > > > Is there a way of doing this without spawning a new Thread?
> >> > > > > >
> >> > > > > > I made the following futile attempt :
> >> > > > > >
> >> > > > > > Managed bean:
> >> > > > > >
> >> > > > > > public String longishRunningAction(){
> >> > > > > >
> >> > > > > >   try{
> >> > > > > >     NavigationUtil.programmaticForward
> >> > > > > > ("/report/index.xhtml");
> >> > > > > >   }
> >> > > > > >   catch(Exception e){}
> >> > > > > >
> >> > > > > >   doLongishRunningOperation();
> >> > > > > >
> >> > > > > >   return null;
> >> > > > > > }
> >> > > > > >
> >> > > > > >
> >> > > > > > Some of the stuff in here were added just to see if the made
> a
> >> > > > difference,
> >> > > > > > they didn't :)
> >> > > > > >
> >> > > > > > public class NavigationUtil {
> >> > > > > >
> >> > > > > >     /**
> >> > > > > >      * Force a forward programmatically
> >> > > > > >      *
> >> > > > > >      * @param viewId the viewId to forward to, ex.
> >> > /report/index.xhtml
> >> > > > > >      * @throws ServletException
> >> > > > > >      * @throws IOException
> >> > > > > >      */
> >> > > > > >     public static void programmaticForward( final String
> viewId
> >> )
> >> > throws
> >> > > > > > ServletException, IOException{
> >> > > > > >
> >> > > > > >         ExternalContext eCtx =
> >> > > > > > FacesContext.getCurrentInstance().getExternalContext();
> >> > > > > >         HttpServletRequest request =
> >> > > > > > (HttpServletRequest)eCtx.getRequest();
> >> > > > > >         HttpServletResponse response =
> >> > > > > > (HttpServletResponse)eCtx.getResponse();
> >> > > > > >         RequestDispatcher dispatcher =
> >> request.getRequestDispatcher(
> >> > > > viewId
> >> > > > > > );
> >> > > > > >
> >> > > > > >         dispatcher.forward(request,response);
> >> > > > > >
> >> > > > > >         FacesContext.getCurrentInstance().responseComplete();
> >> > > > > >
> >> > > > > >         response.getOutputStream().flush();
> >> > > > > >         response.getOutputStream().close();
> >> > > > > >
> >> > > > > >     }
> >> > > > > >
> >> > > > > > }
> >> > > > > >
> >> > > > > >
> >> > > > >
> >> > > >
> >> > > >
> >> > >
> >> >
> >> >
> >>
> >
>
>

Re: Programmatic forward in action,

Posted by Paul Spencer <pa...@apache.org>.
Mikael,

I suggest the action should spawn a thread or post a "todo" for another 
thread/process to do the actual work.  This way the action will return 
quickly.

Paul Spencer

Mikael Andersson wrote:
> Hi,
> I'm afraid I don't quite understand.
> 
> First a little more on my problem:
> 
> I have a page with at table where each row contains the status of a task 
> and
> a commandLink to execute that task (a bit simplified). When ever that page
> is refreshed it re-displays all tasks and their current status.
> My problem now is that when I click the commandLink, the page hangs waiting
> for the action method to finish. I was hoping for an easy way to just tell
> tell the browser via the response to go to a page (the same page in this
> case), without the action method finishing its execution.
> 
> How can I have a refresh trigger a JSF action in plain JSF (without using
> shale viewcontroller)?
> 
> Thanks,
> Mike
> 
> On 09/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
>>
>> Right.   I'm saying that you only use the refresh as a one-time timer
>> rather than an ongoing thing.
>>
>> You start at a page that is set to refresh.
>> The refresh triggers a normal JSF action.
>> The JSF servlet returns back an equivalent auto-refreshing page.
>> Repeat until the action returns back a different page.
>>
>> On 2/9/07, Mikael Andersson <ma...@gmail.com> wrote:
>> > The browser keeps waiting for the action method to finish (when
>> submitting),
>> > that is why I thought it might be possible to force a redirect/forward
>> > programmatically so the action could do its length computation and the
>> > progress page could be redisplayed (without starting a new thread).
>> >
>> > - mike
>> >
>> >
>> > On 08/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
>> > > If it were me, I'd look at having a meta-refresh tag submit a normal
>> > action.
>> > > The action would check the status of the background process, and
>> > > either return the "in progress" page again or return the "action
>> > > completed" page.
>> > >
>> > > You shouldn't need to anything strange like try to short-circult the
>> > > JSF lifecycle or manually construct a response.
>> > >
>> > > On 2/8/07, Mikael Andersson < mail.micke@gmail.com> wrote:
>> > > > Looking for some more suggestions :), I would prefer not to use 
>> ajax
>> > since
>> > > > it is quite a simple page.
>> > > >
>> > > > I have tried some more (hacky) stuff which didn't work either :( :
>> > > >
>> > > > The below changed the location URL, but don't load the page?? Any
>> ideas.
>> > > >
>> > > > public static void programmaticForward2( final String viewId )
>> throws
>> > > > IOException{
>> > > >         FacesContext faces = FacesContext.getCurrentInstance();
>> > > >         HttpServletResponse response = (HttpServletResponse)
>> > > > faces.getExternalContext().getResponse();
>> > > >
>> > > >         response.setContentType("text/html");
>> > > >         response.setHeader("Location", "http://localhost:8080/dss "
>> > > > +viewId);
>> > > >
>> > > >         faces.responseComplete();
>> > > >         response.getOutputStream().flush();
>> > > >         response.getOutputStream().close();
>> > > >
>> > > > }
>> > > >
>> > > > The below didn't do anything?
>> > > >
>> > > > public static void programmaticForward3( final String viewId )
>> throws
>> > > > IOException{
>> > > >         FacesContext faces = FacesContext.getCurrentInstance();
>> > > >         HttpServletResponse response = (HttpServletResponse)
>> > > > faces.getExternalContext().getResponse();
>> > > >         HttpServletRequest request =
>> > > >
>> > (HttpServletRequest)faces.getExternalContext().getRequest();
>> > > >
>> > > >         PrintWriter out = response.getWriter();
>> > > >
>> > > >         response.setContentType("text/html");
>> > > >         response.sendRedirect("http://" +request.getServerName()
>> +":"
>> > > > +request.getServerPort() +"/dss" +viewId);
>> > > >
>> > > >         faces.responseComplete();
>> > > >         out.flush();
>> > > >         out.close();
>> > > >
>> > > > }
>> > > >
>> > > > Cheers,
>> > > >  Mike no.2
>> > > >
>> > > >
>> > > >
>> > > > On 07/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
>> > > > > Here's an ajax solution for a progress bar:
>> > > > >
>> > > > >
>> > > >
>> >
>> http://weblogs.java.net/blog/edburns/archive/2005/05/ajaxian_faces_p.html
>> > > > >
>> > > >
>> >
>> https://blueprints.dev.java.net/bpcatalog/ee5/ajax/usingAJAXwithoutJSF.html 
>>
>> > > > >
>> > > > > Seems like there should be a way to solve this without ajax,
>> though.
>> > > > > Maybe using a meta refresh.
>> > > > >
>> > > > >
>> > > > > On 2/7/07, Mikael Andersson < mail.micke@gmail.com> wrote:
>> > > > > > Hi,
>> > > > > > I have an action which performs a length operation, I'd like to
>> get
>> > the
>> > > > > > browser to redisplay the page while the process keeps 
>> running on
>> the
>> > > > server.
>> > > > > >
>> > > > > > I wonder how I perform a programmatic forward which in an 
>> action
>> > method,
>> > > > > > which causes the browser to re-render the page while the action
>> > method
>> > > > is
>> > > > > > still running.
>> > > > > >
>> > > > > > Is there a way of doing this without spawning a new Thread?
>> > > > > >
>> > > > > > I made the following futile attempt :
>> > > > > >
>> > > > > > Managed bean:
>> > > > > >
>> > > > > > public String longishRunningAction(){
>> > > > > >
>> > > > > >   try{
>> > > > > >     NavigationUtil.programmaticForward
>> > > > > > ("/report/index.xhtml");
>> > > > > >   }
>> > > > > >   catch(Exception e){}
>> > > > > >
>> > > > > >   doLongishRunningOperation();
>> > > > > >
>> > > > > >   return null;
>> > > > > > }
>> > > > > >
>> > > > > >
>> > > > > > Some of the stuff in here were added just to see if the made a
>> > > > difference,
>> > > > > > they didn't :)
>> > > > > >
>> > > > > > public class NavigationUtil {
>> > > > > >
>> > > > > >     /**
>> > > > > >      * Force a forward programmatically
>> > > > > >      *
>> > > > > >      * @param viewId the viewId to forward to, ex.
>> > /report/index.xhtml
>> > > > > >      * @throws ServletException
>> > > > > >      * @throws IOException
>> > > > > >      */
>> > > > > >     public static void programmaticForward( final String viewId
>> )
>> > throws
>> > > > > > ServletException, IOException{
>> > > > > >
>> > > > > >         ExternalContext eCtx =
>> > > > > > FacesContext.getCurrentInstance().getExternalContext();
>> > > > > >         HttpServletRequest request =
>> > > > > > (HttpServletRequest)eCtx.getRequest();
>> > > > > >         HttpServletResponse response =
>> > > > > > (HttpServletResponse)eCtx.getResponse();
>> > > > > >         RequestDispatcher dispatcher =
>> request.getRequestDispatcher(
>> > > > viewId
>> > > > > > );
>> > > > > >
>> > > > > >         dispatcher.forward(request,response);
>> > > > > >
>> > > > > >         FacesContext.getCurrentInstance().responseComplete();
>> > > > > >
>> > > > > >         response.getOutputStream().flush();
>> > > > > >         response.getOutputStream().close();
>> > > > > >
>> > > > > >     }
>> > > > > >
>> > > > > > }
>> > > > > >
>> > > > > >
>> > > > >
>> > > >
>> > > >
>> > >
>> >
>> >
>>
> 


Re: Programmatic forward in action,

Posted by Mikael Andersson <ma...@gmail.com>.
Hi,
I'm afraid I don't quite understand.

First a little more on my problem:

I have a page with at table where each row contains the status of a task and
a commandLink to execute that task (a bit simplified). When ever that page
is refreshed it re-displays all tasks and their current status.
My problem now is that when I click the commandLink, the page hangs waiting
for the action method to finish. I was hoping for an easy way to just tell
tell the browser via the response to go to a page (the same page in this
case), without the action method finishing its execution.

How can I have a refresh trigger a JSF action in plain JSF (without using
shale viewcontroller)?

Thanks,
 Mike

On 09/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
>
> Right.   I'm saying that you only use the refresh as a one-time timer
> rather than an ongoing thing.
>
> You start at a page that is set to refresh.
> The refresh triggers a normal JSF action.
> The JSF servlet returns back an equivalent auto-refreshing page.
> Repeat until the action returns back a different page.
>
> On 2/9/07, Mikael Andersson <ma...@gmail.com> wrote:
> > The browser keeps waiting for the action method to finish (when
> submitting),
> > that is why I thought it might be possible to force a redirect/forward
> > programmatically so the action could do its length computation and the
> > progress page could be redisplayed (without starting a new thread).
> >
> > - mike
> >
> >
> > On 08/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
> > > If it were me, I'd look at having a meta-refresh tag submit a normal
> > action.
> > > The action would check the status of the background process, and
> > > either return the "in progress" page again or return the "action
> > > completed" page.
> > >
> > > You shouldn't need to anything strange like try to short-circult the
> > > JSF lifecycle or manually construct a response.
> > >
> > > On 2/8/07, Mikael Andersson < mail.micke@gmail.com> wrote:
> > > > Looking for some more suggestions :), I would prefer not to use ajax
> > since
> > > > it is quite a simple page.
> > > >
> > > > I have tried some more (hacky) stuff which didn't work either :( :
> > > >
> > > > The below changed the location URL, but don't load the page?? Any
> ideas.
> > > >
> > > > public static void programmaticForward2( final String viewId )
> throws
> > > > IOException{
> > > >         FacesContext faces = FacesContext.getCurrentInstance();
> > > >         HttpServletResponse response = (HttpServletResponse)
> > > > faces.getExternalContext().getResponse();
> > > >
> > > >         response.setContentType("text/html");
> > > >         response.setHeader("Location", "http://localhost:8080/dss "
> > > > +viewId);
> > > >
> > > >         faces.responseComplete();
> > > >         response.getOutputStream().flush();
> > > >         response.getOutputStream().close();
> > > >
> > > > }
> > > >
> > > > The below didn't do anything?
> > > >
> > > > public static void programmaticForward3( final String viewId )
> throws
> > > > IOException{
> > > >         FacesContext faces = FacesContext.getCurrentInstance();
> > > >         HttpServletResponse response = (HttpServletResponse)
> > > > faces.getExternalContext().getResponse();
> > > >         HttpServletRequest request =
> > > >
> > (HttpServletRequest)faces.getExternalContext().getRequest();
> > > >
> > > >         PrintWriter out = response.getWriter();
> > > >
> > > >         response.setContentType("text/html");
> > > >         response.sendRedirect("http://" +request.getServerName()
> +":"
> > > > +request.getServerPort() +"/dss" +viewId);
> > > >
> > > >         faces.responseComplete();
> > > >         out.flush();
> > > >         out.close();
> > > >
> > > > }
> > > >
> > > > Cheers,
> > > >  Mike no.2
> > > >
> > > >
> > > >
> > > > On 07/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
> > > > > Here's an ajax solution for a progress bar:
> > > > >
> > > > >
> > > >
> >
> http://weblogs.java.net/blog/edburns/archive/2005/05/ajaxian_faces_p.html
> > > > >
> > > >
> >
> https://blueprints.dev.java.net/bpcatalog/ee5/ajax/usingAJAXwithoutJSF.html
> > > > >
> > > > > Seems like there should be a way to solve this without ajax,
> though.
> > > > > Maybe using a meta refresh.
> > > > >
> > > > >
> > > > > On 2/7/07, Mikael Andersson < mail.micke@gmail.com> wrote:
> > > > > > Hi,
> > > > > > I have an action which performs a length operation, I'd like to
> get
> > the
> > > > > > browser to redisplay the page while the process keeps running on
> the
> > > > server.
> > > > > >
> > > > > > I wonder how I perform a programmatic forward which in an action
> > method,
> > > > > > which causes the browser to re-render the page while the action
> > method
> > > > is
> > > > > > still running.
> > > > > >
> > > > > > Is there a way of doing this without spawning a new Thread?
> > > > > >
> > > > > > I made the following futile attempt :
> > > > > >
> > > > > > Managed bean:
> > > > > >
> > > > > > public String longishRunningAction(){
> > > > > >
> > > > > >   try{
> > > > > >     NavigationUtil.programmaticForward
> > > > > > ("/report/index.xhtml");
> > > > > >   }
> > > > > >   catch(Exception e){}
> > > > > >
> > > > > >   doLongishRunningOperation();
> > > > > >
> > > > > >   return null;
> > > > > > }
> > > > > >
> > > > > >
> > > > > > Some of the stuff in here were added just to see if the made a
> > > > difference,
> > > > > > they didn't :)
> > > > > >
> > > > > > public class NavigationUtil {
> > > > > >
> > > > > >     /**
> > > > > >      * Force a forward programmatically
> > > > > >      *
> > > > > >      * @param viewId the viewId to forward to, ex.
> > /report/index.xhtml
> > > > > >      * @throws ServletException
> > > > > >      * @throws IOException
> > > > > >      */
> > > > > >     public static void programmaticForward( final String viewId
> )
> > throws
> > > > > > ServletException, IOException{
> > > > > >
> > > > > >         ExternalContext eCtx =
> > > > > > FacesContext.getCurrentInstance().getExternalContext();
> > > > > >         HttpServletRequest request =
> > > > > > (HttpServletRequest)eCtx.getRequest();
> > > > > >         HttpServletResponse response =
> > > > > > (HttpServletResponse)eCtx.getResponse();
> > > > > >         RequestDispatcher dispatcher =
> request.getRequestDispatcher(
> > > > viewId
> > > > > > );
> > > > > >
> > > > > >         dispatcher.forward(request,response);
> > > > > >
> > > > > >         FacesContext.getCurrentInstance().responseComplete();
> > > > > >
> > > > > >         response.getOutputStream().flush();
> > > > > >         response.getOutputStream().close();
> > > > > >
> > > > > >     }
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > >
> >
> >
>

Re: Programmatic forward in action,

Posted by Mike Kienenberger <mk...@gmail.com>.
Right.   I'm saying that you only use the refresh as a one-time timer
rather than an ongoing thing.

You start at a page that is set to refresh.
The refresh triggers a normal JSF action.
The JSF servlet returns back an equivalent auto-refreshing page.
Repeat until the action returns back a different page.

On 2/9/07, Mikael Andersson <ma...@gmail.com> wrote:
> The browser keeps waiting for the action method to finish (when submitting),
> that is why I thought it might be possible to force a redirect/forward
> programmatically so the action could do its length computation and the
> progress page could be redisplayed (without starting a new thread).
>
> - mike
>
>
> On 08/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
> > If it were me, I'd look at having a meta-refresh tag submit a normal
> action.
> > The action would check the status of the background process, and
> > either return the "in progress" page again or return the "action
> > completed" page.
> >
> > You shouldn't need to anything strange like try to short-circult the
> > JSF lifecycle or manually construct a response.
> >
> > On 2/8/07, Mikael Andersson < mail.micke@gmail.com> wrote:
> > > Looking for some more suggestions :), I would prefer not to use ajax
> since
> > > it is quite a simple page.
> > >
> > > I have tried some more (hacky) stuff which didn't work either :( :
> > >
> > > The below changed the location URL, but don't load the page?? Any ideas.
> > >
> > > public static void programmaticForward2( final String viewId ) throws
> > > IOException{
> > >         FacesContext faces = FacesContext.getCurrentInstance();
> > >         HttpServletResponse response = (HttpServletResponse)
> > > faces.getExternalContext().getResponse();
> > >
> > >         response.setContentType("text/html");
> > >         response.setHeader("Location", "http://localhost:8080/dss "
> > > +viewId);
> > >
> > >         faces.responseComplete();
> > >         response.getOutputStream().flush();
> > >         response.getOutputStream().close();
> > >
> > > }
> > >
> > > The below didn't do anything?
> > >
> > > public static void programmaticForward3( final String viewId ) throws
> > > IOException{
> > >         FacesContext faces = FacesContext.getCurrentInstance();
> > >         HttpServletResponse response = (HttpServletResponse)
> > > faces.getExternalContext().getResponse();
> > >         HttpServletRequest request =
> > >
> (HttpServletRequest)faces.getExternalContext().getRequest();
> > >
> > >         PrintWriter out = response.getWriter();
> > >
> > >         response.setContentType("text/html");
> > >         response.sendRedirect("http://" +request.getServerName() +":"
> > > +request.getServerPort() +"/dss" +viewId);
> > >
> > >         faces.responseComplete();
> > >         out.flush();
> > >         out.close();
> > >
> > > }
> > >
> > > Cheers,
> > >  Mike no.2
> > >
> > >
> > >
> > > On 07/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
> > > > Here's an ajax solution for a progress bar:
> > > >
> > > >
> > >
> http://weblogs.java.net/blog/edburns/archive/2005/05/ajaxian_faces_p.html
> > > >
> > >
> https://blueprints.dev.java.net/bpcatalog/ee5/ajax/usingAJAXwithoutJSF.html
> > > >
> > > > Seems like there should be a way to solve this without ajax, though.
> > > > Maybe using a meta refresh.
> > > >
> > > >
> > > > On 2/7/07, Mikael Andersson < mail.micke@gmail.com> wrote:
> > > > > Hi,
> > > > > I have an action which performs a length operation, I'd like to get
> the
> > > > > browser to redisplay the page while the process keeps running on the
> > > server.
> > > > >
> > > > > I wonder how I perform a programmatic forward which in an action
> method,
> > > > > which causes the browser to re-render the page while the action
> method
> > > is
> > > > > still running.
> > > > >
> > > > > Is there a way of doing this without spawning a new Thread?
> > > > >
> > > > > I made the following futile attempt :
> > > > >
> > > > > Managed bean:
> > > > >
> > > > > public String longishRunningAction(){
> > > > >
> > > > >   try{
> > > > >     NavigationUtil.programmaticForward
> > > > > ("/report/index.xhtml");
> > > > >   }
> > > > >   catch(Exception e){}
> > > > >
> > > > >   doLongishRunningOperation();
> > > > >
> > > > >   return null;
> > > > > }
> > > > >
> > > > >
> > > > > Some of the stuff in here were added just to see if the made a
> > > difference,
> > > > > they didn't :)
> > > > >
> > > > > public class NavigationUtil {
> > > > >
> > > > >     /**
> > > > >      * Force a forward programmatically
> > > > >      *
> > > > >      * @param viewId the viewId to forward to, ex.
> /report/index.xhtml
> > > > >      * @throws ServletException
> > > > >      * @throws IOException
> > > > >      */
> > > > >     public static void programmaticForward( final String viewId )
> throws
> > > > > ServletException, IOException{
> > > > >
> > > > >         ExternalContext eCtx =
> > > > > FacesContext.getCurrentInstance().getExternalContext();
> > > > >         HttpServletRequest request =
> > > > > (HttpServletRequest)eCtx.getRequest();
> > > > >         HttpServletResponse response =
> > > > > (HttpServletResponse)eCtx.getResponse();
> > > > >         RequestDispatcher dispatcher = request.getRequestDispatcher(
> > > viewId
> > > > > );
> > > > >
> > > > >         dispatcher.forward(request,response);
> > > > >
> > > > >         FacesContext.getCurrentInstance().responseComplete();
> > > > >
> > > > >         response.getOutputStream().flush();
> > > > >         response.getOutputStream().close();
> > > > >
> > > > >     }
> > > > >
> > > > > }
> > > > >
> > > > >
> > > >
> > >
> > >
> >
>
>

Re: Programmatic forward in action,

Posted by Mikael Andersson <ma...@gmail.com>.
Hi,
had it been solely up to me I would have pimped the page with ajax4jsf a
while ago :) .

On 09/02/07, Ricardo Tercero Lozano <rt...@gmail.com> wrote:
>
>
> Try AjaxAnywhere (http://ajaxanywhere.sourceforge.net/). Although it's an
> Ajax solution, the principal advantage is than this component hadly adds
> complexity to your page.
>
> I've used AjaxAnywhere for a similar functionality with success.
>
> Ricardo.
>
>
>
>
> On 2/9/07, Mikael Andersson < mail.micke@gmail.com> wrote:
> >
> > The browser keeps waiting for the action method to finish (when
> > submitting), that is why I thought it might be possible to force a
> > redirect/forward programmatically so the action could do its length
> > computation and the progress page could be redisplayed (without starting a
> > new thread).
> >
> > - mike
> >
> > On 08/02/07, Mike Kienenberger < mkienenb@gmail.com> wrote:
> > >
> > > If it were me, I'd look at having a meta-refresh tag submit a normal
> > > action.
> > > The action would check the status of the background process, and
> > > either return the "in progress" page again or return the "action
> > > completed" page.
> > >
> > > You shouldn't need to anything strange like try to short-circult the
> > > JSF lifecycle or manually construct a response.
> > >
> > > On 2/8/07, Mikael Andersson < mail.micke@gmail.com> wrote:
> > > > Looking for some more suggestions :), I would prefer not to use ajax
> > > since
> > > > it is quite a simple page.
> > > >
> > > > I have tried some more (hacky) stuff which didn't work either :( :
> > > >
> > > > The below changed the location URL, but don't load the page?? Any
> > > ideas.
> > > >
> > > > public static void programmaticForward2( final String viewId )
> > > throws
> > > > IOException{
> > > >         FacesContext faces = FacesContext.getCurrentInstance();
> > > >         HttpServletResponse response = (HttpServletResponse)
> > > > faces.getExternalContext().getResponse();
> > > >
> > > >         response.setContentType("text/html");
> > > >         response.setHeader("Location", "http://localhost:8080/dss "
> > > > +viewId);
> > > >
> > > >         faces.responseComplete();
> > > >         response.getOutputStream().flush();
> > > >         response.getOutputStream().close();
> > > >
> > > > }
> > > >
> > > > The below didn't do anything?
> > > >
> > > > public static void programmaticForward3( final String viewId )
> > > throws
> > > > IOException{
> > > >         FacesContext faces = FacesContext.getCurrentInstance();
> > > >         HttpServletResponse response = (HttpServletResponse)
> > > > faces.getExternalContext().getResponse();
> > > >         HttpServletRequest request =
> > > > (HttpServletRequest)faces.getExternalContext().getRequest();
> > > >
> > > >         PrintWriter out = response.getWriter();
> > > >
> > > >         response.setContentType("text/html");
> > > >         response.sendRedirect("http://" +request.getServerName()
> > > +":"
> > > > +request.getServerPort() +"/dss" +viewId);
> > > >
> > > >         faces.responseComplete();
> > > >         out.flush();
> > > >         out.close();
> > > >
> > > > }
> > > >
> > > > Cheers,
> > > >  Mike no.2
> > > >
> > > >
> > > >
> > > > On 07/02/07, Mike Kienenberger < mkienenb@gmail.com> wrote:
> > > > > Here's an ajax solution for a progress bar:
> > > > >
> > > > >
> > > > http://weblogs.java.net/blog/edburns/archive/2005/05/ajaxian_faces_p.html
> > >
> > > > >
> > > > https://blueprints.dev.java.net/bpcatalog/ee5/ajax/usingAJAXwithoutJSF.html
> > >
> > > > >
> > > > > Seems like there should be a way to solve this without ajax,
> > > though.
> > > > > Maybe using a meta refresh.
> > > > >
> > > > >
> > > > > On 2/7/07, Mikael Andersson < mail.micke@gmail.com> wrote:
> > > > > > Hi,
> > > > > > I have an action which performs a length operation, I'd like to
> > > get the
> > > > > > browser to redisplay the page while the process keeps running on
> > > the
> > > > server.
> > > > > >
> > > > > > I wonder how I perform a programmatic forward which in an action
> > > method,
> > > > > > which causes the browser to re-render the page while the action
> > > method
> > > > is
> > > > > > still running.
> > > > > >
> > > > > > Is there a way of doing this without spawning a new Thread?
> > > > > >
> > > > > > I made the following futile attempt :
> > > > > >
> > > > > > Managed bean:
> > > > > >
> > > > > > public String longishRunningAction(){
> > > > > >
> > > > > >   try{
> > > > > >     NavigationUtil.programmaticForward
> > > > > > ("/report/index.xhtml");
> > > > > >   }
> > > > > >   catch(Exception e){}
> > > > > >
> > > > > >   doLongishRunningOperation();
> > > > > >
> > > > > >   return null;
> > > > > > }
> > > > > >
> > > > > >
> > > > > > Some of the stuff in here were added just to see if the made a
> > > > difference,
> > > > > > they didn't :)
> > > > > >
> > > > > > public class NavigationUtil {
> > > > > >
> > > > > >     /**
> > > > > >      * Force a forward programmatically
> > > > > >      *
> > > > > >      * @param viewId the viewId to forward to, ex.
> > > /report/index.xhtml
> > > > > >      * @throws ServletException
> > > > > >      * @throws IOException
> > > > > >      */
> > > > > >     public static void programmaticForward( final String viewId
> > > ) throws
> > > > > > ServletException, IOException{
> > > > > >
> > > > > >         ExternalContext eCtx =
> > > > > > FacesContext.getCurrentInstance().getExternalContext();
> > > > > >         HttpServletRequest request =
> > > > > > (HttpServletRequest)eCtx.getRequest();
> > > > > >         HttpServletResponse response =
> > > > > > (HttpServletResponse)eCtx.getResponse();
> > > > > >         RequestDispatcher dispatcher =
> > > request.getRequestDispatcher(
> > > > viewId
> > > > > > );
> > > > > >
> > > > > >         dispatcher.forward(request,response);
> > > > > >
> > > > > >         FacesContext.getCurrentInstance().responseComplete();
> > > > > >
> > > > > >         response.getOutputStream().flush();
> > > > > >         response.getOutputStream().close();
> > > > > >
> > > > > >     }
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > >
> >
> >
>

Re: Programmatic forward in action,

Posted by Ricardo Tercero Lozano <rt...@gmail.com>.
Try AjaxAnywhere (http://ajaxanywhere.sourceforge.net/). Although it's an
Ajax solution, the principal advantage is than this component hadly adds
complexity to your page.

I've used AjaxAnywhere for a similar functionality with success.

Ricardo.




On 2/9/07, Mikael Andersson <ma...@gmail.com> wrote:
>
> The browser keeps waiting for the action method to finish (when
> submitting), that is why I thought it might be possible to force a
> redirect/forward programmatically so the action could do its length
> computation and the progress page could be redisplayed (without starting a
> new thread).
>
> - mike
>
> On 08/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
> >
> > If it were me, I'd look at having a meta-refresh tag submit a normal
> > action.
> > The action would check the status of the background process, and
> > either return the "in progress" page again or return the "action
> > completed" page.
> >
> > You shouldn't need to anything strange like try to short-circult the
> > JSF lifecycle or manually construct a response.
> >
> > On 2/8/07, Mikael Andersson < mail.micke@gmail.com> wrote:
> > > Looking for some more suggestions :), I would prefer not to use ajax
> > since
> > > it is quite a simple page.
> > >
> > > I have tried some more (hacky) stuff which didn't work either :( :
> > >
> > > The below changed the location URL, but don't load the page?? Any
> > ideas.
> > >
> > > public static void programmaticForward2( final String viewId ) throws
> > > IOException{
> > >         FacesContext faces = FacesContext.getCurrentInstance();
> > >         HttpServletResponse response = (HttpServletResponse)
> > > faces.getExternalContext().getResponse();
> > >
> > >         response.setContentType("text/html");
> > >         response.setHeader("Location", "http://localhost:8080/dss "
> > > +viewId);
> > >
> > >         faces.responseComplete();
> > >         response.getOutputStream().flush();
> > >         response.getOutputStream().close();
> > >
> > > }
> > >
> > > The below didn't do anything?
> > >
> > > public static void programmaticForward3( final String viewId ) throws
> > > IOException{
> > >         FacesContext faces = FacesContext.getCurrentInstance();
> > >         HttpServletResponse response = (HttpServletResponse)
> > > faces.getExternalContext().getResponse();
> > >         HttpServletRequest request =
> > > (HttpServletRequest)faces.getExternalContext().getRequest();
> > >
> > >         PrintWriter out = response.getWriter();
> > >
> > >         response.setContentType("text/html");
> > >         response.sendRedirect("http://" +request.getServerName() +":"
> > > +request.getServerPort() +"/dss" +viewId);
> > >
> > >         faces.responseComplete();
> > >         out.flush();
> > >         out.close();
> > >
> > > }
> > >
> > > Cheers,
> > >  Mike no.2
> > >
> > >
> > >
> > > On 07/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
> > > > Here's an ajax solution for a progress bar:
> > > >
> > > >
> > > http://weblogs.java.net/blog/edburns/archive/2005/05/ajaxian_faces_p.html
> >
> > > >
> > >
> > https://blueprints.dev.java.net/bpcatalog/ee5/ajax/usingAJAXwithoutJSF.html
> > > >
> > > > Seems like there should be a way to solve this without ajax, though.
> >
> > > > Maybe using a meta refresh.
> > > >
> > > >
> > > > On 2/7/07, Mikael Andersson < mail.micke@gmail.com> wrote:
> > > > > Hi,
> > > > > I have an action which performs a length operation, I'd like to
> > get the
> > > > > browser to redisplay the page while the process keeps running on
> > the
> > > server.
> > > > >
> > > > > I wonder how I perform a programmatic forward which in an action
> > method,
> > > > > which causes the browser to re-render the page while the action
> > method
> > > is
> > > > > still running.
> > > > >
> > > > > Is there a way of doing this without spawning a new Thread?
> > > > >
> > > > > I made the following futile attempt :
> > > > >
> > > > > Managed bean:
> > > > >
> > > > > public String longishRunningAction(){
> > > > >
> > > > >   try{
> > > > >     NavigationUtil.programmaticForward
> > > > > ("/report/index.xhtml");
> > > > >   }
> > > > >   catch(Exception e){}
> > > > >
> > > > >   doLongishRunningOperation();
> > > > >
> > > > >   return null;
> > > > > }
> > > > >
> > > > >
> > > > > Some of the stuff in here were added just to see if the made a
> > > difference,
> > > > > they didn't :)
> > > > >
> > > > > public class NavigationUtil {
> > > > >
> > > > >     /**
> > > > >      * Force a forward programmatically
> > > > >      *
> > > > >      * @param viewId the viewId to forward to, ex.
> > /report/index.xhtml
> > > > >      * @throws ServletException
> > > > >      * @throws IOException
> > > > >      */
> > > > >     public static void programmaticForward( final String viewId )
> > throws
> > > > > ServletException, IOException{
> > > > >
> > > > >         ExternalContext eCtx =
> > > > > FacesContext.getCurrentInstance().getExternalContext();
> > > > >         HttpServletRequest request =
> > > > > (HttpServletRequest)eCtx.getRequest();
> > > > >         HttpServletResponse response =
> > > > > (HttpServletResponse)eCtx.getResponse();
> > > > >         RequestDispatcher dispatcher =
> > request.getRequestDispatcher(
> > > viewId
> > > > > );
> > > > >
> > > > >         dispatcher.forward(request,response);
> > > > >
> > > > >         FacesContext.getCurrentInstance().responseComplete();
> > > > >
> > > > >         response.getOutputStream().flush();
> > > > >         response.getOutputStream().close();
> > > > >
> > > > >     }
> > > > >
> > > > > }
> > > > >
> > > > >
> > > >
> > >
> > >
> >
>
>

Re: Programmatic forward in action,

Posted by Mikael Andersson <ma...@gmail.com>.
The browser keeps waiting for the action method to finish (when submitting),
that is why I thought it might be possible to force a redirect/forward
programmatically so the action could do its length computation and the
progress page could be redisplayed (without starting a new thread).

- mike

On 08/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
>
> If it were me, I'd look at having a meta-refresh tag submit a normal
> action.
> The action would check the status of the background process, and
> either return the "in progress" page again or return the "action
> completed" page.
>
> You shouldn't need to anything strange like try to short-circult the
> JSF lifecycle or manually construct a response.
>
> On 2/8/07, Mikael Andersson <ma...@gmail.com> wrote:
> > Looking for some more suggestions :), I would prefer not to use ajax
> since
> > it is quite a simple page.
> >
> > I have tried some more (hacky) stuff which didn't work either :( :
> >
> > The below changed the location URL, but don't load the page?? Any ideas.
> >
> > public static void programmaticForward2( final String viewId ) throws
> > IOException{
> >         FacesContext faces = FacesContext.getCurrentInstance();
> >         HttpServletResponse response = (HttpServletResponse)
> > faces.getExternalContext().getResponse();
> >
> >         response.setContentType("text/html");
> >         response.setHeader("Location", "http://localhost:8080/dss "
> > +viewId);
> >
> >         faces.responseComplete();
> >         response.getOutputStream().flush();
> >         response.getOutputStream().close();
> >
> > }
> >
> > The below didn't do anything?
> >
> > public static void programmaticForward3( final String viewId ) throws
> > IOException{
> >         FacesContext faces = FacesContext.getCurrentInstance();
> >         HttpServletResponse response = (HttpServletResponse)
> > faces.getExternalContext().getResponse();
> >         HttpServletRequest request =
> > (HttpServletRequest)faces.getExternalContext().getRequest();
> >
> >         PrintWriter out = response.getWriter();
> >
> >         response.setContentType("text/html");
> >         response.sendRedirect("http://" +request.getServerName() +":"
> > +request.getServerPort() +"/dss" +viewId);
> >
> >         faces.responseComplete();
> >         out.flush();
> >         out.close();
> >
> > }
> >
> > Cheers,
> >  Mike no.2
> >
> >
> >
> > On 07/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
> > > Here's an ajax solution for a progress bar:
> > >
> > >
> >
> http://weblogs.java.net/blog/edburns/archive/2005/05/ajaxian_faces_p.html
> > >
> >
> https://blueprints.dev.java.net/bpcatalog/ee5/ajax/usingAJAXwithoutJSF.html
> > >
> > > Seems like there should be a way to solve this without ajax, though.
> > > Maybe using a meta refresh.
> > >
> > >
> > > On 2/7/07, Mikael Andersson < mail.micke@gmail.com> wrote:
> > > > Hi,
> > > > I have an action which performs a length operation, I'd like to get
> the
> > > > browser to redisplay the page while the process keeps running on the
> > server.
> > > >
> > > > I wonder how I perform a programmatic forward which in an action
> method,
> > > > which causes the browser to re-render the page while the action
> method
> > is
> > > > still running.
> > > >
> > > > Is there a way of doing this without spawning a new Thread?
> > > >
> > > > I made the following futile attempt :
> > > >
> > > > Managed bean:
> > > >
> > > > public String longishRunningAction(){
> > > >
> > > >   try{
> > > >     NavigationUtil.programmaticForward
> > > > ("/report/index.xhtml");
> > > >   }
> > > >   catch(Exception e){}
> > > >
> > > >   doLongishRunningOperation();
> > > >
> > > >   return null;
> > > > }
> > > >
> > > >
> > > > Some of the stuff in here were added just to see if the made a
> > difference,
> > > > they didn't :)
> > > >
> > > > public class NavigationUtil {
> > > >
> > > >     /**
> > > >      * Force a forward programmatically
> > > >      *
> > > >      * @param viewId the viewId to forward to, ex.
> /report/index.xhtml
> > > >      * @throws ServletException
> > > >      * @throws IOException
> > > >      */
> > > >     public static void programmaticForward( final String viewId )
> throws
> > > > ServletException, IOException{
> > > >
> > > >         ExternalContext eCtx =
> > > > FacesContext.getCurrentInstance().getExternalContext();
> > > >         HttpServletRequest request =
> > > > (HttpServletRequest)eCtx.getRequest();
> > > >         HttpServletResponse response =
> > > > (HttpServletResponse)eCtx.getResponse();
> > > >         RequestDispatcher dispatcher = request.getRequestDispatcher(
> > viewId
> > > > );
> > > >
> > > >         dispatcher.forward(request,response);
> > > >
> > > >         FacesContext.getCurrentInstance().responseComplete();
> > > >
> > > >         response.getOutputStream().flush();
> > > >         response.getOutputStream().close();
> > > >
> > > >     }
> > > >
> > > > }
> > > >
> > > >
> > >
> >
> >
>

Re: Programmatic forward in action,

Posted by Mike Kienenberger <mk...@gmail.com>.
If it were me, I'd look at having a meta-refresh tag submit a normal action.
The action would check the status of the background process, and
either return the "in progress" page again or return the "action
completed" page.

You shouldn't need to anything strange like try to short-circult the
JSF lifecycle or manually construct a response.

On 2/8/07, Mikael Andersson <ma...@gmail.com> wrote:
> Looking for some more suggestions :), I would prefer not to use ajax since
> it is quite a simple page.
>
> I have tried some more (hacky) stuff which didn't work either :( :
>
> The below changed the location URL, but don't load the page?? Any ideas.
>
> public static void programmaticForward2( final String viewId ) throws
> IOException{
>         FacesContext faces = FacesContext.getCurrentInstance();
>         HttpServletResponse response = (HttpServletResponse)
> faces.getExternalContext().getResponse();
>
>         response.setContentType("text/html");
>         response.setHeader("Location", "http://localhost:8080/dss "
> +viewId);
>
>         faces.responseComplete();
>         response.getOutputStream().flush();
>         response.getOutputStream().close();
>
> }
>
> The below didn't do anything?
>
> public static void programmaticForward3( final String viewId ) throws
> IOException{
>         FacesContext faces = FacesContext.getCurrentInstance();
>         HttpServletResponse response = (HttpServletResponse)
> faces.getExternalContext().getResponse();
>         HttpServletRequest request =
> (HttpServletRequest)faces.getExternalContext().getRequest();
>
>         PrintWriter out = response.getWriter();
>
>         response.setContentType("text/html");
>         response.sendRedirect("http://" +request.getServerName() +":"
> +request.getServerPort() +"/dss" +viewId);
>
>         faces.responseComplete();
>         out.flush();
>         out.close();
>
> }
>
> Cheers,
>  Mike no.2
>
>
>
> On 07/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
> > Here's an ajax solution for a progress bar:
> >
> >
> http://weblogs.java.net/blog/edburns/archive/2005/05/ajaxian_faces_p.html
> >
> https://blueprints.dev.java.net/bpcatalog/ee5/ajax/usingAJAXwithoutJSF.html
> >
> > Seems like there should be a way to solve this without ajax, though.
> > Maybe using a meta refresh.
> >
> >
> > On 2/7/07, Mikael Andersson < mail.micke@gmail.com> wrote:
> > > Hi,
> > > I have an action which performs a length operation, I'd like to get the
> > > browser to redisplay the page while the process keeps running on the
> server.
> > >
> > > I wonder how I perform a programmatic forward which in an action method,
> > > which causes the browser to re-render the page while the action method
> is
> > > still running.
> > >
> > > Is there a way of doing this without spawning a new Thread?
> > >
> > > I made the following futile attempt :
> > >
> > > Managed bean:
> > >
> > > public String longishRunningAction(){
> > >
> > >   try{
> > >     NavigationUtil.programmaticForward
> > > ("/report/index.xhtml");
> > >   }
> > >   catch(Exception e){}
> > >
> > >   doLongishRunningOperation();
> > >
> > >   return null;
> > > }
> > >
> > >
> > > Some of the stuff in here were added just to see if the made a
> difference,
> > > they didn't :)
> > >
> > > public class NavigationUtil {
> > >
> > >     /**
> > >      * Force a forward programmatically
> > >      *
> > >      * @param viewId the viewId to forward to, ex. /report/index.xhtml
> > >      * @throws ServletException
> > >      * @throws IOException
> > >      */
> > >     public static void programmaticForward( final String viewId ) throws
> > > ServletException, IOException{
> > >
> > >         ExternalContext eCtx =
> > > FacesContext.getCurrentInstance().getExternalContext();
> > >         HttpServletRequest request =
> > > (HttpServletRequest)eCtx.getRequest();
> > >         HttpServletResponse response =
> > > (HttpServletResponse)eCtx.getResponse();
> > >         RequestDispatcher dispatcher = request.getRequestDispatcher(
> viewId
> > > );
> > >
> > >         dispatcher.forward(request,response);
> > >
> > >         FacesContext.getCurrentInstance().responseComplete();
> > >
> > >         response.getOutputStream().flush();
> > >         response.getOutputStream().close();
> > >
> > >     }
> > >
> > > }
> > >
> > >
> >
>
>

Re: Programmatic forward in action,

Posted by Mikael Andersson <ma...@gmail.com>.
Looking for some more suggestions :), I would prefer not to use ajax since
it is quite a simple page.

I have tried some more (hacky) stuff which didn't work either :( :

The below changed the location URL, but don't load the page?? Any ideas.

public static void programmaticForward2( final String viewId ) throws
IOException{
        FacesContext faces = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse)
faces.getExternalContext().getResponse();

        response.setContentType("text/html");
        response.setHeader("Location", "http://localhost:8080/dss" +viewId);

        faces.responseComplete();
        response.getOutputStream().flush();
        response.getOutputStream().close();

}

The below didn't do anything?

public static void programmaticForward3( final String viewId ) throws
IOException{
        FacesContext faces = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse)
faces.getExternalContext().getResponse();
        HttpServletRequest request =
(HttpServletRequest)faces.getExternalContext().getRequest();

        PrintWriter out = response.getWriter();

        response.setContentType("text/html");
        response.sendRedirect("http://" +request.getServerName() +":"
+request.getServerPort() +"/dss" +viewId);

        faces.responseComplete();
        out.flush();
        out.close();

}

Cheers,
 Mike no.2


On 07/02/07, Mike Kienenberger <mk...@gmail.com> wrote:
>
> Here's an ajax solution for a progress bar:
>
> http://weblogs.java.net/blog/edburns/archive/2005/05/ajaxian_faces_p.html
>
> https://blueprints.dev.java.net/bpcatalog/ee5/ajax/usingAJAXwithoutJSF.html
>
> Seems like there should be a way to solve this without ajax, though.
> Maybe using a meta refresh.
>
>
> On 2/7/07, Mikael Andersson <ma...@gmail.com> wrote:
> > Hi,
> > I have an action which performs a length operation, I'd like to get the
> > browser to redisplay the page while the process keeps running on the
> server.
> >
> > I wonder how I perform a programmatic forward which in an action method,
> > which causes the browser to re-render the page while the action method
> is
> > still running.
> >
> > Is there a way of doing this without spawning a new Thread?
> >
> > I made the following futile attempt :
> >
> > Managed bean:
> >
> > public String longishRunningAction(){
> >
> >   try{
> >     NavigationUtil.programmaticForward
> > ("/report/index.xhtml");
> >   }
> >   catch(Exception e){}
> >
> >   doLongishRunningOperation();
> >
> >   return null;
> > }
> >
> >
> > Some of the stuff in here were added just to see if the made a
> difference,
> > they didn't :)
> >
> > public class NavigationUtil {
> >
> >     /**
> >      * Force a forward programmatically
> >      *
> >      * @param viewId the viewId to forward to, ex. /report/index.xhtml
> >      * @throws ServletException
> >      * @throws IOException
> >      */
> >     public static void programmaticForward( final String viewId ) throws
> > ServletException, IOException{
> >
> >         ExternalContext eCtx =
> > FacesContext.getCurrentInstance().getExternalContext();
> >         HttpServletRequest request =
> > (HttpServletRequest)eCtx.getRequest();
> >         HttpServletResponse response =
> > (HttpServletResponse)eCtx.getResponse();
> >         RequestDispatcher dispatcher = request.getRequestDispatcher(
> viewId
> > );
> >
> >         dispatcher.forward(request,response);
> >
> >         FacesContext.getCurrentInstance().responseComplete();
> >
> >         response.getOutputStream().flush();
> >         response.getOutputStream().close();
> >
> >     }
> >
> > }
> >
> >
>

Re: Programmatic forward in action,

Posted by Mike Kienenberger <mk...@gmail.com>.
Here's an ajax solution for a progress bar:

http://weblogs.java.net/blog/edburns/archive/2005/05/ajaxian_faces_p.html
https://blueprints.dev.java.net/bpcatalog/ee5/ajax/usingAJAXwithoutJSF.html

Seems like there should be a way to solve this without ajax, though.
Maybe using a meta refresh.


On 2/7/07, Mikael Andersson <ma...@gmail.com> wrote:
> Hi,
> I have an action which performs a length operation, I'd like to get the
> browser to redisplay the page while the process keeps running on the server.
>
> I wonder how I perform a programmatic forward which in an action method,
> which causes the browser to re-render the page while the action method is
> still running.
>
> Is there a way of doing this without spawning a new Thread?
>
> I made the following futile attempt :
>
> Managed bean:
>
> public String longishRunningAction(){
>
>   try{
>     NavigationUtil.programmaticForward
> ("/report/index.xhtml");
>   }
>   catch(Exception e){}
>
>   doLongishRunningOperation();
>
>   return null;
> }
>
>
> Some of the stuff in here were added just to see if the made a difference,
> they didn't :)
>
> public class NavigationUtil {
>
>     /**
>      * Force a forward programmatically
>      *
>      * @param viewId the viewId to forward to, ex. /report/index.xhtml
>      * @throws ServletException
>      * @throws IOException
>      */
>     public static void programmaticForward( final String viewId ) throws
> ServletException, IOException{
>
>         ExternalContext eCtx =
> FacesContext.getCurrentInstance().getExternalContext();
>         HttpServletRequest request =
> (HttpServletRequest)eCtx.getRequest();
>         HttpServletResponse response =
> (HttpServletResponse)eCtx.getResponse();
>         RequestDispatcher dispatcher = request.getRequestDispatcher( viewId
> );
>
>         dispatcher.forward(request,response);
>
>         FacesContext.getCurrentInstance().responseComplete();
>
>         response.getOutputStream().flush();
>         response.getOutputStream().close();
>
>     }
>
> }
>
>