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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:07:32+00:00 2026-05-27T01:07:32+00:00

i have a backing bean managed by spring, and it’s scope is view and

  • 0

i have a backing bean managed by spring, and it’s scope is view
and i have a users page that display all users
and i want to pass to the datatable the list of users variable, and i want to initialize this variable on construction of the page (and use this variable as long as i am still in the page), and i am confused about the best way to initialize the list of users, i have 3 ways on my mind:

Initialize through constructor:

@Component("user")
@Scope("view")
public class MyBean {

private List<User> usersList;


public MyBean() {

   usersList=userService.getUsers();

}

}

Initialize through preRender event:

@Component("user")
@Scope("view")
public class MyBean {

private List<User> usersList;


public void preRender(ComponentSystemEvent event){
  if(usersList!=null)
   usersList=userService.getUsers();
}

}

Initialize through @PostConstruct

@Component("user")
@Scope("view")
public class MyBean {

private List<User> usersList;

@PostConstruct
public void init() {

   usersList=userService.getUsers();

}


}

please advise what is the best way for initialization in the case of view scope, i want to initialize the variable once, and use the exact same variable in the datatable as long as i am still in same page.

  • 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-05-27T01:07:32+00:00Added an answer on May 27, 2026 at 1:07 am

    Initializing in constructor is only possible if the userService is not an injected dependency. I.e. when you create it manually instead of using @EJB, @Inject or @ManagedProperty or whatever Spring specific.

    If the userService is indeed an injected dependency, then the @PostConstruct is the only right way, because the dependency is injected after construction and thus it would be null in the constructor.

    The preRender method is called before every render response. It’s not called only once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume that we have Spring bean UserController with singleton scope. All my further reasoning
Say I have a JSF backing bean, request scope, that has a List as
I currently have a Richfaces dataTable bound to a backing bean that contains all
I have a search form tied to a backing bean that contains 4 input
I have a a button that is setting a property to a backing bean
Problem Description: My injected Spring bean defined as a Managed-Property to a JSF backing
Title pretty much says it all. I have a page called login.jsp: <f:view> <html>
I found that the backing bean value displayed on the JSF page will collapse
I have managed bean/backing bean and I inject there (with @EJB) session bean. Now
I have two drop downs on a page whose backing bean is Request Scoped.

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.