PDA

View Full Version : [FIXED] RadioGroup.getValue() returns true regardless of the item selected



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

negge
27 Jun 2008, 4:01 AM
Patch to bring RadioGroup setValue() in line with CheckBoxGroup setValue()


--- user/src/com/extjs/gxt/ui/client/widget/form/RadioGroup.java (revision 527)
+++ user/src/com/extjs/gxt/ui/client/widget/form/RadioGroup.java (working copy)
@@ -40,7 +40,7 @@
public Object getValue() {
for (Radio r : fields) {
if (r.getValue()) {
- return r.getValue();
+ return r;
}
}
return null;
@@ -59,7 +59,10 @@
@Override
public void setValue(Object value) {
for (Radio r : fields) {
- r.setValue(value.equals(r.getValue()));
+ if (r.equals(value)) {
+ r.setValue(true);
+ break;
+ }
}
}Above solution would still be better.

Nathan