negge
27 Jun 2008, 3:18 AM
RadioGroup.getValue() returns boolean true, irrespective of which Radio is currently checked. This is because of the following code:
/**
* Returns the value of the selected radio.
*/
@Override
public Object getValue() {
for (Radio r : fields) {
if (r.getValue()) {
return r.getValue();
}
}
return null;
}and
@Override
public void setValue(Object value) {
for (Radio r : fields) {
r.setValue(value.equals(r.getValue()));
}
}The only way I can see to have a working setValue is if Radio contains some user provided value object. This could be achieved if Radio and other classes were made generic e.g.,
Radio<D> extends CheckBox<D>
CheckBox<D> extends Field<Boolean>
RadioGroup<D> extends MultiField<Radio<D>>
MultiField<C extends CheckBox<D>> extends Field<Set<D>>
This would limit MultiField to be only used with CheckBox and Radio, but it would give working getValue and setValue to CheckBoxGroup and RadioGroup, currently the only subclasses of MultiField.
Nathan
/**
* Returns the value of the selected radio.
*/
@Override
public Object getValue() {
for (Radio r : fields) {
if (r.getValue()) {
return r.getValue();
}
}
return null;
}and
@Override
public void setValue(Object value) {
for (Radio r : fields) {
r.setValue(value.equals(r.getValue()));
}
}The only way I can see to have a working setValue is if Radio contains some user provided value object. This could be achieved if Radio and other classes were made generic e.g.,
Radio<D> extends CheckBox<D>
CheckBox<D> extends Field<Boolean>
RadioGroup<D> extends MultiField<Radio<D>>
MultiField<C extends CheckBox<D>> extends Field<Set<D>>
This would limit MultiField to be only used with CheckBox and Radio, but it would give working getValue and setValue to CheckBoxGroup and RadioGroup, currently the only subclasses of MultiField.
Nathan