码迷,mamicode.com
首页 > 其他好文 > 详细

Struts2学习之路(七)—— Struts2标签

时间:2015-07-28 17:40:08      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:

1.如何使用Strut2标签库的标签?

在JSP页面的源码顶部中加入代码

<%@ taglib uri="/struts-tags" prefix="s"  %>

2.标签分类及使用:

(1)属性标签

a)控制标签

示例代码:

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)数据标签

示例代码:

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)表格标签

b)非表格标签

c)Ajax标签

 

Struts2学习之路(七)—— Struts2标签

标签:

原文地址:http://www.cnblogs.com/denisechen/p/4683026.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!