Implementing a Component Property"
From Documentation
Tmillsclare (talk | contribs) m (Created page with '{{ZKComponentDevelopmentEssentialsPageHeader}} A property usually has a getter and a setter. The getter is straightforward: <source lang="java"> private String _value = ""; //a…') |
Jimmyshiau (talk | contribs) |
||
(One intermediate revision by the same user not shown) | |||
Line 11: | Line 11: | ||
</source> | </source> | ||
− | The setter is similar except we have to notify the client. This is achieved by using the <javadoc method="smartUpdate(java.lang.String, | + | The setter is similar except we have to notify the client. This is achieved by using the <javadoc method="smartUpdate(java.lang.String, java.lang.Object)">org.zkoss.zk.ui.AbstractComponent</javadoc> function. |
<source lang="java"> | <source lang="java"> | ||
Line 22: | Line 22: | ||
</source> | </source> | ||
− | The <javadoc method="smartUpdate(java.lang.String, | + | The <javadoc method="smartUpdate(java.lang.String, java.lang.Object)">org.zkoss.zk.ui.AbstractComponent</javadoc> function causes ZK Client Engine to call the <mp>setValue</mp> method of the peer widget (the first argument is the property name). Then, the widget can manipulate the DOM tree from there. |
{{ZKComponentDevelopmentEssentialsPageFooter}} | {{ZKComponentDevelopmentEssentialsPageFooter}} |
Latest revision as of 01:03, 9 March 2011
A property usually has a getter and a setter. The getter is straightforward:
private String _value = ""; //a data member
public String getValue() {
return _value;
}
The setter is similar except we have to notify the client. This is achieved by using the AbstractComponent.smartUpdate(String, Object) function.
public void setValue(String value) {
if (!_value.equals(value)) {
_value = value;
smartUpdate("value", _value);
}
}
The AbstractComponent.smartUpdate(String, Object) function causes ZK Client Engine to call the setValue method of the peer widget (the first argument is the property name). Then, the widget can manipulate the DOM tree from there.