jsp(部分):
<%@taglib prefix="px" uri="fly.tld" %> <div id="InputDiv" class="inputdiv">
<label>客户姓名:</label><br/>
<input type="text" id="fname" name="FNAME" onkeydown="<px:CheckValue sFieldName="${fname.name}" sFieldValue="${fname.text}" />"/><br/>
<label>姓名拼音:</label><br/>
<input type="text" id="sname"/><br/>
<label>身份证件号:</label><br/>
<input type="button" id="btnSave" value="保存"/>
</div>tld:<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>fly</short-name>
<uri>/fly</uri>
<function>
<name>CheckValue</name>
<function-class>src.CheckInput</function-class>
<function-signature>
void CheckFieldValue(String sFieldName, String sFieldValue)
</function-signature>
</function>
<tag>
<description>random</description>
<name>CheckValue</name>
<tag-class>src.CheckInput</tag-class>
<body-content>empty</body-content>
<attribute>
<name>sFieldName</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>sFieldValue</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
校验类:/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/package src;import javax.swing.JOptionPane;/**
*
* @author zhanglongfei
*/
public class CheckInput{ private String sFieldValue;
private String sFieldName; public static void CheckFieldValue(String sFieldValue, String sFieldName)
{
//这里把字段名和字段内容作为参数对字段内容进行校验
} /**
* @return the sFieldValue
*/
public String getSFieldValue() {
return sFieldValue;
} /**
* @param sFieldValue the sFieldValue to set
*/
public void setSFieldValue(String sFieldValue) {
this.sFieldValue = sFieldValue;
} /**
* @return the sFieldName
*/
public String getSFieldName() {
return sFieldName;
} /**
* @param sFieldName the sFieldName to set
*/
public void setSFieldName(String sFieldName) {
this.sFieldName = sFieldName;
}
}
我想要的效果是在文本框录入内容,按回车就触发校验, 若合法就跳到下一个文本框,不合法提示错误并停留在该文本框。
我设想的是通过tld配置校验类,如上代码, 问下我这样想对不对?
但是出错了 说 Cannot find a setter method for the attribute sFieldName of the tag handler src.CheckInput, 但是我明明有sFieldName 字段的 set方法阿?
还有 如果我这种设想是正确的? 在文本框的OnKeyDown事件中应该怎么处理实现:
按回车就触发校验, 若合法就跳到下一个文本框,不合法提示错误并停留在该文本框。
<%@taglib prefix="px" uri="fly.tld" %> <div id="InputDiv" class="inputdiv">
<label>客户姓名:</label><br/>
<input type="text" id="fname" name="FNAME" onkeydown="<px:CheckValue sFieldName="${fname.name}" sFieldValue="${fname.text}" />"/><br/>
<label>姓名拼音:</label><br/>
<input type="text" id="sname"/><br/>
<label>身份证件号:</label><br/>
<input type="button" id="btnSave" value="保存"/>
</div>tld:<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>fly</short-name>
<uri>/fly</uri>
<function>
<name>CheckValue</name>
<function-class>src.CheckInput</function-class>
<function-signature>
void CheckFieldValue(String sFieldName, String sFieldValue)
</function-signature>
</function>
<tag>
<description>random</description>
<name>CheckValue</name>
<tag-class>src.CheckInput</tag-class>
<body-content>empty</body-content>
<attribute>
<name>sFieldName</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>sFieldValue</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
校验类:/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/package src;import javax.swing.JOptionPane;/**
*
* @author zhanglongfei
*/
public class CheckInput{ private String sFieldValue;
private String sFieldName; public static void CheckFieldValue(String sFieldValue, String sFieldName)
{
//这里把字段名和字段内容作为参数对字段内容进行校验
} /**
* @return the sFieldValue
*/
public String getSFieldValue() {
return sFieldValue;
} /**
* @param sFieldValue the sFieldValue to set
*/
public void setSFieldValue(String sFieldValue) {
this.sFieldValue = sFieldValue;
} /**
* @return the sFieldName
*/
public String getSFieldName() {
return sFieldName;
} /**
* @param sFieldName the sFieldName to set
*/
public void setSFieldName(String sFieldName) {
this.sFieldName = sFieldName;
}
}
我想要的效果是在文本框录入内容,按回车就触发校验, 若合法就跳到下一个文本框,不合法提示错误并停留在该文本框。
我设想的是通过tld配置校验类,如上代码, 问下我这样想对不对?
但是出错了 说 Cannot find a setter method for the attribute sFieldName of the tag handler src.CheckInput, 但是我明明有sFieldName 字段的 set方法阿?
还有 如果我这种设想是正确的? 在文本框的OnKeyDown事件中应该怎么处理实现:
按回车就触发校验, 若合法就跳到下一个文本框,不合法提示错误并停留在该文本框。
===============================================
onkeydown="<px:CheckValue sFieldName='${fname.name}' sFieldValue='${fname.text}' />"
里面的改成单引号
<script type="text/javascript">
function handleEnter (field, event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13) {
var i;
for (i = 0; i < field.form.elements.length; i++)
if (field == field.form.elements[i])
break;
i = (i + 1) % field.form.elements.length;
field.form.elements[i].focus();
return false;
}
else
return true;
}
</script>
<form>
<input type="text" onkeypress="return handleEnter(this, event)"><br>
<input type="text" onkeypress="return handleEnter(this, event)"><br>
<textarea>Some text</textarea>
</form>
因为我没有环境,具体的你再改一下变成你所需要的,我接分就行了哈哈
楼主不妨试试fieldName
看来也只有AJAX满足你的要求了。我自己的一点看法。
Cannot find a setter method for the attribute sFieldName of the tag handler src.CheckInput