私は/allhotels?page=2
と呼ぶと、簡単なページングの仕組みを持っています。/allhotels?page=1
または/allhotels?page=3
に戻ってみたいと思います。JSF commandButton next/previousページへのリダイレクトが機能しません
<h:form>
<h:commandButton value="previous" action="#{hotelSearchResult.toPreviousPage}" />
<h:commandButton value="next" action="#{hotelSearchResult.toNextPage}" />
</h:form>
データセットの次/前のページにリダイレクトする必要があります:
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();
}
}
しかし、それは唯一の/pages/allhotels.xhtml
を呼び出して、私は2つのシンプルなボタンがありますか?
私はたくさんのことを試してみましたが、それは働いたことはない:
<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>
2つの方法には...ページは、()にも呼び出されますいけません。 ..誰かが私にどのようにして最も簡単なページング機構を実現できるか教えてもらえますか?私はすでに2時間を失ってしまった...