业务场景:业务单据包含分录,单据编辑界面上有分录表格,分录表格录入数据时,校验其中的某一列数据不允许出现重复。
本例中,单据实体名称为ReverseBill,分录实体名称为ReverseBillEntry。
业务校验verifyInput时,界面控件数据已经封装到界面所绑定的数据对象editData。
分录表格中每行数据为一条分录对象ReverseBillEntryInfo、多行数据为分录集合ReverseBillEntryCollection。
/**
* 业务逻辑校验
*/
@Override
protected void verifyInput(ActionEvent e) throws Exception {
ReverseBillEntryCollection coll = editData.getEntry(); //分录集合
if(coll.isEmpty()){
MsgBox.showWarning("分录不能为空!");
abort(); //中断程序
}
Set ids = new HashSet(); //利用集合元素唯一性
StringBuffer msg = new StringBuffer(); //反馈信息
for(int i = 0; i < coll.size(); i++){
ReverseBillEntryInfo entry = coll.get(i); //得到一条分录对象
String personId = entry.getPerson().getId().toString(); //人员ID
if(ids.contains(personId)){
msg.append("分录中第" + (i + 1) + "行人员存在重复!\n");
} else {
ids.add(personId); //人员信息缓存
}
}
if(msg.length() > 0){
msg.append("请检查并修改数据,然后重新保存。");
MsgBox.showWarning(msg.toString());
abort(); //中断程序
}
}