primefaces: PFS: update using @widgetVar crashes when migrating from 13.0.10 to 14.0.x
Describe the bug
The following is code I used in the reproducer project, but it works (unfortunately for me).
<p:tabView id="PeriodTabView" widgetVar="PeriodTabViewWdg">
<p:tab title="Tab #1">
<p:dataTable>
<f:facet name="header">
<p:commandButton value="Ka-blam!" process="@this" update="@widgetVar(PeriodTabViewWdg)" />
</f:facet>
</p:dataTable>
</p:tab>
</p:tabView>
My code is, of course, a lot more complex, but it was working fine, and it still does after downgrading, but after upgrading to 14.x I now encounter:
jakarta.faces.FacesException: Expression does not match following pattern @widgetVar(var). Expression: "widgetVar(PeriodTabViewWdg)" at org.primefaces.expression.WidgetVarSearchKeywordResolver.resolve(WidgetVarSearchKeywordResolver.java:66) at com.sun.faces.component.search.CompositeSearchKeywordResolver.resolve(CompositeSearchKeywordResolver.java:52) at com.sun.faces.component.search.SearchExpressionHandlerImpl.invokeKeywordResolvers(SearchExpressionHandlerImpl.java:315) at com.sun.faces.component.search.SearchExpressionHandlerImpl.invokeOnComponent(SearchExpressionHandlerImpl.java:269) at jakarta.faces.component.search.SearchExpressionHandler.invokeOnComponent(SearchExpressionHandler.java:180) at com.sun.faces.component.search.SearchExpressionHandlerImpl.resolveClientIds(SearchExpressionHandlerImpl.java:109) at org.primefaces.expression.SearchExpressionUtils.resolveClientIdsAsString(SearchExpressionUtils.java:132) at org.primefaces.util.AjaxRequestBuilder.addExpressions(AjaxRequestBuilder.java:156) at org.primefaces.util.AjaxRequestBuilder.update(AjaxRequestBuilder.java:148) at org.primefaces.renderkit.CoreRenderer.preConfiguredAjaxRequestBuilder(CoreRenderer.java:468) at org.primefaces.renderkit.CoreRenderer.buildAjaxRequest(CoreRenderer.java:489) at org.primefaces.renderkit.CoreRenderer.buildAjaxRequest(CoreRenderer.java:485) at org.primefaces.component.commandbutton.CommandButtonRenderer.buildRequest(CommandButtonRenderer.java:154) Caused by: java.lang.NullPointerException: Cannot invoke "jakarta.faces.component.UIComponent.getClientId(jakarta.faces.context.FacesContext)" because "target" is null at com.sun.faces.component.search.SearchExpressionHandlerImpl$ResolveClientIdsCallback.invokeContextCallback(SearchExpressionHandlerImpl.java:132) at jakarta.faces.component.search.SearchKeywordContext.invokeContextCallback(SearchKeywordContext.java:65) at org.primefaces.expression.WidgetVarSearchKeywordResolver.resolve(WidgetVarSearchKeywordResolver.java:58)
I’ve debugged it, and the pattern does actually match, but
WidgetVarVisitCallback visitCallback = new WidgetVarVisitCallback(matcher.group(1));
context.getSearchExpressionContext().getFacesContext().getViewRoot().visitTree(
VisitContext.createVisitContext(context.getSearchExpressionContext().getFacesContext(), null,
ComponentUtils.VISIT_HINTS_SKIP_UNRENDERED),
visitCallback);
never finds the target and proceeds to provoke an NPE.
Reproducer
I would provide it, but I’m unable to reproduce in the reproducer.
Expected behavior
The rendering should not crash on xhtml load.
PrimeFaces edition
Elite
PrimeFaces version
14.0.x
Theme
No response
JSF implementation
Mojarra
JSF version
4.0.7
Java version
21
Browser(s)
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 16 (11 by maintainers)
Commits related to this issue
- #12470 - fixed possible NPE (#12486) — committed to primefaces/primefaces by tandraschko 2 years ago
- Fix #12470: 14.0.5 WidgetVarSearchKeywordResolver fixed possible NPE — committed to melloware/primefaces by melloware 2 years ago
- Fix #12470: 14.0.5 WidgetVarSearchKeywordResolver fixed possible NPE (#12487) — committed to primefaces/primefaces by melloware 2 years ago
thats not a fix at all, it should just give you the correct exception / error
@matsandreassen-triona sure check out the 14.X branch here and run
mvn clean installhttps://github.com/primefaces/primefaces/tree/14.X that will be 14.0.5-SNAPSHOT for you to use.