ScrollPosition

The ScrollPosition component is a non-visual component that controls the scroll position of the page. By using it, you can specify the position of the scroll when the page is loaded and save the scroll position between page submissions. Note that there can be only one ScrollPosition component on the page.

API Reference | Tag Reference

Specifying Scroll Position Component

To add the ScrollPosition component on the page, use the <q:scrollPosition> tag. When this component is added, the scroll position is saved automatically.

The ScrollPosition component has a boolean autoSaveScrollPos attribute. By default, it is set to "true", which means that the scroll position is saved between page submissions.

<h:form>
  <q:scrollPosition autoSaveScrollPos="true"/>
</h:form>

Specifying Scroll Position on Page Load

You can specify the position of the scroll on page load by using the int scrollX and scrollY attributes. In these attributes, you should specify the x and y coordinates of the left bottom corner of the currently visible page.

<h:form>
  <q:scrollPosition scrollX="0"
                      scrollY="700"/>
</h:form>

If the autoSaveScrollPos attribute is set to "true", the scroll position is saved into the scrollX and scrollY attributes between page submissions.

Tracking Scroll Position For the Entire Application

You can also set the teamdev.jsf.autoSaveScrollPos context attribute in web.xml to "true" (the default is "false") to track the scroll position for all application pages.

<context-param>
  <param-name>teamdev.jsf.autoSaveScrollPos</param-name>
  <param-value>true</param-value>
</context-param>
QuipuKit