struts 2.x版本 datetimepicker日期控件的使用
In Struts 2, the dojo ajax tag “<sx:datetimepicker>” will render a text box and append a calender icon behind, click on the calender icon will prompt a date time picker component.
To create a date time pick component, just ensure :
1. Download the struts2-dojo-plugin.jar library.
2. Include the “struts-dojo-tags” tag and output its header.
开始时把struts2-dojo-plugin.jar包导入到项目WEB-INF/libx下
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
<html>
<head>
<sx:head />
</head>
For example,
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
<html>
<head>
<sx:head />
</head>
<body>
<sx:datetimepicker name="date2" label="Format (dd-MMM-yyyy)"
displayFormat="dd-MMM-yyyy" value="%{'2010-01-01'}"/>
...
Resulting the following HTML, few dojo and JavaScript libraries to create a date time pick component.
<html>
<head>
<script language="JavaScript" type="text/javascript"> // Dojo configurationdjConfig = {isDebug: false,bindEncoding: "UTF-8",baseRelativePath: "/Struts2Example/struts/dojo/",baseScriptUri: "/Struts2Example/struts/dojo/",parseWidgets : false};
</script>
<script language="JavaScript" type="text/javascript"
src="/Struts2Example/struts/dojo/struts_dojo.js"></script> <script language="JavaScript" type="text/javascript"
src="/Struts2Example/struts/ajax/dojoRequire.js"></script> <link rel="stylesheet" href="/Struts2Example/struts/xhtml/styles.css" type="text/css"/> <script language="JavaScript" src="/Struts2Example/struts/utils.js"
type="text/javascript"></script> <script language="JavaScript" src="/Struts2Example/struts/xhtml/validation.js"
type="text/javascript"></script> <script language="JavaScript" src="/Struts2Example/struts/css_xhtml/validation.js"
type="text/javascript"></script>
</head>
...
<td class="tdLabel">
<label for="widget_1291193434" class="label">Format (dd-MMM-yyyy):
</label></td>
<td>
<div dojoType="struts:StrutsDatePicker" id="widget_1291193434"
value="2010-01-01" name="date2" inputName="dojo.date2"
displayFormat="dd-MMM-yyyy" saveFormat="rfc"></div>
</td>
</tr>
<script language="JavaScript" type="text/javascript">
djConfig.searchIds.push("widget_1291193434");</script>
Struts 2 <S:datetimepicker> Example
A complete full example of the <s:datetimepicker> tag to generate a datetimepicker component, and show the use of OGNL and Java property to set the default date to the “datetimepicker” component.
1. Pom.Xml
Download the Struts 2 dojo dependency libraries.
pom.xml
//...<!-- Struts 2 --><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-core</artifactId><version>2.1.8</version></dependency><!-- Struts 2 Dojo Ajax Tags --><dependency><groupId>org.apache.struts</groupId><artifactId>struts2-dojo-plugin</artifactId><version>2.1.8</version></dependency> //...
2. Action Class
Action class to store the selected date.
DateTimePickerAction.java
package com.mkyong.common.action;import java.util.Date;
import com.opensymphony.xwork2.ActionSupport;public class DateTimePickerAction extends ActionSupport{private Date date1;private Date date2;private Date date3;//return today datepublic Date getTodayDate(){return new Date();}//getter and setter methodspublic String execute() throws Exception{return SUCCESS;}public String display() {return NONE;}}
3. Result Page
Render the date time picker component via “<s:datetimepicker>” tag, set the default date via Java property and OGNL.
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
<html>
<head>
<sx:head />
</head>
datetimepicker.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
<html>
<head>
<sx:head />
</head><body>
<h1>Struts 2 datetimepicker example</h1><s:form action="resultAction" namespace="/" method="POST" ><sx:datetimepicker name="date1" label="Format (dd-MMM-yyyy)"
displayFormat="dd-MMM-yyyy" value="todayDate" /><sx:datetimepicker name="date2" label="Format (dd-MMM-yyyy)"
displayFormat="dd-MMM-yyyy" value="%{'2010-01-01'}"/><sx:datetimepicker name="date3" label="Format (dd-MMM-yyyy)"
displayFormat="dd-MMM-yyyy" value="%{'today'}"/><s:submit value="submit" name="submit" /></s:form></body>
</html>
result.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<html><body>
<h1>Struts 2 datetimepicker example</h1><h4>Date1 : <s:property value="date1"/>
</h4> <h4>Date 2 : <s:property value="date2"/>
</h4> <h4>Date 3 : <s:property value="date3"/>
</h4> </body>
</html>
3. Struts.Xml
Link it all ~
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts><constant name="struts.devMode" value="true" /><package name="default" namespace="/" extends="struts-default"><action name="dateTimePickerAction" class="com.mkyong.common.action.DateTimePickerAction" method="display"><result name="none">pages/datetimepicker.jsp</result></action><action name="resultAction" class="com.mkyong.common.action.DateTimePickerAction" ><result name="success">pages/result.jsp</result></action> </package></struts>
4. Demo
http://localhost:8080/Struts2Example/dateTimePickerAction.action
struts 2.x版本 datetimepicker日期控件的使用相关推荐
- Bootstrap中datetimepicker日期控件1899年问题解决
@加粗样式TOC Bootstrap中datetimepicker日期控件1899年问题解决 Bootstrap中datetimepicker日期控件1899年问题解决 最近在开发项目的过程中,遇到一 ...
- winform 位置不空 隐藏控件_C#winform窗体点击TextBox控件,显示DateTimePicker日历控件,并获得日期值(可实现对日期赋空值)...
由于DateTimePicker不能赋空值,用此方法可以置默认日期值为空 步骤如下: 新建项目,个人用到vs2010 文件->新建->项目,选择windows窗体应用程序 2.拖控件,将T ...
- MFC日期控件(DateTimePicker)
引用一个DateTimePicker控件,关联变量m_date为DateTimeCtrl类型: 1. 获取日期控件 CTime date; m_date.GetTime(data); //就可以获得日 ...
- bootstrap日期控件 只显示 年月
<!DOCTYPE html> <html lang="zh" xmlns:th="http://www.thymeleaf.org" > ...
- Wdatepicker日期控件的使用指南
示例2-3-1 起始日期简单应用 示例2-3-2 alwaysUseStartDate属性应用 示例2-3-3 使用内置参数 示例 2-4-1: 年月日时分秒 示例 2-4-2 时分秒 示例 2-4- ...
- 精确到秒的JQuery日期控件,jquery日历插件,jquery日期插件
2019独角兽企业重金招聘Python工程师标准>>> 效果图如下: 首先在页面中引用一下库: <link type="text/css" href=&qu ...
- 2.0版本的日历控件在ie8显示不全的解决办法
如果用 2.1版本的话 IE8下显示如右图 但在ie6.ie7和chrome等浏览器下显示都正常. 解决方法是: 重写一下DateField控件 1 /* 2011-03-04 cx 2 修正日期控件 ...
- 机房系统(八)——【日期控件DTPicker、比较日期大小】
"宁可让程序(员)多干活,也不能让用户多做".本着为用户着想.给用户以方便的原则,系统中用选代替填,给用户减少很多不必要的麻烦. 在机房系统里遇到了填写日期的问题.VB中已 ...
- bootstrop 日期控件 datepicker被弹出框dialog覆盖的解决办法
筒子们在使用bootstrap的日期控件(datepicker , 现在官网提供的名称叫 datetimepicker)时可能会遇到如上图的问题这是啥原因造成的呢? 答案很简单时输出的优先级造成的(z ...
最新文章
- 漫画:如何螺旋遍历二维数组?
- 利用iptables来配置linux禁止所有端口登陆和开放指定端口
- Retina时代的前端视觉优化
- 错误记录:expected single matching bean but found 2
- 二十二.香港大学火星实验室R3LIVE框架跑官方数据集
- linux扫描硬盘故障命令
- linux 进程 cpu 100,清理linux中占用CPU 100%的病毒
- H3C数通 H3CNE H3CSE 资料下载 肖哥视频下载
- L298N——简介及用法
- Matlab将底色改为白色
- 微信小程序音乐播放器系统app毕业设计
- 成功解决 nginx: [emerg] invalid number of arguments in “root“ directive in 问题
- PLC通讯实现-C#实现西门子PLC以太网通讯Sharp7(六)
- 智芯传感微差压气体压力传感器成功入围第三届“SIA感知领航优秀项目征集”年度杰出产品及技术成长型企业组
- signature=d363d26bda212f777fef81d270ecd42b,基于DNA-pooling全基因组重测序初步筛查CAD易感基因变异位点...
- GStreamer基础教程10——GStreamer工具
- 上市企业统计面板数据集(2011-2020年)
- NoSql之Redis系列一: Redis的数据类型和基本使用
- Oracle(三)--数据库建表操作
- Genome Research | 呼吸疾病国家重点实验室华大研究院合作解析新冠轻重症患者血浆cfRNA特征谱...
热门文章
- 经营为什么需要哲学(学习总结)
- Print out Android kernel log
- 利用 WebService实现远程服务器文件的上传和下载
- effective C++ 读书笔记(0-2)
- 如何批量删除QQ浏览器指定历史记录和导出指定的历史记录
- 消息推送与同步协议的思考
- 点击链接,执行.py脚本,cgi脚本,浏览器中没有显示解析后的web页面,而是.py文件本身的代码内容...
- Java中常见数据结构:list与map
- 通过 ANE(Adobe Native Extension) 启动Andriod服务 推送消息(二)
- 安卓工业平板电脑的蓝牙开发教程