Hello-
I am using Smartgwt 4.1p, free version.
I built a set of nested ListGrids, based on two client-only datasources.
Now I want to add a new record to my nested Datasource when I click on an "add" button. I also want to refresh my ListGrid display accordingly. Please see the attached screenshot.
My ListGrid does not display each field from the DS, so the logical approach for me would probably be to avoid using the ListGrid.startEditingNew() and to add instead the Record directly into the nested Datasource. Note that I also tried to add a ListGrid Record and got the same error (see below).
Based on the Smartgwt showcase, I tried this code in my main display:
Nested Datasource:
ListGrid associated with the nested Datasource:
Nothing happens when I click my "Add" button and the console throws this error: "clientOnly dataSource found a missing value for primaryKey field 'secure' during an add request".
Can someone advise on how to perform an add on a nested Datasource?
I am using Smartgwt 4.1p, free version.
I built a set of nested ListGrids, based on two client-only datasources.
Now I want to add a new record to my nested Datasource when I click on an "add" button. I also want to refresh my ListGrid display accordingly. Please see the attached screenshot.
My ListGrid does not display each field from the DS, so the logical approach for me would probably be to avoid using the ListGrid.startEditingNew() and to add instead the Record directly into the nested Datasource. Note that I also tried to add a ListGrid Record and got the same error (see below).
Based on the Smartgwt showcase, I tried this code in my main display:
Code:
IButton newButton = new IButton("Add");
newButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
TransactionDS.getInstance().addData(
createRecord("siteName", "actorCode", "actorName", "transactionCode", "transactionName", "tls", "notls", "repositoryUniqueID"));
}
});Code:
public Record createRecord(String siteName, String actorCode, String actorName, String transactionCode, String transactionName, String tls, String notls, String repositoryUniqueID) {
Record record = new Record();
record.setAttribute("siteName", siteName);
record.setAttribute("actorCode", actorCode);
record.setAttribute("actorName", actorName);
record.setAttribute("transactionCode", transactionCode);
record.setAttribute("transactionName", transactionName);
record.setAttribute("tls", tls);
record.setAttribute("notls", notls);
record.setAttribute("repositoryUniqueID", repositoryUniqueID);
return record;
}Code:
package gov.nist.toolkit.xdstools3.client.customWidgets.endpoints.configure;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceTextField;
/**
* SmartGWT datasource.
*
* Field names must match the XML source and must be unique to this datasource.
*/
public class TransactionDS extends DataSource {
private static TransactionDS instance = null;
public static TransactionDS getInstance() {
if (instance == null) {
instance = new TransactionDS();
}
return instance;
}
private TransactionDS() {
setID("transactionDS");
setDataURL("resources/datasources/endpoints/pub-edited-2.data.xml");
setRecordXPath("/site/actor/transaction"); //the XML path of the element we want to display, in the datasource file (.data.xml)
setClientOnly(true);
//---- actors ----
DataSourceTextField siteName = new DataSourceTextField("siteName", "Site Name");
siteName.setValueXPath("ancestor::site/@siteName");
siteName.setHidden(true);
siteName.setForeignKey("endpointConfigDS.endpointName");
DataSourceTextField actorCode = new DataSourceTextField("actorCode", "Endpoint Code");
actorCode.setValueXPath("parent::actor/@actorCode");
actorCode.setDisplayField("actorName");
actorCode.setHidden(true); // is already displayed in group mode title
DataSourceTextField actorName = new DataSourceTextField("actorName");
actorName.setValueXPath("parent::actor/@actorName");
actorName.setHidden(true); // used only for formatting
//---- transactions -----
DataSourceTextField transactionCode = new DataSourceTextField("transactionCode");
//transactionCode.setPrimaryKey(true);
// transactionCode.setCanEdit(false); // primary keys cannot be edited. A workaround is to delete the record and create a new one with the same values.
transactionCode.setDisplayField("transactionName");
DataSourceTextField transactionName = new DataSourceTextField("transactionName", "Transaction Type");
transactionName.setCanEdit(false);
transactionName.setHidden(true); // used only for formatting
DataSourceTextField tls = new DataSourceTextField("secure", "TLS Endpoint");
tls.setPrimaryKey(true);
DataSourceTextField notls = new DataSourceTextField("unsecure", "Non-TLS Endpoint");
//----- repositoryUniqueID and homeCommunityID ------
DataSourceTextField repositoryUniqueID = new DataSourceTextField("uid");
repositoryUniqueID.setValueXPath("parent::actor/@uid");
setFields(siteName, actorCode, actorName, transactionCode, transactionName, tls, notls, repositoryUniqueID);
}
}ListGrid associated with the nested Datasource:
Code:
package gov.nist.toolkit.xdstools3.client.customWidgets.endpoints.configure;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.types.*;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
/**
* Holds the configuration for the grids displaying a transaction.
*/
public class TransactionGrid extends ListGrid {
public TransactionGrid(){
super();
// --- configuration ---
setDataSource(TransactionDS.getInstance());
setHeight(200);
setCanEdit(true);
setModalEditing(true);
setEditEvent(ListGridEditEvent.CLICK);
setListEndEditAction(RowEndEditAction.NEXT);
setAutoSaveEdits(true);
setAlternateRecordStyles(true);
setGroupByField("actorName");
setGroupStartOpen(GroupStartOpen.ALL);
setCanRemoveRecords(true);
// --- fields ----
ListGridField tls = new ListGridField("secure");
ListGridField transactionCode = new ListGridField("transactionCode");
ListGridField notls = new ListGridField("unsecure");
ListGridField actorName = new ListGridField("actorName");
actorName.setHidden(true);
setFields(actorName, transactionCode, tls, notls);
}
}Can someone advise on how to perform an add on a nested Datasource?