gpt4 book ai didi

java - ATG 中自定义表单处理程序的错误处理

转载 作者:行者123 更新时间:2023-11-29 06:33:27 33 4
gpt4 key购买 nike

我是 ATG 的新手。我正在尝试使用我自己的 RepositoryFormHandler。但是我无法对表单进行验证。

这是我的 .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>

这就是我迄今为止尝试过的所有内容,并且仍在尝试其他方法。请提出解决方案,并告诉我粘贴在此处的代码中的错误(如果有)。

最佳答案

  1. 不要覆盖 handleFormException
  2. 不使用 setMessage,而是使用 ATG 的内置行为。所有表单处理程序都从 GenericFormHandler 父类(super class)继承表单异常的 Vector。要添加错误,请使用:

addFormException(new DropletException("你的错误信息"));

然后,在您的方法结束时,调用:

return checkFormRedirect(getSuccessUrl(), getFailUrl(), pRequest, pResponse);

这会检查是否添加了任何表单异常,如果是,则重定向到 failUrl,否则重定向到 successUrl。

  1. 按照惯例,您应该将表单处理程序命名为 *FormHandler,例如 ProfileFormHandler、BillingInfoFormHandler、PaymentInfoFormHandler 等。

希望这对您有所帮助。参见 http://docs.oracle.com/cd/E22630_01/Platform.1002/apidoc/atg/droplet/GenericFormHandler.html#getFormExceptions()

关于java - ATG 中自定义表单处理程序的错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26586633/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com