Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:29:48+00:00 2026-06-04T00:29:48+00:00

i am using jsf 2.0 i have question accoring to PreRenderView. in my Bean

  • 0

i am using jsf 2.0

i have question accoring to PreRenderView.

in my Bean i have method like

public void init() throws Exception
    {

        FacesContext.getCurrentInstance().getExternalContext().redirect("/To My Page");
        if(!FacesContext.getCurrentInstance().isPostback())
        {
            System.out.println("Kshitij");
        }
    }

when this method is executing it is also printing “Kshitij” in servler log.

then redirecting to page.

why? i think it has to redirect to page first.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:29:49+00:00Added an answer on June 4, 2026 at 12:29 am

    Why do you think that the actual redirect is performed first? The method has to finish running first before the server can ever continue the control over the request/response. It’s impossible to pause code execution halfway and then continue code execution at exactly the same location in a brand new request and thread.

    The redirect() call basically sets the Location response header. Only when the method has returned, the server will send the response and then the browser will send a new request on that location.

    Add a return statement or an if/else if you want to skip the printing when you need to redirect.

    if (youNeedToRedirect) {
        FacesContext.getCurrentInstance().getExternalContext().redirect("/To My Page");
    }
    else {
        if (!FacesContext.getCurrentInstance().isPostback()) {
            System.out.println("Kshitij");
        }
    }
    

    This all has got nothing to do with JSF or preRenderView. It’s all just basic Java and HTTP.

    Related:

    • java.lang.IllegalStateException: Cannot (forward | sendRedirect | create session) after response has been committed
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have created a demo application Using JSF & EJB 3.0 (Stateless session bean
I'm using JSF 2.0. I have a managed bean which I can access through
I am using JSF and spring . I have a spring managed bean in
Hi there Im just learning JSF 2 using Primefaces. I have a question regarding
I have a question about integrating jquery library with JSF 2.0 when using <h:outputScript
I have a JSF 2.0 bean: @ManagedBean @SessionScoped public class LoginBean implements Serializable {
I am using JSF and have made a custom servlet for loading images dynamically.
I'm using JSF 1.2 with Richfaces and Facelets. I have an application with many
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
I am using Struts Tiles with JSF to have one header, menu and footer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.