简体   繁体   中英

back commandbutton in jsf

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.

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?

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

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

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.

You can use:

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

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

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

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;"/>

PS- 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 false it started working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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