/** Returns the name of this radio button. * <p>Don't use this method if your application is purely based * on ZK's event-driven model. * <p>It is readonly, and it is generated automatically * to be the same as its parent's name ({@link Radiogroup#getName}). */ public String getName() { final Radiogroup group = getRadiogroup(); return group != null ? group.getName() : getUuid(); }
public void onPageAttached(Page newpage, Page oldpage) { super.onPageAttached(newpage, oldpage); Component rootParent = ComponentsCtrl.getRootParent(); final Radiogroup rg = getRadiogroup(); // ZK-3818: update selected index in the callback if (!_explictGroup) { _group = this.getRadiogroup(); } if (rg != null && rootParent instanceof ComponentCtrl && (!Components.isAncestor(rootParent, rg) || rootParent == rg)) { ((ComponentCtrl) rootParent).addCallback(AFTER_CHILD_ADDED, new Callback<Component>() { public void call(Component rootParent) { rg.fixOnAdd(Radio.this, false); } }); } } }
public void setParent(Component parent) { Radiogroup oldgp = null; if (getParent() != null) oldgp = getRadiogroup(); super.setParent(parent); Radiogroup newgp = null; if (parent != null) newgp = getRadiogroup(); if (oldgp != newgp) { if (oldgp != null) { //removed from the component tree if (_explictGroup && oldgp == _group) { _group.removeExternal(this); _attachExternal = false; } } if (newgp != null) { if (_explictGroup && !_attachExternal && newgp == _group) { _group.addExternal(this); _attachExternal = true; } } } }
public Object coerceToBean(Object val, Component comp, BindContext ctx) { if (val != null) { final ListModel<?> model = ((Radio) val).getRadiogroup().getModel(); if (model != null && !(model instanceof Selectable)) { throw new UiException("model doesn't implement Selectable"); } if (model != null) { Set<?> selection = ((Selectable<?>) model).getSelection(); if (selection == null || selection.size() == 0) return null; return selection.iterator().next(); } else { //no model return ((Radio) val).getValue(); } } return null; } }
/** Deselects all of the currently selected radio buttons and selects * the given radio button. */ public void setSelectedItem(Radio item) { if (item == null) { setSelectedIndex(-1); } else { if (item.getRadiogroup() != this) throw new UiException("Not a child: " + item); item.setSelected(true); } }
/** Make sure only one of them is checked. */ private void fixSiblings(boolean checked, boolean byclient) { final Radiogroup group = getRadiogroup(); if (group != null) { if (checked) { final Radio sib = group.getSelectedItem(); if (sib != null && sib != this) { if (byclient) { sib._checked = false; } else { sib.setChecked(false); //and fixSelectedIndex return; } } } group.fixSelectedIndex(); group.syncSelectionToModel(); } }
/** Processes an AU request. * * @since 5.0.0 */ public void service(org.zkoss.zk.au.AuRequest request, boolean everError) { final String cmd = request.getCommand(); if (cmd.equals(Events.ON_CHECK)) { CheckEvent evt = CheckEvent.getCheckEvent(request); _checked = evt.isChecked(); fixSiblings(_checked, true); //invoke syncSelectionToModel Events.postEvent(evt); // Bug: B50-3284663: Radio always sends onCheck event final Radiogroup rg = getRadiogroup(); if (rg != null) Events.postEvent(rg, evt); } else super.service(request, everError); }
@Override public void onPageDetached(Page page) { super.onPageDetached(page); //B65-ZK-1768 remove the radio from the radiogroup in case it is an external radio final Radiogroup rg = getRadiogroup(); if (rg != null) { rg.removeExternal(this); } // ZK-3818: update selected index in the callback if (!_explictGroup) { _group = null; } Component rootParent = ComponentsCtrl.getRootParent(); if (rg != null && rootParent instanceof ComponentCtrl && (!Components.isAncestor(rootParent, rg) || rootParent == rg)) { ((ComponentCtrl) rootParent).addCallback(AFTER_CHILD_REMOVED, new Callback<Component>() { public void call(Component rootParent) { rg.fixOnRemove(Radio.this); } }); } }
public void render(Component comp, Writer out) throws IOException { final SmartWriter wh = new SmartWriter(out); final Radio self = (Radio)comp; final String uuid = self.getUuid(); wh.write("<span id=\"").write(uuid).write("\" z.type=\"zul.btn.Radio\"") .write(self.getOuterAttrs()).write(">").write("<input type=\"radio\" id=\"") .write(uuid).write("!real\"").write(self.getInnerAttrs()) .write("/><label for=\"").write(uuid).write("!real\"") .write(self.getLabelAttrs()) .write(" class=\""+self.getZclass()+"-cnt\"") .write(">") .write(self.getImgTag()).write(self.getLabel()) .write("</label>"); if(self.getRadiogroup() != null && self.getRadiogroup().getOrient().equals("vertical")) wh.writeln("<br/>"); wh.write("</span>"); } }
public void render(final Radio item, final Object data, final int index) throws Exception { final Radiogroup radiogroup = item.getRadiogroup(); final int size = radiogroup.getModel().getSize(); final Template tm = resolveTemplate(radiogroup, item, data, index, size, "model");