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:
1. 通过<>建筑/建筑>启动:
@Component("user")
@Scope("view")
public class MyBean {
private List<User> usersList;
public MyBean() {
usersList=userService.getUsers();
}
}
通过<>前活动启动:
@Component("user")
@Scope("view")
public class MyBean {
private List<User> usersList;
public void preRender(ComponentSystemEvent event){
if(usersList!=null)
usersList=userService.getUsers();
}
}
最初通过@PostConstruct。
@Component("user")
@Scope("view")
public class MyBean {
private List<User> usersList;
@PostConstruct
public void init() {
usersList=userService.getUsers();
}
}
请就如何在观点范围方面实现初步化提供意见,即希望一度启动变量,并在数据表中使用完全相同的变量,只要该变量仍然在同一页。