1.如何使用Strut2标签库的标签?
在JSP页面的源码顶部中加入代码
<%@ taglib uri="/struts-tags" prefix="s" %>
2.标签分类及使用:
(1)属性标签
a)控制标签
- if
- elseif
- else
- append
- generator
- iterator
- merge
- sort
- subset
示例代码:
I. if elseif else
<s:if test="%{false}"> <div>Will Not Be Executed</div> </s:if> <s:elseif test="%{true}"> <div>Will Be Executed</div> </s:elseif> <s:else> <div>Will Not Be Executed</div> </s:else>
II. sort
<!-- 示例1 --> <s:sort comparator="myComparator" source="myList"> <s:iterator> <!-- do something with each sorted elements --> <s:property value="..." /> </s:iterator> </s:sort> <!-- 示例2 --> <s:sort var="mySortedList" comparator="myComparator" source="myList" /> <% Iterator sortedIterator = (Iterator) pageContext.getAttribute("mySortedList"); for (Iterator i = sortedIterator; i.hasNext(); ) { // do something with each of the sorted elements } %>
b)数据标签
- a
- action
- bean
- date
- debug
- i18n
- include
- param
- property
- push
- set
- text
- url
示例代码:
I. a
<s:url var="testUrlId" namespace="/subscriber" action="customField" method="delete"> <s:param name="customFieldDefinition.id" value="${id}"/> </s:url> <s:a errorText="Sorry your request had an error." preInvokeJS="confirm(‘Are you sure you want to delete this item?‘)" href="%{testUrlId}"> <img src="<s:url value="/images/delete.gif"/>" border="none"/> </s:a> <img xsrc="<s:url value="/images/delete.gif"/>" border="none"/><s:a><img xsrc="<s:url value="/images/delete.gif"/>" border="none"/></s:a>
II. bean
<-- in freemarker form --> [@s.bean name="org.apache.struts2.example.counter.SimpleCounter" var="counter"] [s:param name="foo" value="BAR"/] The value of foo is : [s:property value="foo"/], when inside the bean tag.<br /> [/s:bean] <-- in jsp form --> <s:bean name="org.apache.struts2.example.counter.SimpleCounter" var="counter"> <s:param name="foo" value="BAR" /> The value of foot is : <s:property value="foo"/>, when inside the bean tag <br /> </s:bean>
III. i18n
<s:i18n name="myCustomBundle"> The i18n value for key aaa.bbb.ccc in myCustomBundle is <s:property value="text(‘aaa.bbb.ccc‘)" /> </s:i18n>
VI. textfield
<s:textfield name="lastName" label="<s:text name="person.lastName"/>" ../>
(2)UI标签
a)表格标签
- checkbox
- checkboxlist
- combobox
- datetextfield
- doubleselect
- head
- file
- form
- hidden
- inputtransferselect
- label
- optiontransferselect
- optgroup
- password
- radio
- reset
- select
- submit
- textarea
- textfield
- token
- updownselect
b)非表格标签
- actionerror
- actionmessage
- component
- div
- fielderror
c)Ajax标签
- a
- autocompleter
- bind
- datetimepicker
- div
- head
- submit
- tabbedPanel
- textarea
- tree
- treenode
时间: 2024-10-14 06:50:29