myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikael Andersson" <mail.mi...@gmail.com>
Subject Re: Programmatic forward in action,
Date Fri, 09 Feb 2007 15:30:41 GMT
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 <mkienenb@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 <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();
> > > > > >
> > > > > >     }
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > >
> >
> >
>

Mime
View raw message