Be sure your post includes:
I need to display a grid(using ListGrid which is databound)
On click of one of the field , it should be edited to a combo box and based on the values in other columns of the same row, set of values needs to be populated in the combo box which also retrieves data from backend.
Following is my code snippet:
For Grid
final DataSource dataSource = new DataSource();
dataSource.setDataFormat(DSDataFormat.JSON);
String url = GWT.getModuleBaseURL() + "getBonds?fetch=Bonds";
System.out.println("url here is" + url);
dataSource.setDataURL(url);
For combo box
final DataSource curveListDS = ComboBoxOptionDS.getInstance("Curves");
OperationBinding fetchCurves = new OperationBinding();
fetchCurves.setOperationType(DSOperationType.FETCH);
fetchCurves.setDataProtocol(DSProtocol.GETPARAMS);
fetchCurves.setDataURL(curveurl);
curveListDS.setOperationBindings(fetchCurves);
final SelectItem curveItem = new SelectItem();
//curveItem.setPickListWidth(210);
curveItem.setAllowEmptyValue(true);
curveItem.setOptionDataSource(curveListDS);
curveItem.setAutoFetchData(true);
curveItem.setDisplayField("curveName");
curveItem.setValueField("curveId");
curveItem.setName("curveName");
Adding combo box to grid
final DataSourceTextField CURVE_NAME = new DataSourceTextField(
"curvveName", "Curve Name");
CURVE_NAME.setCanEdit(true);
CURVE_NAME.setEditorType(curveItem);
grid.addCellClickHandler(new CellClickHandler() {
Integer colnum = null;
public void onCellClick(CellClickEvent event) {
ListGridRecord record = event.getRecord();
colnum = event.getColNum();
System.out.println("colnum" + colnum);
if (colnum.toString().matches("3")) {
ccy = record.getAttribute("ccy");
spn = record.getAttribute("spn");
System.out.println("calling fetchData");
curveListDS.fetchData();
System.out.println("exiting fetchdata");
// curveListDS.updateData(record, callback, requestProperties)
}
}
});
To create dynamic url on click of each combo box
protected Object transformRequest(DSRequest dsRequest) {
System.out.println("inside transformRequest");
//DSOperationType operationType = request.getOperationType();
//System.out.println("operationType here"+operationType);
dsRequest.setPrompt("Hi there " + dsRequest.getDataSource());
String operationType = dsRequest.getOperationType().toString();
System.out.println("operationType >>>>"+operationType);
if (operationType.equals("FETCH")) {
System.out.println("before" + xmlSerialize(dsRequest.getData()) + "before");
//JSOHelper.setAttribute(dsRequest.getData(), "spn", spn);
//String[] values = new String[]{spn,ccy};
//JSOHelper.setAttribute(dsRequest.getData(), "criteria", values);
//System.out.println("after " + xmlSerialize(dsRequest.getData()) + "after");
dsRequest.setActionURL(GWT.getModuleBaseURL()+ "getCurves?fetch=curves&spn="+spn+"&ccy="+ccy);
}
super.transformRequest(dsRequest);
return dsRequest.getData();
}
Now , the issue is that eventhoigh I can see that the db is hit , but the combo box is not getting populated with the values from backend.
The backend data is in json format.
And the display value should be curvename and its hidden value should be curveId.
I need to display a grid(using ListGrid which is databound)
On click of one of the field , it should be edited to a combo box and based on the values in other columns of the same row, set of values needs to be populated in the combo box which also retrieves data from backend.
Following is my code snippet:
For Grid
final DataSource dataSource = new DataSource();
dataSource.setDataFormat(DSDataFormat.JSON);
String url = GWT.getModuleBaseURL() + "getBonds?fetch=Bonds";
System.out.println("url here is" + url);
dataSource.setDataURL(url);
For combo box
final DataSource curveListDS = ComboBoxOptionDS.getInstance("Curves");
OperationBinding fetchCurves = new OperationBinding();
fetchCurves.setOperationType(DSOperationType.FETCH);
fetchCurves.setDataProtocol(DSProtocol.GETPARAMS);
fetchCurves.setDataURL(curveurl);
curveListDS.setOperationBindings(fetchCurves);
final SelectItem curveItem = new SelectItem();
//curveItem.setPickListWidth(210);
curveItem.setAllowEmptyValue(true);
curveItem.setOptionDataSource(curveListDS);
curveItem.setAutoFetchData(true);
curveItem.setDisplayField("curveName");
curveItem.setValueField("curveId");
curveItem.setName("curveName");
Adding combo box to grid
final DataSourceTextField CURVE_NAME = new DataSourceTextField(
"curvveName", "Curve Name");
CURVE_NAME.setCanEdit(true);
CURVE_NAME.setEditorType(curveItem);
grid.addCellClickHandler(new CellClickHandler() {
Integer colnum = null;
public void onCellClick(CellClickEvent event) {
ListGridRecord record = event.getRecord();
colnum = event.getColNum();
System.out.println("colnum" + colnum);
if (colnum.toString().matches("3")) {
ccy = record.getAttribute("ccy");
spn = record.getAttribute("spn");
System.out.println("calling fetchData");
curveListDS.fetchData();
System.out.println("exiting fetchdata");
// curveListDS.updateData(record, callback, requestProperties)
}
}
});
To create dynamic url on click of each combo box
protected Object transformRequest(DSRequest dsRequest) {
System.out.println("inside transformRequest");
//DSOperationType operationType = request.getOperationType();
//System.out.println("operationType here"+operationType);
dsRequest.setPrompt("Hi there " + dsRequest.getDataSource());
String operationType = dsRequest.getOperationType().toString();
System.out.println("operationType >>>>"+operationType);
if (operationType.equals("FETCH")) {
System.out.println("before" + xmlSerialize(dsRequest.getData()) + "before");
//JSOHelper.setAttribute(dsRequest.getData(), "spn", spn);
//String[] values = new String[]{spn,ccy};
//JSOHelper.setAttribute(dsRequest.getData(), "criteria", values);
//System.out.println("after " + xmlSerialize(dsRequest.getData()) + "after");
dsRequest.setActionURL(GWT.getModuleBaseURL()+ "getCurves?fetch=curves&spn="+spn+"&ccy="+ccy);
}
super.transformRequest(dsRequest);
return dsRequest.getData();
}
Now , the issue is that eventhoigh I can see that the db is hit , but the combo box is not getting populated with the values from backend.
The backend data is in json format.
And the display value should be curvename and its hidden value should be curveId.
Comment