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.
Asked
Active
Viewed 6,700 times
5
-
correcting: I want the scrollbar climb to the top of the page, for to do so in jsf this a little tricky. Thank you ... =] – Alfaville Feb 15 '13 at 11:47
2 Answers
2
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.

partlov
- 13,789
- 6
- 63
- 82
-
this almost everything ok, the problem is when called window.scrollTo (0, 0); does not work. The scroll bar does not go to the top of the page. – Alfaville Feb 15 '13 at 11:14
-
That function should be supported on all mayor browsers, problem must be in something else. Do you see any errors in JavaScript console? – partlov Feb 15 '13 at 11:44
-
Shows no error on the console. I put an alert () inside the function to see if it worked. And it works, but when I use window.scrollTo (0, 0); does not work. – Alfaville Feb 15 '13 at 11:57
-
-
Than maybe just `validationFailed` is not true. Debug value of this field. – partlov Feb 15 '13 at 12:11
-
ValidationFailed return the value true when there are validation errors, and it is false when there is no validation error. – Alfaville Feb 15 '13 at 12:31
-