html:errors
来源:互联网 发布:阿里云ddns教程 编辑:程序博客网 时间:2024/04/28 13:37
html:errors标签和html:messages标签的功能相似,所以我们放到一起来介绍。
html:errors标签将由name属性指定的ActionMessages、ActionErrors、String和String[]直接输出到页面中。
html:messages标签将用由name属性(注意message属性值对它的影响)指定的ActionMessages、ActionErrors、String和String[]创建一个新的属性和scripting变量,使用id属性值作为名称。
html:errors标签和html:messages标签的property属性是用来为errors和messages分类的。我们可以给这两个标签指定property属性,以便只显示某一类的错误或消息。
在资源文件增加了如下的内容:
# -- standard errors --
errors.header=<ul>
errors.prefix=<li>
errors.suffix=</li>
errors.footer=</ul>
error=error with none value .
error1=error1 with one value is {0} .
error2=error2 with two values are {0} , {1} .
error3=error3 with three values are {0} , {1} , {2} .
error4=error4 with four values are {0} , {1} , {2} ,{3} .
下面的代码示例了actionErrors的构造:
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors actionErrors = new ActionErrors();
actionErrors.add("property1",
new ActionMessage("error"));
actionErrors.add("property2",
new ActionMessage("error1","value0"));
actionErrors.add("property2",
new ActionMessage("error2","value0","value1"));
actionErrors.add("property3",
new ActionMessage("error3","value0","value1","value2"));
actionErrors.add("property3",
new ActionMessage("error4","value0","value1","value2","value3"));
actionErrors.add("property4",
new ActionMessage("error1",new Object[]{"value0"}));
actionErrors.add("property4",
new ActionMessage("error2",new Object[]{"value0","value1"}));
actionErrors.add("property4",
new ActionMessage("error3",new Object[]{"value0","value1",
"value2"}));
actionErrors.add("property5",
new ActionMessage("error4",new Object[]{"value0","value1",
"value2","value3"}));
actionErrors.add("notBundle",
new ActionMessage("not a bundle key",false));
return actionErrors;
}
errors标签代码示例:
<html:errors/>
<br/>
<html:errors property="property4"/>
messages标签代码示例:
<logic:messagesPresent>
<ul>
<html:messages id="message">
<li><bean:write name="message"/></li>
</html:messages>
</ul>
</logic:messagesPresent>
<br/>
<logic:messagesPresent>
<ul>
<html:messages id="message" property="property4">
<li><bean:write name="message"/></li>
</html:messages>
</ul>
</logic:messagesPresent>
图示 2. 上面的两段代码示例运行结果相同,如下所示:
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/AWUSOFT/archive/2008/05/16/2452874.aspx
- html:errors
- html:errors
- html:errors的使用
- <html:errors/>
- html:errors简析
- Handle HTML errors
- 如何使用 html:errors
- html:errors简析
- html:errors 不显示
- struts <html:errors>
- html errors和html messages
- HTML:MESSAGES,HTML:ERRORS,用法
- Struts html:errors 中文乱码
- html:message和html:errors 小技巧
- html:errors出错的可能原因
- 【struts】html:errors标签的使用
- Errors
- errors
- Archlinux 启动脚本分析(一) -- /etc/inittab
- html:radio
- html:multibox
- html:link
- 【转】Windows Mobile 锁定设备
- html:errors
- 日记090815
- html:javascript
- html:xhtml
- logic:iterate
- 通过ASP实现flash对数据库的访问
- logic:present
- VC下的TCP/IP通信(三)
- logic:messagesPresent