Rectangle 27 5

Did you look in the documentation? Here's a cite from the RequestContext#scrollTo() javadoc:

public abstract void scrollTo(String clientId)

clientId - Client side identifier of the component.

Look, it says client ID, not component ID. It makes also sense, the scrolling job is ultimately done by JavaScript via document.getElementById() and friends. That works only with a client ID.

For starters who haven't memorized the whole NamingContainer thing, an easy way to figure the right client ID is by looking at the JSF-generated HTML output via rightclick, View Source in webbrowser.

For a

<h:form id="genericMessagesForm">
    <p:messages id="genericMessages" />
</h:form>
<form id="genericMessagesForm" ...>
    <div id="genericMessagesForm:genericMessages" ...>
        ...
    </div>
</form>

So, fix the call accordingly:

requestContext.scrollTo("genericMessagesForm:genericMessages");

By the way, if the form contains solely the <p:messages>, then you can alternatively also just get rid of the whole form altogether. The <p:messages> is not an EditableValueHolder nor ActionSource component and does therefore not require to be placed in an UIForm component. This way you can keep using your initial attempt.

D'oh, of course! Thanks again BalusC and also for the explanation about not needing the form :-)

jsf - Primefaces RequestContext scrollTo does not work - Stack Overflo...

jsf primefaces requestcontext
Rectangle 27 0

Did you look in the documentation? Here's a cite from the RequestContext#scrollTo() javadoc:

public abstract void scrollTo(String clientId)

clientId - Client side identifier of the component.

Look, it says client ID, not component ID. It makes also sense, the scrolling job is ultimately done by JavaScript via document.getElementById() and friends. That works only with a client ID.

For starters who haven't memorized the whole NamingContainer thing, an easy way to figure the right client ID is by looking at the JSF-generated HTML output via rightclick, View Source in webbrowser.

For a

<h:form id="genericMessagesForm">
    <p:messages id="genericMessages" />
</h:form>
<form id="genericMessagesForm" ...>
    <div id="genericMessagesForm:genericMessages" ...>
        ...
    </div>
</form>

So, fix the call accordingly:

requestContext.scrollTo("genericMessagesForm:genericMessages");

By the way, if the form contains solely the <p:messages>, then you can alternatively also just get rid of the whole form altogether. The <p:messages> is not an EditableValueHolder nor ActionSource component and does therefore not require to be placed in an UIForm component. This way you can keep using your initial attempt.

D'oh, of course! Thanks again BalusC and also for the explanation about not needing the form :-)

jsf - Primefaces RequestContext scrollTo does not work - Stack Overflo...

jsf primefaces requestcontext