如果要通過編程導航鏈接解決此問題,可以使用LinkedList
作爲堆棧。這樣您可以爲存儲的導航案例數量設置邊界。
例子:
public class BackNavigationBean {
public BackNavigationBean() {
history = new LinkedList<String>();
}
private LinkedList<String> history;
public LinkedList getHistory() {
return history;
}
public void setLastPage(String navigationCase) {
history.push(navigationCase);
if (history.size() > 10) {
history.pollLast();
}
}
public String getLastPage() {
return history.pop();
}
}
所以在 '前進' 鏈接:
<h:commandLink value="Forward" action="#{myBean.someMethod}">
<f:setPropertyActionListener target="#{backNavigationBean.lastPage}"
value="back_to_index" />
</h:commandLink>
和 '回' 鏈接將是:
<h:commandLink value="Back"
action="#{backNavigationBean.getLastPage}" />
嗨。這個Bean的範圍是什麼?因爲如果它是SessionScoped,那麼管理導航將會非常困難,因爲堆棧將被鏈接推送,最終導致錯誤的導航。 – LupoZ 2017-04-21 13:39:12