Disable page jumping to the top after commandButton is clicked

大憨熊 提交于 2019-12-11 08:28:35

问题


I got a <h:commandbutton> like

<h:commandButton value="Neuer Abschnitt"
styleClass="btn btn-primary btn-info"
action="#{beitragBearbeitenBean.erstelleAbschnitt}" />

Well, I click onto the button, the method is called and after that, the page is jumping to the top (provied you are not at the top!)

Interestingly, a

<f:ajax execute="@form" />

does offer a little jump up.

How can I avoid a jump, generally?


回答1:


an <h:commandButton> doess a full post of the page, no ajax stuff. So it is normal to jump back to the top of the same page (assuming your action returns null or is void). The <f:ajax> makes it refresh the form and most likely jumps to the top of the form (if the button you use is also in that form). Updating parts of the form (e.g. a panel inside the form) and not update the button since it can stay ourtside the panel most likely will cause that you stay at the same spot. But if the size of the panel changes, it might not (but then you can e.g. make your pannel scrollable so the button will not move).



来源:https://stackoverflow.com/questions/28629407/disable-page-jumping-to-the-top-after-commandbutton-is-clicked

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!