Ext 实时验证某个输入值是否已经与数据库中的某条记录重名

步骤:


1. js文件:

		this.bIsExist = false;//判断是否已存在的标志

		{
							xtype : 'textfield',
							fieldLabel : '合同号',
							name : 'RegisterField_contractNum',
							value:contractNum,
							labelStyle : 'text-align:right;',
							validator : this.checkUserName,//validator为自定义校验函数属性
							invalidText : '该合同号已存在!',
							allowBlank : false
						}

	 /**
	 * 功能:验证合同号是否已存在
	 */
	,checkIsExist : function() {

		//定义变量值
		var number = this.ownerCt.find('name','RegisterField_contractNum')[0].getValue();//获取textfield的name属性值
		
		/*-------------- 发送请求----------------*/
		Ext.Ajax.request({
					url : 'ContractAction_checkExist.do',
					params : {
						contractNum : number
					},
					method : 'POST',
					scope : this.ownerCt,
					success : function(response, options) {
						var responseArray = Ext.util.JSON
								.decode(response.responseText);
						if (responseArray.success == true) // 合同号已经被使用
							this.bIsExist = false;// 给变量赋值
						else
							// 合同号可以使用
							this.bIsExist = true;// 给变量赋值
					}
				});
		 /*-------------/ 发送请求----------------*/
		return this.ownerCt.bIsExist;
	}


2. Action中:

	/**检查合同号是否已经存在
	 *@author William
	 *@return String
	 * */
	public String checkExist(){
		super.setContentType(super.JSON);
		String	contractNum	 = super.getRequest().getParameter("contractNum"); // 获取合同号
		//验证用户是否存在
		try {
			int id = contractService.sContractIdByInfo(contractNum);
			if( 0 < id )
				super.outPrint("{success:true}");
			else
				super.outPrint("{success:false}");
		} catch (SQLException e) { 
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "json";
	}


3. Service中:

	/**根据合同号查询合同是否已经存在
	 * @author William
	 * @return id 如果存在则返回合同id, 如果不存在则返回 0
	 * @param String 合同号
	 * */
	public int sContractIdByInfo(String contractNum ) throws SQLException{
		return contractDao.sContractIdByInfo(contractNum);
	}


4. Dao中:

	/**根据合同号查询合同是否已经存在
	 * @author William
	 * @return id 如果存在则返回合同id, 如果不存在则返回 0
	 * @param String 合同号
	 * */
	public int sContractIdByInfo(String contractNum ) throws SQLException{
		int id = 0;
		Object oReturn = sqlMapClient.queryForObject("Contract.sContractIdByInfo",contractNum);
		if( null != oReturn ){
			id = (Integer)oReturn;
		}
		return id;
	}


5. xml中:

	<!-- 根据合同号 查询合同是否存在 -->
	<select id="sContractIdByInfo" resultClass="int" parameterClass="string" >
		<![CDATA[ SELECT id FROM sd_contract  WHERE  num = #contractNum# ]]>
	</select>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值