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 ?

Steve
  • 31
  • 4

1 Answers1

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.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • final String widgetVar = button.resolveWidgetVar(); returns widget_loggingForm_loggerTable_j_dt60(id316) Throws java.util.IllegalFormatConversionException line 64 of https://github.com/primefaces-extensions/primefaces-extensions/blob/master/core/src/main/java/org/primefaces/extensions/renderer/CommandButtonSingleClickRenderer.java – Steve Oct 13 '21 at 12:06
  • 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 ? – Steve Oct 13 '21 at 12:22
  • Line 64 is Javadoc. `button.resolveWidgetVar()` will work with 6.1 as it is also used by the `CommandButtonRenderer` of 6.1. – Jasper de Vries Oct 13 '21 at 13:00
  • 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) – Steve Oct 13 '21 at 13:18
  • return String.format("var w=PrimeFaces.widgets['%s'];if(w){w.%sable();};", widgetVar, enabled ? "en" : "dis"); Is failing – Steve Oct 13 '21 at 13:37