Datepicker example in struts2.2.1 framework.
Posted on: January 5, 2011 at 12:00 AM
In this tutorial, you will see how to use date picker in struts2.2.1.

Datepicker example in struts2.2.1 framework.

In this tutorial, we will introduce you to how to implements datepicker in struts2.2.1 frame work. For this we needs an extra jar struts2-dojo-plugin.jar.

Directory structure of datepicker example.

 1- index.html 

<html>ADS_TO_REPLACE_1

<head>

<title>Struts2.2.1 Date Picker Example</title>

</head><body>ADS_TO_REPLACE_2

<hr><h2>Datepicker example in struts2.2.1</h2>

<a href="datepicker.action">Datepicker</a>

</body>ADS_TO_REPLACE_3

</html>

2-DatePickerAction.java

package roseindia;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.opensymphony.xwork2.ActionSupport;

public class DatePickerAction extends ActionSupport {

private Date date1;
public Date getDate1() {
return date1;
}
public void setDate1(Date date1) {
this.date1 = date1;
}
public Date getToday() {
return new Date();
}
public String execute() throws Exception {
return SUCCESS;
}
public String display() {
return NONE;
}
}

2-datepicker.jsp

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

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

<html>

<head><sd:head/><title>Struts2.2.1 Date Picker Example</title>ADS_TO_REPLACE_5

</head><body>

<h4>Example of Struts date picker in struts2.2.1</h4>

<s:form action="resultAction.action" method="post">ADS_TO_REPLACE_6

<sd:datetimepicker name="date1"

displayFormat="yyyy-MM-dd"

value="today"ADS_TO_REPLACE_7

label="Select Date(yyyy-mm-dd):"/>

<s:submit></s:submit></s:form>

</body></html>

4_struts.xml

<constant name="struts.enable.DynamicMethodInvocation" value="false" />ADS_TO_REPLACE_8

<constant name="struts.devMode" value="false" />

<package name="roseindia" extends="struts-default" >

<action name="datepicker" class="roseindia.DatePickerAction" method="display">ADS_TO_REPLACE_9

<result name="none">/jsp/datepicker.jsp</result>

</action>

<action name="resultAction" class="roseindia.DatePickerAction" >ADS_TO_REPLACE_10

<result name="success">jsp/result.jsp</result>

</action>

</package>ADS_TO_REPLACE_11

 

3-result.jsp

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

<html>ADS_TO_REPLACE_12

<head><title>Struts2.2.1 Date Picker Example</title>

</head><body>

<h4>Example of Struts date picker in struts2.2.1</h4>ADS_TO_REPLACE_13

Date :

<s:date name="date1" format="EEEE dd/MM/yyyy " />

</body></html>

 

index.htmlADS_TO_REPLACE_14

datepicker.jsp

ADS_TO_REPLACE_15

datepicker.jsp

Result.jspADS_TO_REPLACE_16

Download Select Source Code


Related Tags for Datepicker example in struts2.2.1 framework.:

Advertisements

Ads

 
Advertisement null

Ads