1) Does SmartGWT have the ability to have a radiobutton in a listgrid? I think the answer is no, as I could only see radiobutton as a formitem.
2) Since I think "no" is answer to #1 above, I tried to fake it by creating 2 boolean/checkbox columns in a listgrid. Then, I tried to get it so that if a user selected one column, it would unselect the other (ie just like a radiobutton). I tried to do this by using both the recordclickhandler and the "onchanged" handler. Neither worked fine. Here were the problems:
<b>Attempt #1: Using recordclickhandler:</b>
Code is below. But the problem is that the recordclickhandler would only work the FIRST time I clicked on the the checkbox. For the 2nd time, it wouldn't fire the recordclickhandler UNLESS I, as the user, selected a different record first and then re-select the original record.
<b>Attempt #2: Using On Changed Handler</b>
Code is below. This worked better than attemp #1 above, in that I could select/deselect a row as many times as I wanted *without* having to select another row first. However, if this was my 2nd click on a checkbox, it would NOT reflect the change that I made to other attributes of the row *until* I selected something else (eg a label in the window etc.). So my question here is there a "right" way to force the row to "refresh" and reflect the changes made to the record if this is the 2nd click of the checkbox?
In general, I think there is something subtle about the "clicking of a checkbox" that causes odd behaviour if you try to click on it a 2nd time in a row.
FYI: In case it helps, here's the details on the grid.(Note: This listgrid is NOT connected to any datasource or, for that matter, to any underyling RDBMS; instead, it's manually populated using the setData() method.
lgFilesWithConflict = new ListGrid();
lgFilesWithConflict.setWidth("100%");
lgFilesWithConflict.setHeight(355);
lgFilesWithConflict.setSaveByCell(true);
// lgFilesWithConflict.setAutoSaveEdits(true);
// lgFilesWithConflict.setCanEdit(true);
lgFilesWithConflict.setEditEvent(ListGridEditEvent.CLICK);
lgFilesWithConflict.setCanEdit(true);
lgFilesWithConflict.setSelectionType(SelectionStyle.NONE);
Miscellaneous Infrastucture Details:
==================================
OS: Windows XP Pro
IDE: MyEclipse 10.0 with Google Plugin for Eclipse (2.5)
SmartGWT Pro 3.0 (Purchased Licence)
Browser: Mozilla Firefox 4.0.1
GWT SDK: 2.4.0
Sun JDK 1.6.0_27
2) Since I think "no" is answer to #1 above, I tried to fake it by creating 2 boolean/checkbox columns in a listgrid. Then, I tried to get it so that if a user selected one column, it would unselect the other (ie just like a radiobutton). I tried to do this by using both the recordclickhandler and the "onchanged" handler. Neither worked fine. Here were the problems:
<b>Attempt #1: Using recordclickhandler:</b>
Code is below. But the problem is that the recordclickhandler would only work the FIRST time I clicked on the the checkbox. For the 2nd time, it wouldn't fire the recordclickhandler UNLESS I, as the user, selected a different record first and then re-select the original record.
Code:
lgfSkip.addRecordClickHandler(new RecordClickHandler() {
@Override
public void onRecordClick(RecordClickEvent event) {
Record rc = event.getRecord();
Boolean skip = rc.getAttributeAsBoolean("skip");
String anIAFileID = rc.getAttributeAsString("anIAFileID");
FileToCopyMove fileToCopyMove = getFilesToCopyMove(anIAFileID);
if (skip) {
//rc.setAttribute("skip",false);
fileToCopyMove.setConflict_res_action(CONFLICT_RES_ACTION.SKIP);
rc.setAttribute("override",true);
}
else {
//rc.setAttribute("skip",true);
fileToCopyMove.setConflict_res_action(CONFLICT_RES_ACTION.OVERRIDE);
rc.setAttribute("override",false);
}
}
});
<b>Attempt #2: Using On Changed Handler</b>
Code is below. This worked better than attemp #1 above, in that I could select/deselect a row as many times as I wanted *without* having to select another row first. However, if this was my 2nd click on a checkbox, it would NOT reflect the change that I made to other attributes of the row *until* I selected something else (eg a label in the window etc.). So my question here is there a "right" way to force the row to "refresh" and reflect the changes made to the record if this is the 2nd click of the checkbox?
In general, I think there is something subtle about the "clicking of a checkbox" that causes odd behaviour if you try to click on it a 2nd time in a row.
Code:
lgfSkip.addChangedHandler(new ChangedHandler() {
@Override
public void onChanged(ChangedEvent event) {
int recordNum=event.getRowNum();
Boolean skip = (Boolean) event.getValue();
ListGridRecord rc = lgFilesWithConflict.getRecord(recordNum);
rc.setAttribute("override",!skip);
//lgfOverride.
String anIAFileID = rc.getAttributeAsString("anIAFileID");
FileToCopyMove fileToCopyMove = getFilesToCopyMove(anIAFileID);
if (skip) {
fileToCopyMove.setConflict_res_action(CONFLICT_RES_ACTION.SKIP);
}
else {
fileToCopyMove.setConflict_res_action(CONFLICT_RES_ACTION.OVERRIDE);
}
// lgFilesWithConflict.deselectAllRecords();
// if (recordNum !=0) lgFilesWithConflict.selectRecord(recordNum-1);
// else lgFilesWithConflict.selectRecord(recordNum+1);
lgFilesWithConflict.saveAllEdits();
//lgFilesWithConflict.redraw();
//lgFilesWithConflict.refreshRow(recordNum);
// lbInsr.setSelected(true);
// lbInsr.select();
System.out.println("refetching!!!");
// lgFilesWithConflict.invalidateCache();
// lgFilesWithConflict.fetchData();
}
});
lgFilesWithConflict = new ListGrid();
lgFilesWithConflict.setWidth("100%");
lgFilesWithConflict.setHeight(355);
lgFilesWithConflict.setSaveByCell(true);
// lgFilesWithConflict.setAutoSaveEdits(true);
// lgFilesWithConflict.setCanEdit(true);
lgFilesWithConflict.setEditEvent(ListGridEditEvent.CLICK);
lgFilesWithConflict.setCanEdit(true);
lgFilesWithConflict.setSelectionType(SelectionStyle.NONE);
Miscellaneous Infrastucture Details:
==================================
OS: Windows XP Pro
IDE: MyEclipse 10.0 with Google Plugin for Eclipse (2.5)
SmartGWT Pro 3.0 (Purchased Licence)
Browser: Mozilla Firefox 4.0.1
GWT SDK: 2.4.0
Sun JDK 1.6.0_27
Comment