Hello :) iam bootcamp java still learn more about java and framework zk
anyone know how to create dynamic radio button such as data from database but now i'm not use it.
this is my source code for test
radiobutton.zul
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="Customer" border="normal" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('vmd.RadioButton')">
<cell>
<vlayout>
<radiogroup id="radiogroup">
</radiogroup>
</vlayout>
</cell>
</window>
</zk>
RadioButton.java
public class RadioButton {
public Radiogroup getRadiogroup() {
return radiogroup;
}
public void setRadiogroup(Radiogroup radiogroup) {
this.radiogroup = radiogroup;
}
private Radiogroup radiogroup = new Radiogroup();
@Init
public void load() {
ArrayList<String> columnEntries = new ArrayList<String>();
columnEntries.add("a");
columnEntries.add("b");
for (String entry : columnEntries) {
radiogroup.appendItem(entry, entry);
}
radiogroup.setVisible(true);
}
}
And Result from that code is no radio button and no error :*( please help me..
According to ZK component lifecycle,
init
method is called before component rendering. So you have to set the value after compose (@AfterCompose
). You can also wire your component. Example :Viewmodel :
View :
You can also bind a list from your viewmodel.
Example :
Viewmodel :
View :
UPDATE : As stated by Malte Hartwig in the comments, this way is preferred when using MVVM (component wiring is discouraged, see http://books.zkoss.org/zk-mvvm-book/8.0/advanced/wire_components.html).
There are several other ways to do it, for example using a Composer.