简体   繁体   English

如何使用PrettyFaces重定向回同一页面?

[英]How to redirect back to the same page using PrettyFaces?

I'd like to know how to redirect to the same page on action call. 我想知道如何在动作调用中重定向到同一页面。

I have this commandButton: 我有这个命令按钮:

<h:commandButton action="#{someBean.edit}" value="Edit" />

This is the action: 这是动作:

@Named
@RequestScoped
public class SomeBean {

    public String edit() {
        // some logic
        return "theSamePage?faces-redirect=true";
    }

}

But it doesn't redirect to the same page, it just refreshes it so when I try to refresh the page by pressing F5 key, the duplicate submission occurs. 但是它不会重定向到同一页面,它只是刷新它,所以当我尝试按F5键刷新页面时,就会出现重复提交。 This can be solved, under normal circumstances, with post/redirect/get. 通常情况下,这可以通过post / redirect / get解决。 But faces won't send the redirect when the action method returns the same viewId as the viewId of the page that the request is send from. 但是,当action方法返回与发送请求的页面的viewId相同的viewId时,面孔将不会发送重定向。

I use prettyfaces. 我用漂亮的脸蛋。

return "pretty:"; 

几乎就是您所需要的。

I have done some searching and rewriting my answer: 我已经做了一些搜索并重写了我的答案:

The view id in pretty faces you can get by doing this: 您可以通过执行以下操作获得漂亮的视图ID:

      PrettyContext prettyContext = PrettyContext.newInstance((HttpServletRequest) request); 
      String viewId = prettyContext.getCurrentCalculatedViewId();

Check this for more information: https://groups.google.com/group/prettyfaces-users/browse_thread/thread/f50482709d7ec69b?pli=1 检查此以获得更多信息: https : //groups.google.com/group/prettyfaces-users/browse_thread/thread/f50482709d7ec69b?pli=1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM