struts2 标签初识 Form Tags

1: <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
2: <%@ taglib prefix="s" uri="/struts-tags" %>
3: <%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
4:
5: <html>
6: <head>
7:     <title>UI Tags Example</title>
8:     <sx:head/>
9: </head>
10:
11: <body>
12:
13: <s:actionerror/>
14: <s:actionmessage/>
15: <s:fielderror />
16:
17:
18: <s:form action="exampleSubmit" enctype="multipart/form-data" javascriptTooltip="true">
19:     <s:textfield
20:             label="Name"
21:             name="name"
22:             tooltip="Enter your Name here"/>
23: <!--String-->
24:     <sx:datetimepicker
25:             tooltip="Select Your Birthday"
26:             label="Birthday"
27:             name="birthday" />
28:  <!--Date-->
29:     <sx:datetimepicker
30:             tooltip="Enter the time you wake up"
31:             label="Wake up time"
32:             name="wakeup"
33:             type="time"/>
34:  <!--Date-->
35:     <s:textarea
36:             tooltip="Enter your Biography"
37:             label="Biography"
38:             name="bio"
39:             cols="20"
40:             rows="3"/>
41: <!--String-->
42:     <s:select
43:             tooltip="Choose Your Favourite Color"
44:             label="Favorite Color"
45:             list="{'Red', 'Blue', 'Green'}"
46:             name="favouriteColor"
47:             emptyOption="true"
48:             headerKey="None"
49:             headerValue="None"/>
50: <!--String-->

51:     <s:select
52:             tooltip="Choose Your Favourite Language"
53:             label="Favourite Language"
54:             list="favouriteLanguages"
55:             name="favouriteLanguage"
56:             listKey="key"
57:             listValue="description"
58:             emptyOption="true"
59:             headerKey="None"
60:             headerValue="None"/>
61: <!--List-->

62:     <s:checkboxlist
63:             tooltip="Choose your Friends"
64:             label="Friends"
65:             list="{'Patrick', 'Jason', 'Jay', 'Toby', 'Rene'}"
66:             name="friends"/>
67: <!--List-->

68:     <s:checkbox
69:             tooltip="Confirmed that your are Over 18"
70:             label="Age 18+"
71:             name="legalAge"/>
72: <!--boolean-->

73:     <s:doubleselect
74:             tooltip="Choose Your State"
75:             label="State"
76:             name="region" list="{'North', 'South'}"
77:             value="'South'"
78:             doubleValue="'Florida'"
79:             doubleList="top == 'North' ? {'Oregon', 'Washington'} : {'Texas', 'Florida'}"
80:             doubleName="state"
81:             headerKey="-1"
82:             headerValue="---------- Please Select ----------"
83:             emptyOption="true" />
84: <!--String-->

85:     <s:doubleselect
86:             tooltip="Choose your Vehical"
87:             label="Favourite Vehical"
88:             name="favouriteVehicalType"
89:             list="vehicalTypeList"
90:             listKey="key"
91:             listValue="description"
92:             value="'MotorcycleKey'"
93:             doubleValue="'YamahaKey'"
94:             doubleList="vehicalSpecificList"
95:             doubleListKey="key"
96:             doubleListValue="description"
97:             doubleName="favouriteVehicalSpecific" headerKey="-1"
98:             headerValue="---------- Please Select ----------"
99:             emptyOption="true" />
100: <!--String-->

101:     <s:file
102:             tooltip="Upload Your Picture"
103:             label="Picture"
104:             name="picture" />
105: <!--File-->

106:     <s:optiontransferselect
107:             tooltip="Select Your Favourite Cartoon Characters"
108:             label="Favourite Cartoons Characters"
109:             name="leftSideCartoonCharacters"
110:             leftTitle="Left Title"
111:             rightTitle="Right Title"
112:             list="{'Popeye', 'He-Man', 'Spiderman'}"
113:             multiple="true"
114:             headerKey="headerKey"
115:             headerValue="--- Please Select ---"
116:             emptyOption="true"
117:             doubleList="{'Superman', 'Mickey Mouse', 'Donald Duck'}"
118:             doubleName="rightSideCartoonCharacters"
119:             doubleHeaderKey="doubleHeaderKey"
120:             doubleHeaderValue="--- Please Select ---"
121:             doubleEmptyOption="true"
122:             doubleMultiple="true" />
123: <!--List-->

124:     <s:textarea
125:             label="Your Thougths"
126:             name="thoughts"
127:             tooltip="Enter your thoughts here" />
128: <!--thoughts-->

129:     <s:submit />
130:     <s:reset οnclick="alert('Resetting form now... Press OK to continue!');" />
131: </s:form>
132:
133: </body>
134: </html>

 <h4>

2、combobox
 <s:combobox label="What's your favor fruit"
headerKey="-1" headerValue="--- Select ---"
list="fruits"
name="yourFruits" />

<!--List<String>-->
</h4>
 
<h4>
<s:combobox label="Select a month"
headerKey="-1" headerValue="--- Select ---"
list="#{'1':'Jan', '2':'Feb', '3':'Mar', '4':'Apr'}"
name="yourMonth" />
</h4>
3、head

<head>
<s:head />
</head>
<head>
</head>
<body>
<s:head />
...
4、s:hidden 
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>
 
<body>
<h1>Struts 2 - hidden value example</h1>
 
<s:form action="helloHidden" namespace="/">
 
	<h4>This page has a hidden value (view source): 
	<s:hidden name="url" value="http://www.mkyong.com" /></h4> 
 
	<s:submit value="submit" name="submit" />
 
</s:form>
 
</body>
</html>
5、label
<s:label key="userName" />
6、optgroup
<s:select label="My Selection"
           name="mySelection"
           value="%{'POPEYE'}"
           list="%{#{'SUPERMAN':'Superman', 'SPIDERMAN':'spiderman'}}">
   <s:optgroup label="Adult"
                list="%{#{'SOUTH_PARK':'South Park'}}" />
   <s:optgroup label="Japanese"
                list="%{#{'POKEMON':'pokemon','DIGIMON':'digimon','SAILORMOON':'Sailormoon'}}" />
</s:select>
7、radio
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>
 
<body>
<h1>Struts 2 radio button example</h1>
 
<s:form action="resultAction" namespace="/">
 
<h4>
  <s:radio label="Gender" name="yourGender" list="genders" value="defaultGenderValue" /><!--genders List<String>-->
  <s:radio label="Gender" name="yourLanguage" list="languages" 
      listKey="languageCode" listValue="languageDisplay" value="defaultLanguageValue" /><!--List<Language> languages -->
  <s:radio label="Answer" name="yourAnswer" list="#{'1':'Yes','2':'No'}" value="2" />
</h4> 
 
<s:submit value="submit" name="submit" />
 
</s:form>
 
</body>
</html>
8、reset


   
   
Render an button reset:
<s:reset label="My Selection" type="button" key="reset"/>
9、submit
<s:submit name="save" value="保存" align="left" method="save"/>
<s:submit name="print" value="打印" align="left" method="print" />         
10、token
<s:reset value="Reset" />
        <action name="transfer" class="org.apache.struts2.showcase.token.TokenAction">
            <interceptor-ref name="defaultStack"/>
            <interceptor-ref name="token"/>
            <result name="invalid.token">doublePost.jsp</result>
            <result name="success">transferDone.jsp</result>
        </action>
1: <%@ taglib prefix="s" uri="/struts-tags" %>
2: <html>
3:     <head><title>Token Examples</title></head>
4: 
5: <body>
6:     <h1>Token Example 1</h1>
7: 
8:     <b>Example 1:</b> This example illustrates a situation where you can transfer money from
9:     one account to another. We use the token to prevent double posts so the transfer only
10:     happens once.
11:     <p/>
12: 
13:     <br/>Balance of source account: <s:property value="#session.balanceSource"/>
14:     <br/>Balance of destination account: <s:property value="#session.balanceDestination"/>
15:     <p/>
16: 
17:     <s:form action="transfer">
18:         <s:token/>
19:         <s:textfield label="Amount" name="amount" required="true" value="100"/>
20:         <s:submit value="Transfer money"/>
21:     </s:form>
22: 
23: </body>
24: </html>
token用于避免重复提交<result name="invalid.token">doublePost.jsp</result>重复提交时显示这个页面
11、updownselect
<!-- Example 1: simple example -->
<s:updownselect
list="#{'england':'England', 'america':'America', 'germany':'Germany'}"
name="prioritisedFavouriteCountries"
headerKey="-1"
headerValue="--- Please Order Them Accordingly ---"
emptyOption="true" />

12:     <s:updownselect
13:         tooltip="Prioritized Your Favourite Cartoon Characters"
14:         label="Prioritised Favourite Cartoon Characters"
15:         list="defaultFavouriteCartoonCharacters" 
16:         name="prioritisedFavouriteCartoonCharacters" 
17:         headerKey="-1" 
18:         headerValue="--- Please Order ---" 
19:         emptyOption="true"  />
42:     public Map getDefaultFavouriteCartoonCharacters() {
43:         Map m = new LinkedHashMap();
44:         m.put("heMan", "He-Man");
45:         m.put("popeye", "Popeye");
46:         m.put("mockeyMouse", "Mickey Mouse");
47:         return m;
48:     }
80:     public List getPrioritisedFavouriteCartoonCharacters() {
81:         return _prioritisedFavouriteCartoonCharacters;
82:     }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值