日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

struts 2.x版本 datetimepicker日期控件的使用

發(fā)布時間:2024/4/15 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 struts 2.x版本 datetimepicker日期控件的使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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.

The ‘displayFormat‘ attribute is supported in many date patterns, read this article –?Date Format Patterns. Ensure you put the “struts-dojo-tags” tag and render it’s header <sx:head />

<%@ 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日期控件的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。