JSF scroll bar at the top of the page

I was wondering how to make the browser scrollbar. go to the top of the page. I am developing a registration screen that is too large and contains some fields that are needed. He displayed an error message to the user if the required fields were not informed. The problem is that the scrollbar does not rise, and I want it to move to the top of the page. I use Primefaces and jQuery, but this does not work.

+4
source share
2 answers
<div id="msg"> 

Content Page

  onclick="javascript:window.location='#msg'" 
+3
source

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

First add the JavaScript function:

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

validationFailed is a callback parameter that PrimeFaces implicitly adds if validation fails.

Now commandButton :

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

This will call the JavaScript function after the completion of the AJAX request.

This is as far as I can guess, you did not provide a lot of information. Adapt this code to your needs.

+1
source

All Articles