Best practices for “Back” navigation links in JSF

前端 未结 2 928
耶瑟儿~
耶瑟儿~ 2021-02-09 03:36

What is the best way to make \"Back\" links, so that the application stays consistent after navigation.

  • onclick=\"history.go(-1)\". Is this very harmf
2条回答
  •  南笙
    南笙 (楼主)
    2021-02-09 04:08

    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();
        }
        private LinkedList 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:

    
        
    
    

    And a 'back' link would be:

    
    

提交回复
热议问题