Validation¶
About the server side validation in intra-mart Accel Kaiden!, validator class creation and validator class execution will be each described.
Validator Creation¶
Validator sample is posted.package jp.co.slcs.kaiden2.base.foundation.util.validate; import java.util.List; import java.util.Map; import jp.co.slcs.kaiden2.base.foundation.conf.BaseProp; import jp.co.slcs.kaiden2.base.foundation.util.CollectionUtil; import jp.co.slcs.kaiden2.base.foundation.util.StringUtil; /** * XXX check validator. */ public class XxxValidator extends KaidenAbstractValidator implements KaidenValidatorIF { /** default message key when validate error time . */ private static final String DEFAULT_ERROR_MESSAGE_KEY = BaseProp.M.XXXX; /** * constructor. */ public XxxValidator() { super(); } /** * judgement process. */ public boolean isValid(Object value) { // implements check process // returns true when check OK and false when NG return true; } /** * obtains fieldKey specified from valueMap and does check.<br> */ @Override public KaidenValidateResult executeValidate(Map<String, Object> valueMap, String fieldKey, String[] args, Map<String, String> surfaces) { inputCheck(valueMap); Object value = valueMap.get(fieldKey); KaidenValidateResult result = super.makeNewValidateResult(fieldKey, surfaces, StringUtil.toString(value)); // judgement process if (!isValid(value)) { setErrorDetail(result, DEFAULT_ERROR_MESSAGE_KEY); } return result; } }
Explanation¶
executeValidate method implementation is forced by jp.co.slcs.kaiden2.base.foundation.util.validate.KaidenValidatorIF, and validation is executed if this method is called.
The result is set to the validate execution result object, and will be returned.Notes
In intra-mart Accel Kaiden! standard, validator class is set to the dicon file but this is omitted in this chapter.
Validation Execution¶
It explains the implementation method to do validation by using validator class which was created above.// validation target data Map Map<String, Object> dataMap = new HashMap<String, Object>(); dataMap.put("companyCd", ""); // surface Map for error message Map<String, String> surfaceMap = new HashMap<String, String>(); surfaceMap.put("companyCd", "company code"); // server side validate execution class KaidenValidateExecutor validateExecutor = new KaidenValidateExecutor(dataMap, surfaceMap); // add validate definition validateExecutor.addValidateDef("companyCd", "xxx"); // validate execution List<KaidenValidateResult> validateResult = validateExecutor.executeAll();
Explanation¶
Field key and validation ID for check target are specified by validateExecutor.addValidateDef(“companyCd”, “xxx”);.Notes
Validation ID will be the one "Validator" character string is removed from the component name set to the dicon file.