Reputation: 569
I want to use jQuery datepicker in my Struts app
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>My First JQuery Page</title>
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="css/mytestcss.css">
<script src="/js/jquery-1.11.1.js"></script>
<script src="/js/jquery-ui.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<div id="formdiv">
<s:form>
<s:textfield label="username" name="username" ></s:textfield>
<s:password label="password" name="password" ></s:password>
<s:textfield label="date" id="datepicker" name="date"></s:textfield>
</s:form>
</div>
<input type="text" id="datepicker">
</body>
</html>
Did I miss anything? Why datepicker is not loading?
Upvotes: -1
Views: 645
Reputation: 569
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>My First JQuery Page</title>
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="css/mytestcss.css">
<script src="js/jquery-1.11.1.js"></script>
<script src="js/jquery-ui.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<div id="formdiv">
<s:form>
<s:textfield label="username" name="username" ></s:textfield>
<s:password label="password" name="password" ></s:password>
<s:textfield label="date" id="datepicker" name="date"></s:textfield>
</s:form>
</div>
</body>
</html>
The .js file was not loaded ,because of /js/jquery-1.11.1.js i changed it to js/jquery-1.11.1.js (removed '/')
Upvotes: 1
Reputation: 1
You can use s:url
tag to build correct path
<script src="<s:url value='/js/jquery-1.11.1.js'/>"></script>
JSTL c:url
tag works similar
<script src="<c:url value='/js/jquery-1.11.1.js'/>"></script>
or use JSP EL
<script src="${pageContext.request.contextPath}/js/jquery-1.11.1.js"></script>
Upvotes: 1
Reputation: 627
You should use document ready event to be sure your element is rendered
Try using this:
$(document).ready(function() {
$( "#datepicker" ).datepicker();
});
Upvotes: 0