I want to have a simple paging mechanism so when I call /allhotels?page=2
I want to go back to /allhotels?page=1
or forth to /allhotels?page=3
. I have 2 simple buttons:
<h:form>
<h:commandButton value="previous" action="#{hotelSearchResult.toPreviousPage}" />
<h:commandButton value="next" action="#{hotelSearchResult.toNextPage}" />
</h:form>
Which should redirect to the next/previous page of a data set:
public int getPreviousPage() {
return page > 0 ? page - 1 : 0;
}
public void toPreviousPage() {
int previous = getPreviousPage();
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
String url = context.getRequestContextPath() + "/allhotels?page=" + previous;
try {
context.redirect(url);
} catch (IOException e) {
e.printStackTrace();
}
}
public int getNextPage() {
return hotels != null && hotels.size() == 100 ? page + 1 : page;
}
public void toNextPage() {
int next = getNextPage();
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
String url = context.getRequestContextPath() + "/allhotels?page=" + next;
try {
context.redirect(url);
} catch (IOException e) {
e.printStackTrace();
}
}
but it only calls /pages/allhotels.xhtml
?
I have tried so many things but it never worked:
<f:viewParam name="page" value="#{hotelSearchResult.page}" />
<h:commandButton value="vor" action="#{hotelSearchResult.toNextPage}">
<f:param name="page" value="#{hotelSearchResult.nextPage}" />
</h:commandButton>
faces.config.xml:
<navigation-rule>
<from-view-id>/allhotels</from-view-id>
<navigation-case>
<from-outcome>*</from-outcome>
<to-view-id>*</to-view-id>
<redirect>
<redirect-param>
<name>page</name>
<value>*</value>
</redirect-param>
</redirect>
</navigation-case>
</navigation-rule>
The 2 methods To...Page() dont even get invoked ... can somebody tell me how I can get the simplest paging mechanism possible? I already lost 2 hours ...