0

According to https://www.zkoss.org/wiki/ZK_Component_Reference/Essential_Components/Button#Autodisable, I have customized our ZK app to enable autodisable for all buttons by specifying the following in the custom language addon:

<language-addon>
<component>
    <component-name>button</component-name>
    <extends>button</extends>
    <property>
        <property-name>autodisable</property-name>
        <property-value>self</property-value>
    </property>
</component>

It works fine for buttons defined in ZUL files but not for buttons defined in Java, for example when I have to display a button in each row of a table (listbox), and so I define the buttons in the renderer class.

I could also set the necessary functioning individually for a button:

  myButton.setAutodisable("self");

but it would be nice to arrange it in a similar central way as for the normal buttons. How to achieve it?

Géza
  • 481
  • 1
  • 3
  • 13

1 Answers1

1

Since you have access to the button class in Java, the simplest solution would be to create a ButtonExt (or any class name that makes sense in your project's name patterns), generate constructors based on the super class and add this.setAutodisable("self"); in the constructors (after super(...);)

This is basically what the zul parser does. The component config described in your post is just an instruction to tell the parser to always call newComponent.setAutodisable("self"); every time that it instantiate a button.

Since your ButtonExt will be extending the default button class, you can then just instantiate it in Java: Button myButton = new ButtonExt(); and it will act as a standard button, with your extra initialization code.

MDuchemin
  • 431
  • 2
  • 6
  • Thank you, it works fine. The only drawback is that I do not know a way to prevent myself and my collegues to instanciate the original ZK Button in the future. I asked a separate question for it: https://stackoverflow.com/questions/59290346/how-to-mark-a-java-library-class-as-deprecated – Géza Dec 11 '19 at 16:43