The problem is that your bean is created as @RequestScoped
, so it will be recreated on every request. In order to make it live longer you should wide the scope at least to @ViewScoped
. In this way, the bean will live while the client is in the same view, it is very useful when handling ajax requests in the same view.
Also, you should remove any business logic from the getters/setters of your fields since the getters may be called several times by the view (JSP or Facelets). You should load any initial data for your bean in a @PostConstruct
annotated method.
Your bean should look like this:
@ManagedBean
@ViewScoped
public class ShowRecords {
//fields declaration
@PostConstruct
public void init() {
//initialize your fields here
//logifc to initialize dataList goes here
}
//getters, setters and other methods...
}
More info:
Not part of the answer, but since you're using JSF 2 and PrimeFaces 4, you should stop using JSP as your view technology and move to Facelets.