-1

尝试从第 1 页导航到第 3 页以及从第 2 页导航到第 3 页。在第 3 页中,当我单击后退按钮时,它应该导航到相应的页面。有人可以帮我实现这一目标吗?

4

2 回答 2

0

You can achieve this by having a bean which has a field storing the previous page. Then in the third page you can use the value of this field to return to the appropriate page. For example in your first page you need to have a commandLink navigating you to third page, while setting the previousPage as firstPage. Similar commandLink should be part of second page too. You need to enclose h:commandLinks in h:forms as they use post method to pass parameters.

<h:commandLink value="Third  Page" action="#{navigationPageBean.updateLastVisitedPage("/firstPage.xhtml")}"/>

<h:commandLink value="Third  Page" action="#{navigationPageBean.updateLastVisitedPage("/secondPage.xhtml")}"/>

@Named
public class NavigationPageBean implements Serializable
{
    private String previousPage;

    public String updateLastVisitedPage(String pageName)
    {
        previousPage = pageName;
        return "/thirdpage.xhtml";
    }

    public String getPreviousPage()
    {
        return previousPage;
    }

    public void setPreviousPage(String previousPage)
    {
        this.previousPage = previousPage;
    }
}

You can achieve this by using javascript methods to learn the previous page too I think, but I don't know the exact methods.

于 2013-01-04T09:20:27.023 回答
0

如果你想实现它,你必须实现基于 url 的导航。要从 1 导航到 3,您可以<h:button>使用结果属性来实现。

<h:button value="Go to third" outcome="/thirdpage.xhtml" />

您也可以指定导航规则。但是,您有几十个教程可以做到这一点。

http://www.mkyong.com/jsf2/jsf-2-button-and-commandbutton-example/

http://www.mkyong.com/jsf2/implicit-navigation-in-jsf-2-0/

JSF 2.0 隐式导航,不同的视图

为了知道你来自哪里,有不同的方法,但我认为正确的方法是使用视图参数。在按钮或链接中,您可以指定一个<f:param name="ComingFrom" value="#{sourceBean.id}" />,然后您会在目标页面中以这种方式接收它<f:viewParam id="ComingFrom" name="ComingFrom" value="#{destinationBean._ParamSourceId}" />

这样你就可以通过请求传递参数,你可以构建你的后退按钮来指向一个 url 或另一个。

你有更多的东西。

https://blogs.oracle.com/rlubke/entry/jsf_2_0_bookmarability_view

于 2013-01-04T07:29:14.357 回答