How to use resolveWidgetVar before PrimeFaces 8?
Asked Answered
P

1

1

https://github.com/primefaces-extensions/primefaces-extensions/blob/master/core/src/main/java/org/primefaces/extensions/renderer/CommandButtonSingleClickRenderer.java

This appears to be an elegant solution to disable and enable PrimeFaces CommandButton and available in version 8 and up of PrimeFaces.

Unfortunately, I'm unable to compile it in PrimeFaces 6.1, Java 8.

It now compiles with the suggested update, Thanks, but the method doesn't return the correct type - String.

It could be related to the structure of our DOM, we have multiple layers of xhtml, the first loaded index.xhtml doesn't have any buttons. But the CommandButtonSingleClickRenderer.java is being called. The properties of the CommandButton are all default values.

protected String getAttributeValue(final FacesContext context, final CommandButton button, final String attribute)

returns null

Added a check for null prior to the call to getToggleJS to get the pages with buttons loaded.

What is required in the commandButton ? How do you call the CommandButtonSingleClickRenderer from xhtml ?

Porpoise answered 12/10, 2021 at 21:49 Comment(0)
S
1

In PrimeFaces 8, the default String resolveWidgetVar(FacesContext context) method was introduced in the Widget interface.

Before that, so in PrimeFaces 6.1, you should use button.resolveWidgetVar().

See also the source of CommandButtonRenderer in PrimeFaces 6.1.

Slash answered 13/10, 2021 at 6:24 Comment(5)
final String widgetVar = button.resolveWidgetVar(); returns widget_loggingForm_loggerTable_j_dt60(id316) Throws java.util.IllegalFormatConversionException line 64 of github.com/primefaces-extensions/primefaces-extensions/blob/…Porpoise
String clientId = button.getClientId(context); WidgetBuilder wb = getWidgetBuilder(context); wb.init("CommandButton", button.resolveWidgetVar(), clientId); wb contains everything available - what should be used to provide the correct value for wigdetVar ?Porpoise
Line 64 is Javadoc. button.resolveWidgetVar() will work with 6.1 as it is also used by the CommandButtonRenderer of 6.1.Slash
In my version, apologies line 75. In both cases button.resolveWidgetVar() , the method needs and String,and the assignment is a String but calling it like described. final String widgetVar = button.resolveWidgetVar(); - stopped in the debugger it's widget_loggingForm_loggerTable_j_dt60(id316)Porpoise
return String.format("var w=PrimeFaces.widgets['%s'];if(w){w.%sable();};", widgetVar, enabled ? "en" : "dis"); Is failingPorpoise

© 2022 - 2024 — McMap. All rights reserved.