Assuming you are using JSF 2.2, you could use the viewParam
to retrieve the page in the GET parameters and viewAction
to call a method before the rendering (actually called in the INVOKE_APPLICATION
phase by default).
Facelets:
<f:metadata>
<f:viewParam name="page" value="#{articleIndexBean.entityPage}" />
<f:viewAction action="#{articleIndexBean.loadScreenSupport}" />
</f:metadata>
If you are using JSF 2.0 or JSF 2.1, then you have to replace viewAction
by:
<f:event type="preRenderView" listener="#{articleIndexBean.loadScreenSupport}" />
Java:
@Named
@SessionScoped
public class ArticleIndexBean {
List<Article> articleList=new ArrayList<>();
List<Article> articleSubList=new ArrayList<>();
int pageNumber = 1; // by default first page
public void loadScreenSupport() {
search();
toEntityPage(pageNumber);
}
public int getPageNumber() {
return pageNumber;
}
public void setPageNumber(int pageNumber) {
this.pageNumber = pageNumber;
}
protected void search() {
// this method sets articleList which is the full list fetched from the database
}
public void toEntityPage(int pageNumber) {
// this method sets articleSubList which is a subset of articleList
}
}
The link to the page is then easy:
<h:outputLink value="resultPage.xhtml">
<h:outputText value="2" />
<f:param name="page" value="2" />
</h:outputLink>
Reference: