我在jsp画面上有一个textbox在validator里面有check,但是这个控件在jsp里是根据一个flg来决定显示不显示的,当画面不显示的时候,validator因为找不到指定控件而报错,据说可以在validator里面做判断是不是要做那个check,哪位高人教小弟一把,如果在validator里面判断,具体怎么写法,判断的标准和值怎么取得,最好给一段具体的代码看一下,谢谢了
调试欢乐多
我不知道。
不过你可以这样:如果不显示的话,你可以把它设为隐藏字段,然后给他一个默认值。
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/**
* <strong>LogonForm</strong> handles the form
* that the user will use to logon to the application.
*/public final class LogonForm extends ActionForm {
private String username = null;
private String password = null;
public String getUserName() {
return (this.username);
} public void setUserName(String username) {
this.username = username;
}
public String getPassword() {
return (this.password);
} public void setPassword(String password) {
this.password = password;
} public void reset(ActionMapping mapping, HttpServletRequest request) {
this.username = null;
this.password = null; } public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) { ActionErrors errors = new ActionErrors();
if ((username == null) || (username.length() < 1))
errors.add("username", new ActionMessage("error.username.required"));
if ((password == null) || (password.length() < 1))
errors.add("password", new ActionMessage("error.password.required")); return errors; }
}
其实也没看明白你想说社么 呵呵 贴段代码你参考
在你指定的validator节点里面加上
<validator name="textCheck"
classname=".........."
...<javascript><![CDATA[
function textCheck() {}
]]>
</javascript>
</validator>当然了,在你自己的class里面也要加上相应的check