http://www.blogjava.net/bulktree/archive/2008/01/04/172859.html
这些都是Struts2的一些新标签,感觉很新鲜,特别是datetimedipacker标志感觉很好
filevalidateExample.jsp 文件
<%@ page language="java" c
pageEncoding="ISO-8859-5"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>fieldValidatorsExample test</title>
<s:url id="siteCss" includeC
value="/validationExamplesStyles.css" />
<s:head theme="xhtml" />
</head>
<body>
<h3>All field Error will show</h3>
<s:fielderror />
<hr color="red" />
<s:form action="fieldValidators" method="post">
<s:textfield tooltip="ENTER YOUR NAME" label="YOUR NAME" name="name" />
<s:textfield tooltip="ENTER YOUR AGE" label="YOUR AGE" name="age" />
<s:datetimepicker tooltip="ENTER YOUR BIRTHDAY" label="YOUR BIRTHDAY"
name="birthday" />
<s:textfield tooltip="ENTER YOUR EMAIL" label="YOUR EMAIL" name="Email" />
<s:textfield tooltip="ENTER YOUR URL" label="YOUR URL" name="url" />
<s:select tooltip="SELECT YOUR PROGRAM" label="YOUR PROGRAM"
name="program" list="{'Java','.net','C#','Struts2'}" />
<s:checkboxlist tooltip="SELECT YOUR FAVOURITE COLOR"
label="FAVOURITE COLOR" name="color"
list="{'red','green','yellow','pink','blue'}" value="{'green','blue'}" />
<s:tree label="parent" id="parentId" theme="ajax"
templateCssPath="/struts/tree.css" showRootGrid="true" showGrid="true">
<s:treenode theme="ajax" label="child1" id="child1Id">
<s:treenode theme="ajax" label="grandchild1" id="grandchild1Id" />
<s:treenode theme="ajax" label="grandchild2" id="grandchild2Id" />
<s:treenode theme="ajax" label="grandchild3" id="grandchild3Id" />
</s:treenode>
<s:treenode theme="ajax" label="child2" id="child2Id" />
<s:treenode theme="ajax" label="child3" id="child3Id" />
<s:treenode theme="ajax" label="child4" id="child4Id" />
<s:treenode theme="ajax" label="child5" id="child5Id">
<s:treenode theme="ajax" label="gChild1" id="gChild1Id" />
<s:treenode theme="ajax" label="gChild2" id="gChild2Id" />
</s:treenode>
</s:tree>
<s:hidden name="hiddenName" value="bulktree and oakertree" />
<s:submit label="SUBMIT" />
</s:form>
</body>
</html>
FileValidateAction.java文件
package com.bulktree.struts2;
import java.util.Date;
import com.opensymphony.xwork2.ActionSupport;
public class FieldValidatorsAction extends ActionSupport {
private String name = null;
private Integer age = null;
private Date birthday = null;
private String Email = null;
private String url = null;
private String program = null;
private String color = null;
private String hiddenName = null;
private String child2 = null;
public String getChild2() {
return child2;
}
public void setChild2(String child2) {
this.child2 = child2;
}
public String getHiddenName() {
return hiddenName;
}
public void setHiddenName(String hiddenName) {
this.hiddenName = hiddenName;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getProgram() {
return program;
}
public void setProgram(String program) {
System.out.println("*****setProgram**********");
this.program = program;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getEmail() {
return Email;
}
public void setEmail(String email) {
Email = email;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Override
public String execute() throws Exception {
return SUCCESS;
}
@Override
public void validate() {
}
}
struts.xml配置片段
<action name="fieldValidators"
class="com.bulktree.struts2.FieldValidatorsAction">
<result>/welcome.jsp</result>
</action>
welcome.jsp显示页面
<%@ page language="java" c
pageEncoding="GB2312"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!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" c>
<title>login</title>
</head>
<body>
YOUR USERNAME:
<FONT size="5" color="red"><s:property value="username" /></FONT>
<br>
YOUR PASSWORD:
<FONT size="5" color="red"><s:property value="password" /></FONT>
<br>
YOUR USERNAME:
<FONT size="5" color="red"><s:property value="user.username" /></FONT>
<br>
YOUR PASSWORD:
<FONT size="5" color="red"><s:property value="user.password" /></FONT>
<br>
YOUR NAME:
<FONT size="5" color="red"><s:property value="name" /></FONT>
<br>
YOUR AGE:
<FONT size="5" color="red"><s:property value="age" /></FONT>
<br>
YOUR BIRTHDAY:
<FONT size="5" color="red"><s:property value="birthday" /></FONT>
<br>
YOUR EMAIL:
<FONT size="5" color="red"><s:property value="Email" /></FONT>
<br>
YOUR URL:
<FONT size="5" color="red"><s:property value="url" /></FONT>
<br>
YOUR PROGARAM:
<FONT size="5" color="red"><s:property value="program" /></FONT>
<br>
YOUR FAVOURITE COLOR:
<FONT size="5" color="red"><s:property value="color" /></FONT>
<br>
YOUR HIDDEN NAME
<FONT size="5" color="red"><s:property value="hiddenName" /></FONT>
<br>
TREE:
<s:property value="child2" />
</body>
</html>