voodude
7 Sep 2009, 8:51 PM
In 2.0.1, FormBinding does not work with RadioGroup. The fundamental problem is that RadioGroup's setValue()/getValue() works with values of type Radio, which of course is not going to work with a bound Model.
This RadioGroupBinding class (used instead of FieldBinding on the RadioGroup fields) fixes the problem:
package com.similarity.simi.gwt.client;
import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
/**
* <p>FieldBinding is broken for RadioGroup fields. This fixes it.</p>
*
* <p>The bug is that RadioGroup's value is a Radio type, but all
* models will have a String type. This converts between the two.
* Really, RadioGroup's value should be a String type, associated
* with the valueAttribute property.</p>
*/
public class RadioGroupBinding extends FieldBinding
{
/** */
public RadioGroupBinding(RadioGroup group, String property)
{
super(group, property);
}
/** Auto-ish binding; model property name is assumed same as group name */
public RadioGroupBinding(RadioGroup group)
{
// This hoop is necessary because the RadioGroup doesn't set its Name property
this(group, group.get(0).getName());
}
/** Takes the radio and turns it into a string, easy */
@Override
protected Object onConvertFieldValue(Object value)
{
return ((Radio)value).getValueAttribute();
}
/** Takes the string and looks up the radio with the appropriate value attribute */
@Override
@SuppressWarnings("unchecked")
protected Object onConvertModelValue(Object value)
{
for (Field rad: ((RadioGroup)this.field).getAll())
if (((Radio)rad).getValueAttribute() == value)
return rad;
return null;
}
}
This RadioGroupBinding class (used instead of FieldBinding on the RadioGroup fields) fixes the problem:
package com.similarity.simi.gwt.client;
import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
/**
* <p>FieldBinding is broken for RadioGroup fields. This fixes it.</p>
*
* <p>The bug is that RadioGroup's value is a Radio type, but all
* models will have a String type. This converts between the two.
* Really, RadioGroup's value should be a String type, associated
* with the valueAttribute property.</p>
*/
public class RadioGroupBinding extends FieldBinding
{
/** */
public RadioGroupBinding(RadioGroup group, String property)
{
super(group, property);
}
/** Auto-ish binding; model property name is assumed same as group name */
public RadioGroupBinding(RadioGroup group)
{
// This hoop is necessary because the RadioGroup doesn't set its Name property
this(group, group.get(0).getName());
}
/** Takes the radio and turns it into a string, easy */
@Override
protected Object onConvertFieldValue(Object value)
{
return ((Radio)value).getValueAttribute();
}
/** Takes the string and looks up the radio with the appropriate value attribute */
@Override
@SuppressWarnings("unchecked")
protected Object onConvertModelValue(Object value)
{
for (Field rad: ((RadioGroup)this.field).getAll())
if (((Radio)rad).getValueAttribute() == value)
return rad;
return null;
}
}