private boolean one = false;
private boolean two = false;
private boolean three = false;
One
Two
Three
如果选中后被提交则相应的属性的值为true。 回页首
html:radio
html:radio标签生成一个radio。主要的用法有两种,下面我们通过代码来示例。
下面的代码示例了html:radio标签的一般用法,如果被提交则选中的radio的value值将被提交到radioForm中的id中。
One
Two
下面的代码示例了html:radio标签的典型用法,其中的persons和bean:define标签中的一致,您可以参考bean:define标签。我只介绍这个,idName指定html:radio要使用的bean(这里为person),value="id"表示person的id属性将作为radio元素的value值而property="id"表示提交时选中的radio的值将被提交给radioForm中的id属性。
下面我们以代码示例来说明每一种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 persons = new ArrayList();
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");
}
Go Top
单参单值
多参单值
单参多值
混合
下面的代码示例了html:link标签的indexed属性和indexId属性的用法,这两个属性只有html:link标签嵌套在logic:iterate标签中时才可用。
person
赵辰
李为芳
王微
其中的number是由indexId="number"确定的,而该参数的值为元素在集合中的位置。
-->
html:rewrite标签和html:link标签类似只是不生成锚点(),而是简单的输出字符串。 回页首
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=
errors.prefix=
errors.suffix=
errors.footer=
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标签代码示例: