I am migrating from PrimeFaces 6.2 to 8.0. In my project I am using multiple Primeface DataTables with a Paginator.
MCVE:
Create a data list with more than 10 elements. Then click through the different page numbers. When any page number bigger than 10 is clicked or selected from the JumpToPageDropdown the console will log the following error:
Error in Chrome console:
jquery.js.xhtml?ln=primefaces&v=8.0:2 Uncaught Error: Syntax error, unrecognized expression: option[value=\31 0]
at Function.se.error (jquery.js.xhtml?ln=primefaces&v=8.0:2)
at se.tokenize (jquery.js.xhtml?ln=primefaces&v=8.0:2)
at se.compile (jquery.js.xhtml?ln=primefaces&v=8.0:2)
at se.select (jquery.js.xhtml?ln=primefaces&v=8.0:2)
at se (jquery.js.xhtml?ln=primefaces&v=8.0:2)
at Function.se.matches (jquery.js.xhtml?ln=primefaces&v=8.0:2)
at Function.k.filter (jquery.js.xhtml?ln=primefaces&v=8.0:2)
at k.fn.init.k.fn.<computed> [as children] (jquery.js.xhtml?ln=primefaces&v=8.0:2)
at c.updateUI (components.js.xhtml?ln=primefaces&v=8.0:58)
at c.updateTotalRecords (components.js.xhtml?ln=primefaces&v=8.0:58)
Used component:
<p:dataTable id="datatable"value="#{backendController.dataList}"
var="data" paginator="true" rows="1" paginatorPosition="top"
pageLinks="20"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {JumpToPageDropdown} {NextPageLink} {LastPageLink}">
-> Add a few <p:column> tags.
</p:dataTable>
Temporary fix:
I was able to identify that JumpToPageDropdown is causing the error. When this is removed from the paginatorTemplate the error will not be shown anymore when clicking on pages greater than 10. Unfortunately I want to use this dropdown.
Further research:
PrimeFaces uses these JS files for their components and hence also for the JumpToPageDropdown:
- PrimeFaces 6.2: components.js.xhtml?ln=primefaces&v=6.2 PrimeFaces
- PrimeFaces 8.0: components.js.xhtml?ln=primefaces&v=8.0
This are the respective calls to update the
Both versions:
this.jtpSelect = this.jq.children(".ui-paginator-jtp-select");
PrimeFaces 8.0:
this.jtpSelect.children("option[value=" + $.escapeSelector(this.cfg.page) + "]").prop("selected", "selected")
PrimeFaces 6.2:
this.jtpSelect.children("option[value=" + (this.cfg.page) + "]").prop("selected", "selected")
The difference is that in version 8.0 the value of this.cfg.page
is passed to the function $.escapeSelector()
.
this.cfg.page
uses zero-based numbering. Page 1 is 0, page 10 is 9 and so on. In version 6.2 this.jtpSelect.children()
would be called with option[value=10] when the selected page is 11. But in version 8.0 $.escapeSelector()
would format the same input to \31 0
and results in option[value=\31 0]
.
This in consequence leads to the error mentioned above. See this line: Uncaught Error: Syntax error, unrecognized expression: option[value=\31 0]
Recommendation:
If this is a bug $.escapeSelector()
should be removed from this function in PrimeFaces 8.0, there is apparently no need for escaping: Numbers do not need to be escaped.