I use a RadioGroupItem with two values. The value map uses Boolean values rather than String to map a value to the corresponding option. The first time the value is set the option is correctly displayed. But if I try to change it to a new value it clears the options leaving me with an empty RadioGroupItem. I think it is only a display problem, the value seems to be correct.
I tried this with the Version 5.0p (2014-09-14) and GWT 2.6.1. Upgrading to the latest nightly build of smartgwt does not help. I had an old version of smartgwt from the year 2013 which works as indented. But unfortunately, I don't know which version that is since it is a dummy project and not under source control.
Below is a standalone test case. As mentioned before the initial value is displayed correctly. Once you press the switch-button though the RadioGroupItem displays nothing. Sometimes the correct value is displayed for a fraction of second before cleared.
If I replace the Boolean values in the value map with Strings ("true" and "false") and set a String value (String.valueOf(this.flag)) instead of a Boolean value, then it works. This is the workaround I've currently implemented (and which I consider ugly).
I tried this with the Version 5.0p (2014-09-14) and GWT 2.6.1. Upgrading to the latest nightly build of smartgwt does not help. I had an old version of smartgwt from the year 2013 which works as indented. But unfortunately, I don't know which version that is since it is a dummy project and not under source control.
Below is a standalone test case. As mentioned before the initial value is displayed correctly. Once you press the switch-button though the RadioGroupItem displays nothing. Sometimes the correct value is displayed for a fraction of second before cleared.
If I replace the Boolean values in the value map with Strings ("true" and "false") and set a String value (String.valueOf(this.flag)) instead of a Boolean value, then it works. This is the workaround I've currently implemented (and which I consider ugly).
Code:
import java.util.LinkedHashMap;
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.ValuesManager;
import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
import com.smartgwt.client.widgets.layout.VLayout;
public class Test implements EntryPoint {
private static final String FIELD_RADIO = "radio";
private boolean flag = false;
@Override
public void onModuleLoad() {
VLayout layout = new VLayout();
final ValuesManager mgr = new ValuesManager();
DynamicForm form = new DynamicForm();
form.setValuesManager(mgr);
RadioGroupItem item = new RadioGroupItem(FIELD_RADIO, "Do you like cookies?");
item.setWrapTitle(Boolean.FALSE);
// Value map for possible options
LinkedHashMap<Object, String> map = new LinkedHashMap<Object, String>();
map.put(Boolean.TRUE, "Yes");
map.put(Boolean.FALSE, "No");
item.setValueMap(map);
item.setVertical(false);
form.setFields(item);
editWithNewValueForFlag(mgr);
layout.addMember(form);
Button button = new Button("switch");
button.addClickHandler(
new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Test.this.flag = !Test.this.flag;
editWithNewValueForFlag(mgr);
}
}
);
layout.addMember(button);
layout.draw();
}
private void editWithNewValueForFlag(final ValuesManager mgr) {
Record record = new Record();
record.setAttribute(FIELD_RADIO, Boolean.valueOf(this.flag));
mgr.editRecord(record);
}
}
Comment