使用JSF导航到上一页 [英] Navigate to previous page with JSF

查看:75
本文介绍了使用JSF导航到上一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用支持bean,可以在其中保存表单并导航到此页面.

public String saveHere() {
    return Faces.getViewId() + "?faces-redirect=true&includeViewParams=true";
}

如何使用OmniFaces导航到上一页? 我的保存操作应在页面上显示编辑"按钮. 通常为列表视图(在非常项目旁边带有编辑按钮) 或其他带有(带有此项目的编辑按钮)的页面

谢谢!

解决方案

您需要从某处导航的页面ID.乍一看,将其保留在Session中似乎是一个好主意,但是,如果您在多标签中导航(通过不同的浏览器标签共享同一Http Session),这可能会一直存在冲突.

话虽如此,最适合您的情况的解决方案是将视图参数传递给版本视图,以告知您来自何处.那应该像这样简单:

<h:button outcome="edit" value="Edit registry">
    <f:param name="pageFrom" value="#{view.viewId}" />
</h:button>

然后,在您的版本视图中,将此参数绑定到您的bean:

<f:metadata>
    <f:viewParam name="pageFrom" value="#{editBean.pageFrom}" />
</f:metadata>

保存后,只需将其重定向到 EditBean.java 中的该视图即可,假设它是@ViewScoped:

public String saveHere() {
    //save here
    return pageFrom + "?faces-redirect=true&includeViewParams=true";
}

这是实现您所要求的最直接的方法.但是,您必须考虑到您所来自的页面仍然是视图参数,以便最终用户可以在此键入他想要的内容.以此行为,他可以实现重定向到其他页面而不是预期的页面.如果要避免这种情况,请使用 Flash作用域而不是视图参数. /p>

另请参见:

I use a backing bean where I can save a form and navigate to this page.

public String saveHere() {
    return Faces.getViewId() + "?faces-redirect=true&includeViewParams=true";
}

How do I navigate to the previous page with OmniFaces? My save action should result in the page where I have the "edit" button. Typically a list-view (with edit-button next to very item) or another page with (with edit-button to this item)

Thanks!

解决方案

You need the page id you're navigating from somewhere. At first look, keeping it in Session seems to be a good idea, however, this could remain in coflict if you're navigating in multi-tab (sharing same Http Session through different browser tabs).

Having said that, the most proper solution for your case is to pass a view param to your edition view telling where you're coming from. That should be as easy as this:

<h:button outcome="edit" value="Edit registry">
    <f:param name="pageFrom" value="#{view.viewId}" />
</h:button>

After that, in your edition view bind this param to your bean:

<f:metadata>
    <f:viewParam name="pageFrom" value="#{editBean.pageFrom}" />
</f:metadata>

And just redirect to that view in your EditBean.java after saving, supposing it is @ViewScoped:

public String saveHere() {
    //save here
    return pageFrom + "?faces-redirect=true&includeViewParams=true";
}

That's the most straight forward way to achieve what you ask for. However, you must take into account the page where you're coming from remains to be a view parameter, so the end user could type what he wants there. With this behaviour, he could achieve being redirected to some other page rather than the one expected. If you want to avoid that, go with the flash scope instead of view parameters.

See also:

这篇关于使用JSF导航到上一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆