Home » struts 2 datetimepicker example

struts 2 datetimepicker example

by Online Tutorials Library

Struts2 DateTimePicker Example

1) Create index.jsp for input

This jsp page creates a form using struts UI tags. It receives name, password and email id from the user.

index.jsp

<%@ taglib prefix="s" uri="/struts-tags" %> <%@ taglib prefix="sx" uri="/struts-dojo-tags" %> <html> <head> <sx:head  /> </head> <body>  <s:form action="DateTimePicker" method="POST"> <sx:datetimepicker name="todayDate" label="Format (yyyy-mm-dd)" displayFormat="yyyy-MM-dd"/> <sx:datetimepicker name="todayDate2" label="Format (dd-mm-yyyy)" displayFormat="dd-MMM-yyyy"/> <s:submit></s:submit> </s:form> </body> </html> 

2) Create the action class

This action class inherits the ActionSupport class and overrides the execute method.

RegisterAction.java

3) Create struts.xml

This xml file defines an extra result by the name input, and an interceptor jsonValidatorWorkflowStack.

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="s" extends="struts-default"> <action name="DateTimePicker" class="mypack.DateBean"> <result>/welcome.jsp</result> </action> </package> </struts>     

4) Create view component

It is the simple jsp file displaying the information of the user.

welcome.jsp

<%@ taglib prefix="s" uri="/struts-tags" %> first date:<s:property value="todayDate" /> second date:<s:property value="todayDate2" /> 

You may also like