“返回”的最佳实践JSF 中的导航链接

发布于 2024-08-20 01:04:22 字数 296 浏览 2 评论 0原文

制作“后退”链接的最佳方法是什么,以便应用程序在导航后保持一致。

  • onclick="history.go(-1)"。这是非常有害的吗?
  • 在支持 bean 中使用堆栈来弹出最后一个视图的导航情况。您可以通过使用 设置导航案例来完成此操作。
  • 这些都不是……其他解决方案。

任何帮助将不胜感激!分享你的想法! 丹尼尔

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?
  • Using a stack in a backing bean that pops you the navigation case of the last view. You can do this by setting the navigation case with <f:setPropertyActionListener>.
  • None of these... other solutions.

Any help would be appreciated! Share your thoughts!
Daniel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里的微风 2024-08-27 01:04:22

如果您想通过编程导航链接来解决此问题,可以使用 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}" />

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}" />
桃酥萝莉 2024-08-27 01:04:22

我正在使用:

这确保了按下“后退”按钮或 history.go(-1) 时:

  • 前一屏幕中可用的数据仍然存在(因为对话仍处于活动状态)
  • “重新提交”浏览器对话框将不会打开。

PS "backlink" 有不同的含义

I'm using:

  • MyFaces orchestra for providing conversation scope
  • <redirect /> for each navigation rule

This ensures that on pressing the "back" button or history.go(-1):

  • the data that has been available in the previous screen will be still there (because the conversation is still active)
  • the "resubmit" browser dialog won't open.

P.S. "backlink" has a different meaning

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文