ATG中的自定义表单处理程序的错误处理
问题描述:
我是ATG的新手。我正在尝试使用我自己的RepositoryFormHandler。但我无法在表单上进行验证。ATG中的自定义表单处理程序的错误处理
这是我的java文件:
public class MyLoginBean extends RepositoryFormHandler {
private String logname;
private String logpwd;
private String message;
public String getLogname() {
return logname;
}
public void setLogname(String logname) {
this.logname = logname;
}
public String getLogpwd() {
return logpwd;
}
public void setLogpwd(String logpwd) {
this.logpwd = logpwd;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public boolean handleLogname(DynamoHttpServletRequest pRequest,
DynamoHttpServletResponse pResponse) throws ServletException,
IOException {
boolean tf=true;
if(logname.isEmpty() || logname==null)
{
tf=false;
setMessage("User name can't empty");
}
System.out.println("inside logname");
return tf;
}
public void handleFormException(DropletFormException exception,
DynamoHttpServletRequest request, DynamoHttpServletResponse response) {
// TODO Auto-generated method stub
super.handleFormException(exception, request, response);
}
}
这里是我的.jsp文件:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/dspTaglib" prefix="dsp" %>
<dsp:importbean bean="/atg/dynamo/droplet/ErrorMessageForEach"/>
<dsp:importbean bean="/dynamusic/MyLoginBean"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Custom Login</title>
</head>
<body>
<dsp:form style="color:white">
<table style="background:#3b5998">
<tr>
<td>
<ul>
<dsp:droplet name="ErrorMessageForEach">
<dsp:param bean="MyLoginBean.formExceptions" name="exceptions"/>
<dsp:oparam name="output">
<li>
<dsp:valueof param="message"/>
</li>
</dsp:oparam>
</dsp:droplet>
</ul>
</td>
</tr>
<tr>
<td>
User Name:
</td>
<td>
Password:
</td>
</tr>
<tr>
<td>
<dsp:input type="text" name="logname" bean="MyLoginBean.logname"> </dsp:input>
</td>
<td>
<dsp:input type="password" name="logpwd" bean="MyLoginBean.logpwd"> </dsp:input>
</td>
<td>
<dsp:input type="submit" bean="MyLoginBean.login"> </dsp:input>
</td>
</tr>
</table>
</dsp:form>
</body>
</html>
这一切到目前为止,我已经试过,仍然尝试别的东西。 请建议解决方案,并告诉我在这里粘贴的代码中的错误,如果有的话。
答
- 不要覆盖handleFormException
- 而不是使用setMessage的,使用ATG的内置行为。所有表单处理程序都从GenericFormHandler超类继承了一个Vector异常表单。要添加一个错误,使用:
addFormException(new DropletException("Your error message"));
然后,在你的方法结束时,拨打:如果任何形式的例外已添加
return checkFormRedirect(getSuccessUrl(), getFailUrl(), pRequest, pResponse);
此检查,如果所以,重定向到failUrl,否则重定向到successUrl。
- 按照惯例,你应该为您的表单处理程序* FormHandler,例如ProfileFormHandler,BillingInfoFormHandler,PaymentInfoFormHandler等
您对'logname'的访问者将与您的'handleLogname'方法冲突,因为这两者都将被表单称为“MyLoginBean.logname”。看起来您随后通过在JSP上使用'MyLoginBean.login'来解决此问题,但在Java代码中没有相关的'handle'方法。另请参阅Patrick的评论以获取更多指导。 – radimpe 2014-10-28 08:31:14