ZK 8.5.0 how to override button widget setLabel function

asked 2019-02-18 09:42:26 +0800

cindy951357 gravatar image cindy951357
3 2

The ZK setLabel() function of Button widget does not work; when the code runs to the line like foobutton.setLabel(mystring), the button disappears from the browser.

In the eclipse IDE, if I hover on the setLabel() function, the IDE shows this message:

If label is changed, the whole component is invalidate.Thus, you want to smart-update, you have to override this method.

Using ZK 8.5.0

Inside the controller class, I declare:

 Button delSelectedMonitor;

Inside the controller, I implement a class which implements EventListener:

public class onClickHolderEditMode implements EventListener{

    public void onEvent(Event event) throws Exception {
        clickedDivEditMode = (Div) event.getTarget();
        clickedDivIdEditMode = clickedDivEditMode.getId().split(myUtil.monitorholderString)[1];

        String curName = getCamNameById(clickedDivIdEditMode);


event binding:

tmpdiv.addEventListener("onClick",  new onClickHolderEditMode());

My expectation is that when someone clicks the tmpdiv, the button delSelectedMonitor will change its label according to the property of tmpdiv. However as I say previously, the button is just disappearing.

I have tried the section "Specify Your Own Widget Class" at the official tutorial "Widget Customization", but the browser will be pending.

Please help, thank you.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-02-20 12:51:17 +0800

MDuchemin gravatar image MDuchemin
1346 1 4
ZK Team

Hi Cindy951357,

Regarding the Javadoc info on setLabel:

If label is changed, the whole component is invalidate.Thus, you want to smart-update, you have to override this method.

This means that the button will be rerendered if you change its label (not a problem in the default case, the browser will delete the input and recreate it). However, if you want to keep the same DOM element when changing the label, you would have to update the setLabel to use smart-update instead. Again, not a requirement if you just want to update the text on the button.

Regarding the "Widget Customization" section: ZK objects exists as "components" on server-side (java objects) and have a client-side "copy" called a widget (Javascript objects). If you customize a widget, you are changing how the client renders data received from the server. If you customize a component, you are changing how the server is building the page. From you description, it doesn't look like you would require this at the moment.

Based on the sample code provided, the label on the button should be updated. There might be some extra code in your composer affecting this button that is not visible in the available code though.

I've made a fiddle to show a simple example of how this would work:


Have a look and let me know if this also cause the button to disappear on your side.

If the button disappear during rerender, there might be an error in your client console. Before testing this case, open your browser's developer tools and check into the JavaScript console for errors or warnings. If any, just add them to this question for debugging :)

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2019-02-18 09:42:26 +0800

Seen: 10 times

Last updated: Feb 20

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More