Let us see how to work with this
datetimepicker in struts 2, actually no need to add any external
jar files to work with this, some of us may think we need to add some
Ajax related jars bla bla…, let me clear
jars required
- commons-logging-1.0.4.jar
- freemarker-2.3.8.jar
- ognl-2.6.11.jar
- struts2-core-2.0.11.jar
- xwork-2.0.4.jar
Let us see
one example, files
required
- index.jsp
- success.jsp
- web.xml
- struts.xml
- LogingEx.java
Directory Structure
index.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<%@ taglib prefix="s" uri="/struts-tags" %>
<head>
<s:head theme="ajax" debug="true"/>
</head>
<body>
<s:form action="resultAction">
<s:datetimepicker label="Select From" name="toDate" displayFormat="MM-dd-yy" required="true" />
<s:datetimepicker label="Select To" name="fromDate" displayFormat="MM-dd-yy" required="true" />
<s:datetimepicker label="Select Other" name="otherDate" displayFormat="MM-dd-yy" required="true" />
<s:submit value="Click" align="center" />
</s:form>
</body>
|
success.jsp
|
|
<%@ taglib prefix="s" uri="/struts-tags" %>
Entered to date: <s:property value="toDate"/><br>
Entered from date: <s:property value="fromDate"/><br>
Entered other date: <s:property value="otherDate"/><br>
|
LogingEx.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package java4s;
import java.util.Date;
public class LogingEx{
private static final long serialVersionUID = 1L;
private Date toDate;
private Date fromDate;
private Date otherDate;
public Date getToDate() {
return toDate;
}
public void setToDate(Date toDate) {
this.toDate = toDate;
}
public Date getFromDate() {
return fromDate;
}
public void setFromDate(Date fromDate) {
this.fromDate = fromDate;
}
public Date getOtherDate() {
return otherDate;
}
public void setOtherDate(Date otherDate) {
this.otherDate = otherDate;
}
public String execute(){
return "success";
}
}
|
web.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
|
struts.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<?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>
<include file="struts-default.xml"/>
<package name="a" extends="struts-default">
<action name="resultAction" class="java4s.LogingEx">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
|
No comments:
Post a Comment