`
gazeldx
  • 浏览: 102277 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Struts2学习

 
阅读更多

 

 

public boolean validateSave() {// 验证选中的必须都是准付。通过此验证,可以有效防止并发操作时对单据的重复付款。
		uids = chk_ids.split(",");
		for (String ids_i : uids) {
			BizFolio bf = mng.findById(Integer.valueOf(ids_i));
			if (!bf.getSext2().equals(DBConstants.Bizfolio_Sext2_CouldPay)) {
				addActionError("_only_allow_could_pay");
				return true;
			}
		}
		return false;
	}

 在save方法前,自动被调用,注意红色必须是addActionError,而不能是addActionMessage。因为后者让程序继续执行,只有前者才能让程序中断,达到validate的目的。

xml中:

 

<many-to-one name="store" column="usstoreid"
			class="com.atech.data.entity.Store" not-null="true">
		</many-to-one>
		<property name="storeid" column="usstoreid" type="integer"
			not-null="true" />

 

 insert="false"
			update="false"在下面两种情况中分别放在:情况1-下侧 情况2-上侧

view中ftl:

情况1:<@p.select label="_store_belong" name="bean.storeid" list=storeList listKey="id" listValue="name" required="true" class="required" headerValue="_tobe_assigned"/><@p.tr/>

 

 

情况2:<@p.select label="_store_belong" name="bean.store.id" list=storeList listKey="id" listValue="name" required="true" class="required" headerValue="_tobe_assigned"/><@p.tr/>

 情况2应该比情况1写法要好一些,能够有效防止不存在的数据进入系统。比如刚刚新增一个store,然后立刻要新增一条人员数据,进入view这个页面,选中了这条新增的store,但还没有点击保存。这时删掉store,然后点击view中的保存,情况1并不会验证这个store是否是存在的,而情况2就能够爆出错误来:

 

org.hibernate.PropertyValueException: not-null property references a null or transient value: com.atech.core.entity.AdminA.store
 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics