What is the best way to make "Back" links, so that the application stays consistent after navigation.
onclick="history.go(-1)"
. Is this very harmful?<f:setPropertyActionListener>
.Any help would be appreciated! Share your thoughts! Daniel
If you want to solve this by programmed navigation links, you can use a LinkedList
as a stack. This way you can set boundaries for the number of stored navigation cases.
Example:
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();
}
}
So in 'forward' links:
<h:commandLink value="Forward" action="#{myBean.someMethod}">
<f:setPropertyActionListener target="#{backNavigationBean.lastPage}"
value="back_to_index" />
</h:commandLink>
And a 'back' link would be:
<h:commandLink value="Back"
action="#{backNavigationBean.getLastPage}" />
I'm using:
<redirect />
for each navigation ruleThis ensures that on pressing the "back" button or history.go(-1)
:
P.S. "backlink" has a different meaning
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With