我上的index.xhtml和我有這樣的代碼片段:分頁對JSF使用get參數
<h:form>
<h:commandButton action="#{blogentryListerBean.olderBlogEntries}"
value="Older Blog Entries"/>
</h:form>
BlogEntryListerBean是RequestScoped。這是olderBlogEntries
public String olderBlogEntries() {
HttpServletRequest request
= (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String id = request.getParameter("id");
if (id == null || id.equals("")) {
id = "0";
}
int pageIamOn = Integer.valueOf(id);
String stringToBeReturned = "index.xhtml?id=" + (pageIamOn + 1) + "&faces-redirect=true";
return stringToBeReturned;
}
所以,當我打的index.xhtml,第一次我看到的網址是代碼我有:的index.xhtml預期。 我第一次點擊按鈕「老年博客文章」我看網址:??的index.xhtml ID = 1 現在,當我打了舊的博客條目按鈕,我再次上的index.xhtml ID = 1
是什麼這裏錯了嗎?爲什麼我不去index.xhtml?id = 2
?
謝謝。
但也許你需要指定id ant標籤命令按鈕.. – ZaoTaoBao
@ZaoTaoBao對不起? –
你試圖用request.getParameter(「id」)恢復一個html標籤..這個參數在哪裏?永遠是空的?所以總是在第1頁。如果我不正確理解 – ZaoTaoBao