Alfaville
Alfaville

Reputation: 553

JSF scroll bar at the top of the page

I was wondering how to make the scroll bar of the browser. go to top of page. I am developing a registration screen that is too big, and it contains some fields that are needed. It displayed an error message to the user if the required fields are not informed. The problem is that the scroll bar does not go up, and I want her to go to the top of the page. I'm using Primefaces and JQuery, but no this working.

Upvotes: 5

Views: 7053

Answers (2)

Alfaville
Alfaville

Reputation: 553

<div id="msg">

Content page

 onclick="javascript:window.location='#msg'"

Upvotes: 6

partlov
partlov

Reputation: 14277

I must say that your question looks like some discussion between two people, but I will try to give an answer. I suppose you have p:commandButton for submit the form.

First add JavaScript function:

<script type="text/javascript">
  function handleResponse(xhr, status, args) {
    if (args.validationFailed) {
      window.scrollTo(0, 0);
    }
  }
</script>

validationFailed is callback parameter which is added implicitly by PrimeFaces in case hen validation fails.

Now, commandButton:

<p:commandButton value="Submit" actionListener="#{myBean.submit}" oncomplete="handleResponse(xhr, status, args)"/>

This will call JavaScript function after AJAX request is completed.

This is as much as I can suggest, you didn't provide much information. Adapt this code to your needs.

Upvotes: 2

Related Questions