struts2中用DOJO时间控件dropdowndatepicker

来源:互联网 发布:飞鱼网络电视直播 编辑:程序博客网 时间:2024/05/22 03:31

 

在struts2中集成了对dojo的支持,这里以一个比较常用的日期标签来说明它的使用:
1。把struts2的jar包放入到工程中。
2。在页面头部加入:
<script type="text/javascript">
     // Dojo configuration
     djConfig = {
        baseRelativePath: "struts/dojo",
        isDebug: false,
        bindEncoding: "UTF-8",
        debugAtAllCosts: true // not needed, but allows the Venkman debugger to work with the includes
     };
</script>
<script type="text/javascript" src="struts/dojo/dojo.js"></script>
<script type="text/javascript" src="struts/simple/dojoRequire.js"></script>
3。在需要日期标签的地方加入如下代码:
<div dojoType="dropdowndatepicker" inputName="startDate" dateFormat="%Y年%m月%d日"
 value="${startDate}"  containerToggle="explode" saveFormat="rfc">
</div>
其中的属性dojoType指明widget的类型(全部小写就可以了)。inputName就是生成的input字段的name,提交时候作为表单的一个 参数。dateFormat是日期的格式。weekStartsOn是日历中显示的一周以哪一天开始,这里是以周一开始(0-6,0代表周日)。 adjustWeeks指明是否需要根据每个月的实际天数来调整日历中每月显示的天数(如果不调整,每个月除了自己的天数,还会多出一些相邻月份的天数, 总的天数固定为42天)。如果需要给日期设置一个初始值,可以添加value属性,例如value="2006-10-25"。

下面看完整的例子:

  1. <%@ page contentType="text/html; charset=GBK"%>
  2. <%@ taglib uri="/WEB-INF/struts-bsst.tld" prefix="bsst"%>
  3. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  4. <html>
  5.     <head>
  6.         <script type="text/javascript">
  7.         // Dojo configuration
  8.         djConfig = {
  9.         baseRelativePath: "struts/dojo",
  10.         isDebug: false,
  11.         bindEncoding: "UTF-8",
  12.         debugAtAllCosts: true // not needed, but allows the Venkman debugger to work with the includes
  13.         };
  14.         </script>
  15.         <!-- 引入dojo包 -->
  16.         <script type="text/javascript" src="struts/dojo/dojo.js"></script>
  17.         <script type="text/javascript" src="struts/simple/dojoRequire.js"></script> 
  18.     </head>
  19.     <body>
  20.         <form action="" method="post" name="form1" >
  21.             
  22.                 
  23.                <tr class="MultiColor2">
  24.                    <td align="right">起始时间:</td>
  25.                    <td colspan="2">
  26.                         <div dojoType="dropdowndatepicker" inputName="startDate" dateFormat="%Y年%m月%d日"
  27.                            value="${startDate}"  containerToggle="explode" saveFormat="rfc"></div>
  28.                         <span class="alert"> *</span>
  29.                    </td>
  30.                 </tr>
  31.                 
  32.                 <tr class="MultiColor1">   
  33.                    <td align="right">截至时间:</td>
  34.                     <td colspan="2">          
  35.                         <div dojoType="dropdowndatepicker" inputName="endDate" dateFormat="%Y年%m月%d日"
  36.                            value="${endDate}"  containerToggle="explode" saveFormat="rfc"></div>
  37.                         <span class="alert"> *</span>   
  38.                   </td>
  39.                 </tr>   
  40.     
  41.             </table>
  42.             
  43.         <iframe id="resultFrame" name="resultFrame" style="display:none;"></iframe>
  44.     </body>
  45. </html>
原创粉丝点击