Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

Validate on 'Add' and 'update' action is different

$
0
0
smartgwt.version: 4.1p
gwt.version: 2.5.1
fireFox:24.2

My question
1. how the servercustom validate method get the operationtype Add/New? because I need to different validate rule with Add/New action.
2. I want to get the grid previous row value to validate with current row value, how can I get the previous row value?
Pls help, many thanks.

DS:
<field name="rclmTaxRat" required="true" title="Tax Rate" type="float" primaryKey="true" >
@rclmTaxRatValidator@
</field>
<field name="taxRatSrt" required="true" title="Start Date" type="date">
<validators>
<validator type="serverCustom">
<serverObject lookupStyle="spring" bean="taxRatSrtValidator"/>
<errorMessage>$errorMessage</errorMessage>
</validator>
</validators>
</field>


Validate method as below:
public boolean condition(final Object value, final Validator validator,
final String fieldName, final Map record, final DataSource ds)
throws Exception {
LOGGER
.info("validating value: '" + value + "' for fieldName: '"
+ fieldName + "' in DataSource: '" + ds.getID()
+ "'\nin record: " + DataTools.prettyPrint(record)
+ "\nvalidator definition: "
+ DataTools.prettyPrint(validator));
// check operation type is equal to expected operation type: Edit or New
if (!isNullOrEmpty(record.get("screnOpsType"))
&& !expectedOpsType.equals(record.get("screenOpsType"))) {
return true;
}

// Validate when all notnullFields have value
if (isNotEmpty(notNullFields)) {
final String[] keys = notNullFields.split(",");
for (String key : keys) {
key = key.trim();
if (isNullOrEmpty(record.get(key))) {
return true;
}
}
}
List<?> resultSet = null;
// record.put(fieldName.trim() + "New", value);
resultSet = DataSource.query(query, record, voName);

if (!resultSet.isEmpty()) {
validator.addErrorMessageVariable("errorMessage", errorMessage);
return false;
}
return true;
}

Viewing all articles
Browse latest Browse all 4756

Trending Articles