-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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:
@Wire
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);
delSelectedMonitor.setLabel("DELETE:"+clickedDivIdEditMode+","+curName);
}
}
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.
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:
http://zkfiddle.org/sample/2bk35in/5-button-label-update
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 :)
Asked: 2019-02-18 09:42:26 +0800
Seen: 14 times
Last updated: Feb 20 '19