Hi Isomorphic,
continuing this thread here (v12.0p_2019-01-05). Please see this BuiltInDS-based testcase:
BuiltInDS.java:
TestValidator.java:
supplyItem.ds.xml:
Flow to reproduce:
Best regards
Blama
continuing this thread here (v12.0p_2019-01-05). Please see this BuiltInDS-based testcase:
BuiltInDS.java:
Code:
package com.smartgwt.sample.client;
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.Version;
import com.smartgwt.client.core.KeyIdentifier;
import com.smartgwt.client.data.AdvancedCriteria;
import com.smartgwt.client.data.Criterion;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.SortSpecifier;
import com.smartgwt.client.types.OperatorId;
import com.smartgwt.client.types.SortDirection;
import com.smartgwt.client.util.Page;
import com.smartgwt.client.util.PageKeyHandler;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.VLayout;
public class BuiltInDS implements EntryPoint {
private VLayout mainLayout;
private IButton recreateBtn;
public void onModuleLoad() {
KeyIdentifier debugKey = new KeyIdentifier();
debugKey.setCtrlKey(true);
debugKey.setKeyName("D");
Page.registerKey(debugKey, new PageKeyHandler() {
public void execute(String keyName) {
SC.showConsole();
}
});
mainLayout = new VLayout(20);
mainLayout.setWidth100();
mainLayout.setHeight100();
recreateBtn = new IButton("Recreate");
recreateBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
recreate();
}
});
mainLayout.addMember(recreateBtn);
recreate();
mainLayout.draw();
}
private void recreate() {
Window w = new Window();
w.setWidth("95%");
w.setHeight("95%");
w.setMembersMargin(0);
w.setModalMaskOpacity(70);
w.setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
w.setTitle("TITLE" + w.getTitle());
w.setShowMinimizeButton(false);
w.setIsModal(true);
w.setShowModalMask(true);
w.centerInPage();
final ListGrid supplyItemGrid = new ListGrid(DataSource.get("supplyItem"));
supplyItemGrid.setHeight100();
supplyItemGrid.setWidth100();
supplyItemGrid.setCanEdit(true);
supplyItemGrid.setAutoFetchData(false);
ListGridField itemID = new ListGridField("itemID");
ListGridField itemName = new ListGridField("itemName");
ListGridField sku = new ListGridField("SKU");
ListGridField category = new ListGridField("category");
ListGridField units = new ListGridField("units");
ListGridField unitCost = new ListGridField("unitCost");
ListGridField inStock = new ListGridField("inStock");
ListGridField nextShipment = new ListGridField("nextShipment");
supplyItemGrid.setFields(itemID, itemName, sku, category, units, unitCost, inStock, nextShipment);
supplyItemGrid.setSort(new SortSpecifier[] { new SortSpecifier(itemName.getName(), SortDirection.ASCENDING) });
supplyItemGrid.fetchData(new AdvancedCriteria(new Criterion(itemName.getName(), OperatorId.STARTS_WITH, "A")));
w.addItem(supplyItemGrid);
w.show();
}
}
Code:
package com.smartgwt.sample.server.listener;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.isomorphic.datasource.DSResponse;
import com.isomorphic.datasource.DataSource;
import com.isomorphic.datasource.Validator;
import com.isomorphic.log.Logger;
public class TestValidator {
Logger log = new Logger(DSResponse.class.getName());
public boolean condition(Object value, Validator validator, String fieldName, @SuppressWarnings("rawtypes") Map record, DataSource ds,
HttpServletRequest httpServletRequest) throws Exception {
log.info("TestValidator called");
String valueName = (String) record.get("itemName");
if (!valueName.equals("Account Book 168 Page Hardcover A4 4MC")) {
validator.addErrorMessageVariable("errorMessage", "Error");
return false;
} else
return true;
}
}
Code:
<DataSource ID="supplyItem" serverType="sql" tableName="supplyItem" titleField="itemName"
testFileName="/examples/shared/ds/test_data/supplyItem.data.xml" dbImportFileName="/examples/shared/ds/test_data/supplyItemLarge.data.xml">
<fields>
<field name="itemID" type="sequence" hidden="true" primaryKey="true" />
<field name="itemName" type="text" title="Item" length="128" required="true">
<validators>
<validator type="serverCustom" validateOnChange="true">
<serverObject lookupStyle="new" className="com.smartgwt.sample.server.listener.TestValidator" />
<errorMessage>$errorMessage</errorMessage>
<dependentFields>
<dependentField>inStock</dependentField>
<dependentField>SKU</dependentField>
</dependentFields>
</validator>
</validators>
</field>
<field name="SKU" type="text" title="SKU" length="10" required="true" />
<field name="description" type="text" title="Description" length="2000" />
<field name="category" type="text" title="Category" length="128" required="true" foreignKey="supplyCategory.categoryName" />
<field name="units" type="enum" title="Units" length="5">
<valueMap>
<value>Roll</value>
<value>Ea</value>
<value>Pkt</value>
<value>Set</value>
<value>Tube</value>
<value>Pad</value>
<value>Ream</value>
<value>Tin</value>
<value>Bag</value>
<value>Ctn</value>
<value>Box</value>
</valueMap>
</field>
<field name="unitCost" type="float" title="Unit Cost" required="true">
<validators>
<validator type="floatRange" min="0" errorMessage="Please enter a valid (positive) cost" />
<validator type="floatPrecision" precision="2" errorMessage="The maximum allowed precision is 2" />
</validators>
</field>
<field name="inStock" type="boolean" title="In Stock" />
<field name="nextShipment" type="date" title="Next Shipment" />
</fields>
</DataSource>
- Double click a row to enter edit mode
- Change "In Stock" or "SKU" to see validation requests issued as expected
- See that the requests return an error (expected)
- This error is not shown in the GUI (issue one, might be on purpose (?))
- Exit row to issue update (possible, as the error is not shown in the GUI, see above)
- Update issued successfully and validator server code not hit (issue two, validator should be hit)
- "In Stock" toggle without entering ListGrid edit mode also does not trigger the server side validator
Best regards
Blama
Comment