表格-后台的提交前校验

1.样例说明

后台的提交前校验功能:在表单提交前,进行数据校验、规则校验、业务校验等功能,如果不符合条件,直接抛出异常;当通过校验后,直接进行保存操作。

2.样例配置

2.1样例配置如下图所示:
表格-后台的提交前校验

2.2关键代码:

package com.kingdee.eas.custom;
import java.math.BigDecimal;
import java.util.Iterator;
import org.springframework.ui.ModelMap;
import com.kingdee.bos.BOSException;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.eventbus.event.action.KDActionEvent;
import com.kingdee.bos.webframework.exception.WafException;
import com.kingdee.bos.webframework.dynamic.application.WebSymbolConstant;
import com.kingdee.bos.webframework.dynamic.handler.AbstractWebEventHandler;
import com.kingdee.bos.eventbus.event.action.IActionEventHandler;
import com.kingdee.eas.custom.webdevsample.NetOrderEntry;
import com.kingdee.eas.custom.webdevsample.NetOrderEntryCollection;
import com.kingdee.eas.custom.webdevsample.NetOrderEntryInfo;
import com.kingdee.eas.custom.webdevsample.NetOrderInfo;

public class BeforeSubmitHandler extends AbstractWebEventHandler implements IActionEventHandler {
	public void onAction(KDActionEvent event) throws WafException,BOSException {
	
		ModelMap modelMap = event.getReqeustContext().get(ModelMap.class);
		NetOrderInfo model=(NetOrderInfo)modelMap.get(WebSymbolConstant.MODEL_ATTRIBUTE_KEY);
		NetOrderEntryCollection collection =  model.getEntrys();
		
		Iterator<NetOrderEntryInfo> netOrderEntryInfos = collection.iterator();
		NetOrderEntryInfo netOrderEntryInfo = null;
		BigDecimal price = null;
		BigDecimal qty = null;
		BigDecimal amnt = null;
		
		//循环分录表格数据
		while(netOrderEntryInfos.hasNext()){
			netOrderEntryInfo = netOrderEntryInfos.next();

			//得到分录表格中单价
			price = netOrderEntryInfo.getPrice();

			//得到分录表格中数量
			qty = netOrderEntryInfo.getQty();

			//得到分录表格中金额
			amnt = netOrderEntryInfo.getAmnt();
			
			//判断分录表格中的金额是否等于单价乘以数量
			if (amnt.equals(price.multiply(qty))) {
				//计算正确!
			} else {
				//计算错误!
				throw new WafException("金额不等于单价乘以数量,请重新计算!");
			}
		}
	}
}

2.3显示效果:
表格-后台的提交前校验

3.样例演示

1.配置页面

2.预览页面

相关样例