Hello, I'm using SmartClient Version: SC_SNAPSHOT-2011-11-08/PowerEdition Deployment (built 2011-11-08)
In the following code, I have a Listgrid containing Lectures, with a foreign field to a Teacher table (who's teaching the lecture). This dropdown menu is written as follows:
When editing this listgrid field in-line (ie. by doubleclicking on a record in the grid), the selectitem-editor shows correctly, but upon changing a selection, it doesn't show the value being picked (while still in edit mode, that is). This is because setValueFormatter does not seem to be called (I put a breakpoint there to check).
What am I missing, because if i remember correctly this worked a few nightlies ago. Is my code wrong, or is the setValueFormatter broken?
In the following code, I have a Listgrid containing Lectures, with a foreign field to a Teacher table (who's teaching the lecture). This dropdown menu is written as follows:
Code:
final SelectItem TeacherSelectItem = new SelectItem("Teacher_id",
teacherMessages.name_single());
TeacherSelectItem.setOptionDataSource(DataSource.get("Teacher"));
TeacherSelectItem.setValueField("Teacher_id");
TeacherSelectItem.setAlign(Alignment.LEFT);
TeacherSelectItem.setTextAlign(Alignment.LEFT);
TeacherSelectItem.setTitleAlign(Alignment.LEFT);
ListGrid TeacherListGrid = new ListGrid();
TeacherListGrid.setShowFilterEditor(true);
TeacherListGrid.setFilterOnKeypress(true);
final SortSpecifier sort = new SortSpecifier("surname",SortDirection.ASCENDING);
final SortSpecifier[] s = new SortSpecifier[] {sort};
TeacherListGrid.setInitialSort(s);
TeacherSelectItem.setValueFormatter(new FormItemValueFormatter() {
public String formatValue(Object value, Record selectedRecord,
DynamicForm form, FormItem item) {
ListGridRecord selectedRecord = TeacherSelectItem.getSelectedRecord();
if(selectedRecord == null)
return "";
String t = selectedRecord.getAttribute("tussenvoegsel");
String tus = t == null || "".equals(t) ? "" : " " + t;
if(selectedRecord.getAttribute("firstname") == null && selectedRecord.getAttribute("surname")==null)
return "";
return selectedRecord.getAttribute("firstname")+tus+" "+selectedRecord.getAttribute("surname");
}
});
TeacherSelectItem.setAllowEmptyValue(true);
TeacherSelectItem.setPickListWidth(500);
TeacherSelectItem.setPickListFields(
TeacherModelMessages m = (TeacherModelMessages) GWT
.create(TeacherModelMessages.class);
ListGridField[] ret = new ListGridField[3];
ret[0] = new ListGridField("firstname",m.firstname());
ret[1] = new ListGridField("surname",m.surname());
ret[2] = new ListGridField("companyName",m.companyName());
return ret;
);
TeacherSelectItem.setPickListProperties(TeacherListGrid);
TeacherField.setAlign(Alignment.LEFT);
TeacherField.setEditorType(TeacherSelectItem);
TeacherField.setOptionDataSource(DataSource.get("Teacher"));
TeacherField.setDisplayField("firstname");
TeacherField.setFilterEditorType(TeacherSelectItem); //reusing this is okay appearantly
TeacherField.setCellFormatter(new CellFormatter(){
public String format(Object value, ListGridRecord record,
int rowNum, int colNum) {
String f = record.getAttribute("firstname");
String t = record.getAttribute("tussenvoegsel");
String s = record.getAttribute("surname");
String c = record.getAttribute("companyName");
String ret = ((f == null || "".equals(f)) ? "" : f) +
((t == null || "".equals(t)) ? "" : " " + t) +
((s == null || "".equals(s)) ? "" : " " + s) +
((c == null || "".equals(c)) ? "" : " (" + c + ")");
return ret;
}
});
TeacherField.addCellSavedHandler(new CellSavedHandler(){
public void onCellSaved(CellSavedEvent event) {
final int rowNum = event.getRowNum();
DataSource ds= DataSource.get("Lecture");
DSRequest req= new DSRequest();
req.setOperationId("presenceList");
final Record r = event.getRecord();
Criteria c = new Criteria();
c.setAttribute("Lecture_id", r.getAttribute("Lecture_id"));
ds.fetchData(c, new DSCallback(){
public void execute(DSResponse response, Object rawData,DSRequest request) {
RecordList rl = response.getDataAsRecordList();
if(rl!=null){
Log.debug("fetched name " + rl.get(0).getAttribute("surname") + ", " +rl.get(0).getAttribute("tussenvoegsel")
+ ", "+rl.get(0).getAttribute("firstname"));
r.setAttribute("surname", rl.get(0).getAttribute("surname"));
r.setAttribute("firstname", rl.get(0).getAttribute("firstname"));
grid.refreshRow(rowNum);
}
}
},req);
}
});
What am I missing, because if i remember correctly this worked a few nightlies ago. Is my code wrong, or is the setValueFormatter broken?
Comment