jsf - Primefaces RequestContext scrollTo does not work -


primefaces v3.5

trying use requestcontext.getcontext().scrollto("") scroll form programmatically @ end of ajax request.

xhtml snippets:

<h:form id="genericmessagesform">                     <p:messages id="genericmessages" />                 </h:form> <p:commandbutton id="testbutton"              value="test" process="#{cc.attrs.itemname}final, @this"                 actionlistener="#{mybean.methodcalledbyajax()}" /> 

bean:

public void methodcalledbyajax() {     list<string> updatetargets = new arraylist<string>();                 updatetargets.add("currentrecordform");                 updatetargets.add("genericmessagesform");                 requestcontext.getcurrentinstance().update(updatetargets);                 requestcontext.getcurrentinstance().scrollto("genericmessagesform"); } 

update does work.

scrollto does not work (same id!).

no server errors thrown.

no javascript console errors thrown.

browsers tried: firefox (latest), chrome (latest), ie8.

did in documentation? here's cite requestcontext#scrollto() javadoc:

scrollto

public abstract void scrollto(string clientid)

scroll component after ajax request completed.

parameters:

clientid - client side identifier of component.

look, says client id, not component id. makes sense, scrolling job done javascript via document.getelementbyid() , friends. works client id.

for starters haven't memorized whole namingcontainer thing, easy way figure right client id looking @ jsf-generated html output via rightclick, view source in webbrowser.

for

<h:form id="genericmessagesform">     <p:messages id="genericmessages" /> </h:form> 

that's like

<form id="genericmessagesform" ...>     <div id="genericmessagesform:genericmessages" ...>         ...     </div> </form> 

so, fix call accordingly:

requestcontext.scrollto("genericmessagesform:genericmessages"); 

by way, if form contains solely <p:messages>, can alternatively rid of whole form altogether. <p:messages> not editablevalueholder nor actionsource component , therefore not require placed in uiform component. way can keep using initial attempt.

see also:


Comments