`

struts标签之html手册

阅读更多
转过来的文章
http://space.itpub.net/html/76/694276-51409.html




html:checkbox name="checkboxForm" property="one">
One
</html:checkbox>
<html:checkbox name="checkboxForm" property="two">
Two
</html:checkbox>
<html:checkbox name="checkboxForm" property="three">
Three
</html:checkbox>
如果选中后被提交则相应的属性的值为true。
回页首
html:radio
html:radio标签生成一个radio。主要的用法有两种,下面我们通过代码来示例。
下面的代码示例了html:radio标签的一般用法,如果被提交则选中的radio的value值将被提交到radioForm中的id中。

<html:radio name="radioForm" property="id" value="00001">
One
</html:radio>
<html:radio name="radioForm" property="id" value="00002">
Two
</html:radio>
下面的代码示例了html:radio标签的典型用法,其中的persons和bean:define标签中的一致,您可以参考bean:define标签。我只介绍这个<html:radio idName="person" property="id" value="id">,idName指定html:radio要使用的bean(这里为person),value="id"表示person的id属性将作为radio元素的value值而property="id"表示提交时选中的radio的值将被提交给radioForm中的id属性。

<logic:notEmpty name="radioForm" property="persons">
<logic:iterate id="person" name="radioForm" property="persons">
<html:radio idName="person" property="id" value="id">
<bean:write name="person" property="name"/>
</html:radio>
</logic:iterate>
</logic:notEmpty>
回页首
html:multibox
html:multibox标签生成多个checkbox。当您要使用大量的checkbox时使用这个标签非常方便,可以使您避免在ActionForm中声明大量的boolean类型的变量,带之以一个数组就行了。
注意:为了正确的处理没有选中的checkbox您必须在reset()中设置数组的长度为0。
下面的代码示例了html:multibox标签的一般用法,如果被提交则选中的所有checkbox的value值将被提交到multiboxForm中的selectedItems中,这是一个String[]数组。

<html:multibox name="multiboxForm" property="selectedItems"
value="00001"/>
<html:multibox name="multiboxForm" property="selectedItems"
value="00002"/>
下面的代码示例了html:multibox标签的典型用法:

<logic:iterate id="person" name="multiboxForm" property="persons">
<html:multibox property="selectedItems">
<bean:write name="person" property="id"/>
</html:multibox>
<bean:write name="person" property="name"/>
</logic:iterate>
回页首
html:link
html:link标签生成一个锚点(<a>)元素。我从html:link标签如何构造基本url和如何构造query参数两个方面来介绍这个标签。
构造基本url是依据该标签的如下四个属性进行的,这四个属性一次只能出现一个。让我们看看它们:

forward,指定一个全局ActionForward的名称。另外如果forward是module相关的则该forward必须指向一个action而不能是一个页面。
action,指定一个Action的名称。
href,struts会直接使用这个值而不会对其进行任何处理。
page,指定一个页面的路径,必须以/开始。
构造query参数,下面列举了可能的形式,其中baseurl只是一个占位符:

baseurl?p=00001(单参单值)
baseurl?p1=00001&p2=00002&p3=00003(多参单值)
baseurl?p=00001&p=00002&p=00003(单参多值)
baseurl?p1=00001&p2=00002&p=00001&p=00002&p=00003(混合)
下面我们以代码示例来说明每一种html:link的用法,首先让我们花点时间看看相关action中的代码:

<!-- 下面所有代码的数据都是在这里构造的 -->
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {

DataForm dataForm = (DataForm) form;

dataForm.setParam("00001");

HashMap paramSingleMap = new HashMap();
paramSingleMap.put("p1","00001");
paramSingleMap.put("p2","00002");
paramSingleMap.put("p3","00003");
dataForm.setParamSingleMap(paramSingleMap);

HashMap paramMultiMap = new HashMap();
paramMultiMap.put("p",new String[]{"00001","00002","00003"});
dataForm.setParamMultiMap(paramMultiMap);

HashMap paramSMMap = new HashMap();
paramSMMap.put("p1","00001");
paramSMMap.put("p2","00002");
paramSMMap.put("p",new String[]{"00001","00002","00003"});
dataForm.setParamSMMap(paramSMMap);

List<Person> persons = new ArrayList<Person>();
Person person1 = new Person();
person1.setId("00001");
person1.setName("赵辰");
Person person2 = new Person();
person2.setId("00002");
person2.setName("李为芳");
Person person3 = new Person();
person3.setId("00003");
person3.setName("王微");
persons.add(person1);
persons.add(person2);
persons.add(person3);
dataForm.setPersons(persons);

return mapping.findForward("success");
}

<!-- 这用来设置一个位置 -->
<html:link linkName="top"/>
<!-- 这用来定位到上面的那个位置 -->
<html:link page="/link.do" anchor="top">Go Top</html:link>

<html:link page="/link.do" paramId="p" paramName="dataForm"
paramProperty="param">
单参单值
</html:link><br/>
<html:link page="/link.do" name="dataForm" property="paramSingleMap">
多参单值
</html:link><br/>
<html:link page="/link.do" name="dataForm" property="paramMultiMap">
单参多值
</html:link><br/>
<html:link page="/link.do" name="dataForm" property="paramSMMap">
混合
</html:link>
下面的代码示例了html:link标签的indexed属性和indexId属性的用法,这两个属性只有html:link标签嵌套在logic:iterate标签中时才可用。

<logic:iterate id="person" name="dataForm" property="persons">
<html:link action="/link.do" paramId="person" paramName="person"
paramProperty="id" indexed="true" indexId="number">
person
</html:link>
<br/>
</logic:iterate>
<!-- 下面是上面代码的运行结果(产生的html)
<a href="/struts-demo/link.do?person=00001&number=0">赵辰</a><br/>
<a href="/struts-demo/link.do?person=00002&number=1">李为芳</a><br/>
<a href="/struts-demo/link.do?person=00003&number=2">王微</a><br/>
其中的number是由indexId="number"确定的,而该参数的值为元素在集合中的位置。
-->

html:rewrite标签和html:link标签类似只是不生成锚点(<a>),而是简单的输出字符串。
回页首
html:errors
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. 上面的两段代码示例运行结果相同,如下所示:


html:javascript
html:javascript标签生成用于校验的javascript脚本代码。
下面的代码片段示例了html:javascript标签的基本用法,其中formName属性的值是在validation.xml文件的<formset>中定义的form的名称。有一点值得注意的是在确定<formset>时要使用合适的language属性值。

<html:javascript formName="dataForm"/>


html:xhtml
html:xhtml标签在页面中一出现就是告诉该页的所有其它的Struts html标签以XHTML1.0兼容的形式输出。这和将html:html标签的xhtml属性值指定为true有些类似。如果上述情况都没有出现,Struts html标签将以html4.01兼容的形式输出。
分享到:
评论

相关推荐

    struts标签-手册.chm

    HTML 标签 用来创建能够和Struts 框架和其他相应的HTML 标签交互的HTML 输入表单 Bean 标签 在访问JavaBeans 及其属性,以及定义一个新的bean 时使用 Logic 标签 管理条件产生的输出和对象集产生的循环 ...

    Struts应用开发完全手册(html标签)

    Struts应用开发完全手册(html标签)

    Struts标签手册

    Struts标签的详解,包括中文和英文的查询,有详细例子解释

    Struts1标签手册

    Struts1 标签手册,5类标签库,html,nested,logic,bean,titles

    Struts标签资料(Struts标签大全)

    其中包含Struts标签大全 jsp Struts之HTML标签库详解 struts框架bean,html,logic标签手册等内容。不错,其中的JSP Struts之HTML标签库详解 .doc是朋友总结的。不错!

    struts2 tag 标签手册(2.0全部收录,详细,超值)

    网上struts2的资料很多,不过讲解struts2jsp标签的很少,特定上传一个。基于html格式的,基本是直接翻译过来的,很全很详细,您下了绝对不会后悔。另外在附struts2的中文教程一本,这个网上比较多,顺带上吧。好东西...

    struts2 标签库 帮助文档

    Struts 2 标签库(文档手册) Tags-API-CLSW-JSP &lt;%@ taglib prefix="s" uri="/struts-tags" %&gt; 就能使用struts2.0的标签库 下面就介绍每个标签的具体应用实例说明:按字母排列 A: 1. 2. &lt;s:a href=""&gt;&lt;/s:a&gt;-...

    68个常用开发手册

    struts2标签.chm tomcat5.5中文帮助文档.chm W3CSchool.chm w3school完整版.CHM WebGL自修教程.chm XML+Schema官方教程(9loong中文版)修正版2009.04.chm XmlSchema标准参考手册.chm XPathTutorial.chm 样式表中文...

    各种开发手册大全

    │ struts2标签.chm │ tomcat5.5中文帮助文档.chm │ W3CSchool .chm │ W3CSchool.chm │ w3school完整版.CHM │ WebGL自修教程.chm │ XML+Schema官方教程(9loong中文版)修正版2009.04.chm │ XmlSchema标准...

    有关javaAPI或者手册

    包的内容资源有android手册、html手册、ext中文API、标签修饰手册、hibernate API、J2E API、script手册、spring中文手册、struts手册、w3csc

    仿WebQQ在线桌面版28个html格式帮助文档

    暂时整理了28个常用的帮助手册,列表...19、Struts2标签 20、Yii中文API 21、Zend中文API 22、XMLDOM对象 23、Hibernate中文帮助手册 24、CSS 规范 25、CSS 框架 26、HTML 规范 27、Prototype 28、jquery 1.4帮助手册

    java web帮助手册

    全是一些帮助手册,具体如下: yufa(JSP语法).chm Struts+2.0+API.chm Struts1.3.chm Struts Taglibs.chm ...HTML标签.chm jQueryAPI-100214.chm Spring2.5-中文参考手册.chm plsqldev.chm Linux常用命令全集.CHM

    说明文档2 ASP Java C#

    ASP.NET帮助文档.chm ...struts2.0中文帮助手册.chm struts2-API.chm Struts2与Struts1的对比.chm struts 2.0标签简介.chm Struts Taglibs标签库详解.chm struts+1.3+api.chm 网页制作完全手册.chm

    说明文档7 ASP Java C#

    ASP.NET帮助文档.chm ...struts2.0中文帮助手册.chm struts2-API.chm Struts2与Struts1的对比.chm struts 2.0标签简介.chm Struts Taglibs标签库详解.chm struts+1.3+api.chm 网页制作完全手册.chm

    说明文档8 ASP Java C#

    ASP.NET帮助文档.chm ...struts2.0中文帮助手册.chm struts2-API.chm Struts2与Struts1的对比.chm struts 2.0标签简介.chm Struts Taglibs标签库详解.chm struts+1.3+api.chm 网页制作完全手册.chm

    说明文档4 ASP Java C#

    ASP.NET帮助文档.chm ...struts2.0中文帮助手册.chm struts2-API.chm Struts2与Struts1的对比.chm struts 2.0标签简介.chm Struts Taglibs标签库详解.chm struts+1.3+api.chm 网页制作完全手册.chm

    说明文档1 ASP Java C#

    ASP.NET帮助文档.chm ...struts2.0中文帮助手册.chm struts2-API.chm Struts2与Struts1的对比.chm struts 2.0标签简介.chm Struts Taglibs标签库详解.chm struts+1.3+api.chm 网页制作完全手册.chm

    说明文档3 ASP Java C#

    ASP.NET帮助文档.chm ...struts2.0中文帮助手册.chm struts2-API.chm Struts2与Struts1的对比.chm struts 2.0标签简介.chm Struts Taglibs标签库详解.chm struts+1.3+api.chm 网页制作完全手册.chm

    说明文档6 ASP Java C#

    ASP.NET帮助文档.chm ...struts2.0中文帮助手册.chm struts2-API.chm Struts2与Struts1的对比.chm struts 2.0标签简介.chm Struts Taglibs标签库详解.chm struts+1.3+api.chm 网页制作完全手册.chm

Global site tag (gtag.js) - Google Analytics