cancel
Showing results for 
Search instead for 
Did you mean: 

Redirecting from dialog to web script

oltchuva
Champ in-the-making
Champ in-the-making
I have 2 separate working pieces: custom dialog and web script
I want to use properties entered by user in the dialog to add parameters to web script url

In finishImpl method of the dialog i try to redirect to the web script and I get the following error: java.lang.IllegalStateException: Cannot forward after response has been committed

      protected String finishImpl(FacesContext context, String outcome) throws Exception
      {
         ExternalContext externalContext = context.getExternalContext();
         HttpServletResponse response =  (HttpServletResponse)externalContext.getResponse();
         try {
            response.sendRedirect("<web_script_url_is_here>");
         } catch (Exception e) {
         }
        
         // return the default outcome
         return outcome;
      }

Thank you,
Olga
3 REPLIES 3

samuel_penn
Champ in-the-making
Champ in-the-making
Hi Olga,

I don't know anything about how dialogs are implemented in the context of what you're doing, but in the general case of setting HTTP response data from Java (from my experience with basic Servlets), anything which affects the headers has to be done before any output is written back to the client - i.e., setting a redirect has to be the first thing that you do. Given that the method is called finishImpl(), I'm guessing that this is happening last, and some output has already been written to the response buffer by this point, which is why you get that error.

Sam.

oltchuva
Champ in-the-making
Champ in-the-making
Hi Sam,

How can can I open this URL in a new window? This would be optimal solution for me

Thank you,
Olga

oltchuva
Champ in-the-making
Champ in-the-making
Update:

so my problem was
I had 2 separate working pieces: custom dialog and web script
I wanted to pass properties entered by user in the dialog as parameters to web script url

I couldn't redirect from finishImpl() method, so i did the following:
1) added additional button to dialog called "Update link"
2) when this button is clicked updateLink() method of the bean is called
3) updateLink() method combines web script url with values entered by user and saves it as bean's property
4) dialog's jsp then displays the updated link as href
5) when user clicks on the link, it opens web script page in a separate window

It's not straight forward, but it works. If you know the better way, please share 😃

Olga