1

How to default checked radio button inside java class [closed]

asked 2012-12-03 11:45:09 +0800

hswain gravatar image hswain flag of India
1763 3 10
http://corejavaexample.bl...

updated 2013-01-22 10:35:41 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team
Listcell cell = new Listcell();
Radiogroup rbtng = new Radiogroup();

Radio rbtn = new Radio();

rbtn.setLabel("Yes");
rbtn.setValue("Y");
rbtn.setRadiogroup(rbtng);
Radio rbtn1 = new Radio();

This code not working how to fix this?

rbtn1.setId("no" + generateDynamicId());
rbtn1.setLabel("No");
rbtn1.setValue("N");
rbtn1.setChecked(true);

rbtn1.setRadiogroup(rbtng);
//                                                              
cell.appendChild(rbtng);
cell.appendChild(rbtn);
cell.appendChild(rbtn1);
row.appendChild(cell);
//rbtn1.setChecked(true);
delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by sjoshi
close date 2013-02-08 06:40:43

2 Replies

Sort by ยป oldest newest

answered 2012-12-04 05:54:06 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Do this

rbtn1.setParent (rbtng);

Rather than

rbtn1.setRadiogroup(rbtng);

link publish delete flag offensive edit

answered 2013-01-22 09:32:47 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

You can either set the parent to radiogroup directly or or set selected radio item after components are attached to the view, then radiogroup can control the exclusive selection.

<zk>
<window border="normal" title="hello" onCreate="build1(self)">

</window>
<zscript><![CDATA[
public void build1(Window window) {
    Radiogroup rbtng = new Radiogroup();
    Radio btnY = new Radio();
    btnY.setLabel("Yes");
    btnY.setValue("Y");
    btnY.setRadiogroup(rbtng);

    Radio btnN = new Radio();
    btnN.setLabel("No");
    btnN.setValue("N");
    btnN.setRadiogroup(rbtng);

    window.appendChild(rbtng);
    window.appendChild(btnY);
    window.appendChild(btnN);

    rbtng.setSelectedItem(btnN);
}
]]></zscript>
<window border="normal" title="hello" onCreate="build2(self)">

</window>
<zscript><![CDATA[
public void build2(Window window) {
    Radiogroup rbtng = new Radiogroup();
    Radio btnY = new Radio();
    btnY.setLabel("Yes");
    btnY.setValue("Y");
    btnY.setRadiogroup(rbtng);

    Radio btnN = new Radio();
    btnN.setLabel("No");
    btnN.setValue("N");
    btnN.setRadiogroup(rbtng);
    btnN.setChecked(true);

    rbtng.appendChild(btnY);
    rbtng.appendChild(btnN);

    window.appendChild(rbtng);


}
]]></zscript>
</zk>
link publish delete flag offensive edit

Question tools

Follow

RSS

Stats

Asked: 2012-12-03 11:45:09 +0800

Seen: 135 times

Last updated: Jan 22 '13

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