问题
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