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 8786147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:32:33+00:00 2026-06-13T21:32:33+00:00

When the page loads for the first time, the @PostConstruct is called, but when

  • 0

When the page loads for the first time, the @PostConstruct is called, but when I perform a postback on this page, the @PostConstruct is called again.

How can I make it to run only on the initial request and not on every postback?

@PostContruct
public void init() {
    // charge combos....
}

public void submit() { 
    // action 
}
  • 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-13T21:32:34+00:00Added an answer on June 13, 2026 at 9:32 pm

    Apparently your bean is request scoped and thus reconstructed on every HTTP request. I’m not exactly sure why you’d like to prevent the @PostConstruct from being called again, as you would otherwise end up with an "empty" bean state which might possibly lead to form submit errors, but okay, you could add a check if the current request is not a postback.

    public void init() {
        if (!FacesContext.getCurrentInstance().isPostback()) {
            // charge combos....
        }
    }
    

    This way the "charge combos" part won’t be invoked on postbacks.

    Or, maybe your actual question is not "How to prevent postconstruct from being called on postback?", but more "How to retain the same bean instance on postback?". In that case, you’d need to put the bean in the view scope instead of in the request scope.

    @ManagedBean
    @ViewScoped
    public class Bean implements Serializable {
        // ...
    }
    

    As long as you return null from action methods, this way the same bean instance will live as long as you’re interacting with the same view by postbacks. This way the @PostConstruct won’t be invoked (simply because the bean isn’t been reconstructed).

    See also:

    • How to choose the right bean scope?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I stop my xml loading every time my index.php (template page) loads
Visit the following site in chrom and teh first time the page loads the
For first time when the page loads we are unable to retrieve selected drop
when my page loads very first time i see the watermark on the textbox
I have an application where an HTML page first loads, then an applet with
This is my first time using a rails helper, and haven't found much documentation
Let's say we have a page written in PHP. This page loads by it
I can not set the custom cells accessory view while the page loads for
This is my first time using AJAX. I'm trying to load one of my
This is my first time using jQuery (I'm familiar with Java) and I've followed

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.