Ich möchte einen einfachen Paging-Mechanismus haben, wenn ich also /allhotels?page=2
anrufen möchte, gehe ich zurück zu /allhotels?page=1
oder weiter zu /allhotels?page=3
. Ich habe 2 einfache Tasten:JSF commandButton Weiterleitung zur nächsten/vorherigen Seite funktioniert nicht
<h:form>
<h:commandButton value="previous" action="#{hotelSearchResult.toPreviousPage}" />
<h:commandButton value="next" action="#{hotelSearchResult.toNextPage}" />
</h:form>
Welche zum nächsten/vorherigen Seite eines Datensatzes umleiten sollte:
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();
}
}
aber es ruft nur /pages/allhotels.xhtml
?
Ich habe so viele Dinge ausprobiert, aber es hat nie funktioniert:
<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>
Die 2 Methoden ... Seite() nicht sogar aufgerufen bekommen. Kann mir jemand sagen, wie ich den einfachsten Paging-Mechanismus bekommen kann? Ich habe bereits 2 Stunden verloren ...