I am trying to implement simple select item with pick list grid to be able to select default value.
I am facing very strange problems, selection get lost. You can see problem live on: http://tagws.cust.panline.net:8080/test9/Test9.html
Just play around by clicking on 3th column (default) and you will see that selection is changed in field item. When close and open pick List again complete selection is buggy (see the attached picture).
Any idea how to resolve this problem, I am spending days on this topic :(
This is my code:
Data source:
public class TestDS extends DataSource{
public TestDS() {
DataSourceIntegerField idField = new DataSourceIntegerField("id");
idField.setHidden(true);
idField.setPrimaryKey(true);
DataSourceTextField nameField = new DataSourceTextField("name");
DataSourceImageField imageField = new DataSourceImageField("default");
setFields(idField, nameField, imageField);
setClientOnly(true);
}
}
This is main class:
public class Test9 implements EntryPoint {
private SelectItem selectItem = new SelectItem();
private TestDS ds = new TestDS();
private ListGridRecord selectedRecord;
public void onModuleLoad() {
DynamicForm form = new DynamicForm();
form.setWidth(300);
form.setHeight(400);
form.setLeft(50);
form.setTop(100);
selectItem.setTitle("Test data");
selectItem.setMultiple(true);
selectItem.setMultipleAppearance(MultipleAppearance.PICKLIST);
selectItem.setOptionDataSource(ds);
selectItem.setAutoFetchData(true);
selectItem.setValueField("id");
selectItem.setDisplayField("name");
ListGridField locationName = new ListGridField("name", "Name");
ListGridField locationImage = new ListGridField("default", "Default", 50);
locationImage.setAlign(Alignment.CENTER);
locationImage.setType(ListGridFieldType.IMAGE);
locationImage.setImageURLSuffix(".png");
selectItem.setPickListFields(locationName, locationImage);
selectItem.setPickListWidth(300);
form.setFields(selectItem);
// initial data
fillData();
selectData();
form.draw();
locationImage.addRecordClickHandler(new RecordClickHandler() {
@Override
public void onRecordClick(RecordClickEvent event) {
ListGridRecord sel = (ListGridRecord) event.getRecord();
if(sel != selectedRecord) {
// set old selected record to nothing
selectedRecord.setAttribute("default", "");
ds.updateData(selectedRecord);
// set new selected record
sel.setAttribute("default", "ok_16");
selectedRecord = sel;
ds.updateData(selectedRecord);
}
}
});
}
private void selectData() {
String values[];
String sel = "0,1,2,3,5";
values = sel.split(",");
// select some options
selectItem.setValues(values);
}
private void fillData() {
// fill list with dummy data
for(int i = 0;i < 7;i++) {
ListGridRecord lg = new ListGridRecord();
lg.setAttribute("id",i);
lg.setAttribute("name", "name_" + i);
if(i == 3) {
lg.setAttribute("default", "ok_16");
selectedRecord = lg;
} else {
lg.setAttribute("default", "");
}
ds.addData(lg);
}
}
}
I use SmartGWT 2.2 and GWT 2.0.4
Best regards
I am facing very strange problems, selection get lost. You can see problem live on: http://tagws.cust.panline.net:8080/test9/Test9.html
Just play around by clicking on 3th column (default) and you will see that selection is changed in field item. When close and open pick List again complete selection is buggy (see the attached picture).
Any idea how to resolve this problem, I am spending days on this topic :(
This is my code:
Data source:
public class TestDS extends DataSource{
public TestDS() {
DataSourceIntegerField idField = new DataSourceIntegerField("id");
idField.setHidden(true);
idField.setPrimaryKey(true);
DataSourceTextField nameField = new DataSourceTextField("name");
DataSourceImageField imageField = new DataSourceImageField("default");
setFields(idField, nameField, imageField);
setClientOnly(true);
}
}
This is main class:
public class Test9 implements EntryPoint {
private SelectItem selectItem = new SelectItem();
private TestDS ds = new TestDS();
private ListGridRecord selectedRecord;
public void onModuleLoad() {
DynamicForm form = new DynamicForm();
form.setWidth(300);
form.setHeight(400);
form.setLeft(50);
form.setTop(100);
selectItem.setTitle("Test data");
selectItem.setMultiple(true);
selectItem.setMultipleAppearance(MultipleAppearance.PICKLIST);
selectItem.setOptionDataSource(ds);
selectItem.setAutoFetchData(true);
selectItem.setValueField("id");
selectItem.setDisplayField("name");
ListGridField locationName = new ListGridField("name", "Name");
ListGridField locationImage = new ListGridField("default", "Default", 50);
locationImage.setAlign(Alignment.CENTER);
locationImage.setType(ListGridFieldType.IMAGE);
locationImage.setImageURLSuffix(".png");
selectItem.setPickListFields(locationName, locationImage);
selectItem.setPickListWidth(300);
form.setFields(selectItem);
// initial data
fillData();
selectData();
form.draw();
locationImage.addRecordClickHandler(new RecordClickHandler() {
@Override
public void onRecordClick(RecordClickEvent event) {
ListGridRecord sel = (ListGridRecord) event.getRecord();
if(sel != selectedRecord) {
// set old selected record to nothing
selectedRecord.setAttribute("default", "");
ds.updateData(selectedRecord);
// set new selected record
sel.setAttribute("default", "ok_16");
selectedRecord = sel;
ds.updateData(selectedRecord);
}
}
});
}
private void selectData() {
String values[];
String sel = "0,1,2,3,5";
values = sel.split(",");
// select some options
selectItem.setValues(values);
}
private void fillData() {
// fill list with dummy data
for(int i = 0;i < 7;i++) {
ListGridRecord lg = new ListGridRecord();
lg.setAttribute("id",i);
lg.setAttribute("name", "name_" + i);
if(i == 3) {
lg.setAttribute("default", "ok_16");
selectedRecord = lg;
} else {
lg.setAttribute("default", "");
}
ds.addData(lg);
}
}
}
I use SmartGWT 2.2 and GWT 2.0.4
Best regards
Comment