java jsf中的后退命令按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/649834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 13:13:16  来源:igfitidea点击:

back commandbutton in jsf

javajsfnavigationback-button

提问by Andreas Petersson

how would one implement a back-button as a commandbutton that works universally? with back button i don't mean the browser-button, but rather a button that sits somewhere on the page. it is not always possible to use the Post-redirect-get pattern.

如何将后退按钮实现为通用的命令按钮?后退按钮不是浏览器按钮,而是位于页面某处的按钮。并非总是可以使用 Post-redirect-get 模式。

its quite impractial to pass around the information on every single where the button should point to.

在按钮应该指向的每个地方传递信息是非常不切实际的。

is there maybe a reserved keyword for a navigation rule that points to the last navigation rule applied?

是否有导航规则的保留关键字指向最后应用的导航规则?

回答by alexmeia

I use a h:commandLinkwith attribute onclick="history.go(-1)"in this case. It works universally.

在这种情况下,我使用h:commandLinkwith 属性onclick="history.go(-1)"。它普遍适用。

回答by Martlark

My first idea :

我的第一个想法:

on every

在每个

<h:commandLink .....>

and etc; store the navigation string in a bean, or even a stack, and then the back button can retrieve it and just return that as per faces-config.xml

等等; 将导航字符串存储在一个 bean 中,甚至是一个堆栈中,然后后退按钮可以检索它并根据 faces-config.xml 返回它

Second idea.

第二个想法。

But on reflection you should override or use a filter to intercept the navigation commands and push them onto a stack. Then the back button can just pop the navigation off and away you go.

但是经过反思,您应该覆盖或使用过滤器来拦截导航命令并将它们推送到堆栈中。然后后退按钮可以弹出导航并离开。

回答by Chris Dale

I would store the navigation string in a stack datatype and you use the stack.peek() to show which is the site behind you, and when its clicked you fire an action event that triggers the stack.pop()

我会将导航字符串存储在堆栈数据类型中,然后您使用 stack.peek() 来显示您身后的站点,当它被点击时,您会触发一个触发 stack.pop() 的动作事件

回答by Erick Alves

You can use:

您可以使用:

<p:commandButton onclick="window.history.back();"/>

That instruction do the same as onclick="history.go(-1)"which alexmeia has said.

该指令与onclick="history.go(-1)"alexmeia所说的相同。

回答by Shweta Rajput

I have used the "previous" button in my tab view and the navigation is working smoothly by just using

我在选项卡视图中使用了“上一个”按钮,只需使用导航即可顺利运行

 <p:commandButton value="Previous" id="PreviousOffer" onclick="window.history.go(-1);return false;"/>

P.S.- When I did not use return false;and I clicked on the previous button, it stays on the current page only. However, after adding return falseit started working.

PS-当我没有使用return false;并单击上一个按钮时,它仅停留在当前页面上。但是,添加后return false它开始工作。