Tooltip: renders its children while in the middle of using WidgetBuilder
See original GitHub issueDescribe the bug Tooltip renders its children while being in the middle of using WidgetBuilder. PrimeFaces reuses a single WidgetBuilder instance. If the children use WidgetBuilder too, they risk affecting its internal state (namely the endFunction field) in such a way, that later Tooltip won’t finish its widget properly.
Reproducer
Environment:
- PF Version: 6.2.30
- PFE Version: 6.2.10
- JSF + version:
- Affected browsers: ALL
To Reproduce
Open the page, see error in console (Uncaught SyntaxError: Unexpected end of input
in Firefox).
Expected behavior No errors, valid markup.
Sample XHTML
<pe:tooltip>
<p:dataGrid columns="1">
Ayy
</p:dataGrid>
</pe:tooltip>
Furthermore
Related discussion and changes here: https://github.com/primefaces/primefaces/issues/3110#issuecomment-354194466 - this is when @tandraschko changed wb.append("},true);});");
to wb.finish()
, which uncovered the problem.
Now, seemingly by a happy accident, this problem doesn’t happen in PF10+PFE10. Because WidgetBuilder gets inited with endFunction=false not on a widget by widget basis anymore, but:
if ((context.isPostback() && context.getPartialViewContext().isAjaxRequest()) || configuration.isMoveScriptsToBottom()) {
this.init(widgetClass, widgetVar, id, false);
}
else {
context.getResponseWriter().write("$(function(){");
this.init(widgetClass, widgetVar, id, true);
}
So either all widgets per request have endFunction=false, or all have it=true. Still, this could be a problem in the future. Perhaps
- Tooltip should render it’s children to a buffer before building the widget.
- PrimeFaces’ WidgetBuilder should prevent such misuse by adding a new boolean like this:
private boolean building;
init() {
checkState(!building);
building = true;
}
finish() {
building = false;
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
@melloware, yes, that’s good.
@VsevolodGolovanov can you review this fix? I just basically moved that above the wb.init method.
https://github.com/primefaces-extensions/primefaces-extensions/commit/35597fc868c7af152bfd1ce3bdcc9317729103c8