JSF 2和发布/重定向/获取?

编程入门 行业动态 更新时间:2024-10-10 11:28:52
本文介绍了JSF 2和发布/重定向/获取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我写错了,请纠正我,但是我认为我的所有非AJAX提交者都应该使用发布/重定向/获取(PRG)方式,因为应该使用GET刷新/查询数据,并且就我而言,我能想到的应用程序页面实际上只对数据进行更新,然后刷新页面,因此我认为PRG适合此处.

Please correct me if I'm wrong, but I'm thinking of all of my non-AJAX submits should use the Post/Redirect/Get (PRG) way, since GET should be used to refresh/query data, and in my case, the application pages I can think of really only do update on the data and then refresh the page, so I think PRG fits here.

我相信我可以使用faces-config.way(在其中使用<redirect/>)进行操作,也可以使用return "myview.xhtml?faces-redirect=true";

I believe I can do this using the faces-config.way, where I make use of the <redirect/>, or I can use the return "myview.xhtml?faces-redirect=true";

现在的问题是..

有什么办法可以全局配置该配置,以便非AJAX调用/提交自动使用faces-redirect = true,这样我的源代码就这么简单:

Is there any way I can configure this globally that for non-AJAX calls/submits, automatically make use of faces-redirect=true, so that my source is as simple as this:

return "myview";

推荐答案

您可以使用自定义的 ConfigurableNavigationHandler .这是一个启动示例:

You could do this with a custom ConfigurableNavigationHandler. Here's a kickoff example:

package com.example; import java.util.Map; import java.util.Set; import javax.faces.application.ConfigurableNavigationHandler; import javax.faces.application.NavigationCase; import javax.faces.application.NavigationHandler; import javax.faces.context.FacesContext; public class RedirectNavigationHandler extends ConfigurableNavigationHandler { private NavigationHandler parent; public RedirectNavigationHandler(NavigationHandler parent) { this.parent = parent; } @Override public void handleNavigation(FacesContext context, String from, String outcome) { if (!outcome.endsWith("?faces-redirect=true")) { outcome += "?faces-redirect=true"; } parent.handleNavigation(context, from, outcome); } @Override public NavigationCase getNavigationCase(FacesContext context, String fromAction, String outcome) { if (parent instanceof ConfigurableNavigationHandler) { return ((ConfigurableNavigationHandler) parent).getNavigationCase(context, fromAction, outcome); } else { return null; } } @Override public Map<String, Set<NavigationCase>> getNavigationCases() { if (parent instanceof ConfigurableNavigationHandler) { return ((ConfigurableNavigationHandler) parent).getNavigationCases(); } else { return null; } } }

在faces-config.xml中进行如下注册:

<application> <navigation-handler>com.example.RedirectNavigationHandler</navigation-handler> </application>

更多推荐

JSF 2和发布/重定向/获取?

本文发布于:2023-10-12 05:10:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483806.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   JSF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!