Datetimepicker tag in struts2 framework

Datetimepicker tag in struts2 framework

Previous Home Next

 

Struts2 framework provide datetimepicker component to select date and its format and submit. 
Download the struts2-dojo-plugin.jar library and Include the “struts-dojo-tags” tag and output its header.
Struts2 tag library provide datetimepicker component to select date and its format.
<sx:datetimepicker name="mydate1" label="Format (dd-MMM-yyyy)" displayFormat="dd-MMM-yyyy" value="todayDate" />

 
Directory Structure of <s:datetimepicker> tag Example in Struts 2.0 Using MyEclipse IDE



index.jsp

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

<h1>Datetimepicker Tag Example in Struts2 Framework</h1>
 
<s:form action="date" method="POST" >

<sx:datetimepicker name="mydate1" label="Format (dd-MMM-yyyy)" 
displayFormat="dd-MMM-yyyy" value="todayDate" />
 
<sx:datetimepicker name="mydate2" label="Format (dd-MMM-yyyy)" 
displayFormat="dd-MMM-yyyy" value="%{'2011-06-08'}"/>
 
<sx:datetimepicker name="mydate3" label="Format (dd-MMM-yyyy)" 
displayFormat="dd-MMM-yyyy" value="%{'today'}"/>
 
<s:submit value="submit" name="submit" />
</s:form>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  
  <filter>
  <filter-name>f1</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>f1</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration
2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="demo" extends="struts-default">
<action name="" class="org.r4r.DatetimepickerAction" method="display">
<result name="none" type="dispatcher">/index.jsp</result>
</action>
<action name="date" class="org.r4r.DatetimepickerAction">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>

DatetimepickerAction.java

package org.r4r;
import java.util.Date;

public class DatetimepickerAction {
	Date mydate1;
	Date mydate2;
	Date mydate3;
	
	public Date getTodayDate(){
		return new Date();
	}
	public String execute(){
		return "success";
	}
	public String display(){
		return "none";
	}
	public Date getMydate1() {
		return mydate1;
	}
	public void setMydate1(Date mydate1) {
		this.mydate1 = mydate1;
	}
	public Date getMydate2() {
		return mydate2;
	}
	public void setMydate2(Date mydate2) {
		this.mydate2 = mydate2;
	}
	public Date getMydate3() {
		return mydate3;
	}
	public void setMydate3(Date mydate3) {
		this.mydate3 = mydate3;
	}
}

success.jsp

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

<h1>Datetimepicker Tag Example in Struts2 Framework</h1>
<h4>Date1 : <s:property value="mydate1"/></h4> 
<h4>Date 2 : <s:property value="mydate2"/></h4> 
<h4>Date 3 : <s:property value="mydate3"/></h4> 

Output






Previous Home Next