我有一个页面 index.jsp
,我在这个 jsp 中使用了 struts2-jquery tabbedpannel 标签来显示另外两个 JSP(first.jsp
& second.jsp
) 作为选项卡。
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<sj:head />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Index Page</title>
</head>
<body>
<sj:tabbedpanel
id="remotetabs"
selectedTab="0"
show="true"
hide="'fade'"
collapsible="true"
sortable="true">
<sj:tab id="tab1" href="first.jsp" label="First JSP"/>
<sj:tab id="tab2" href="second.jsp" label="Second JSP"/>
</sj:tabbedpanel>
</body>
</html>
另外两个 JSP 包含一个表单,每个表单都带有 struts2-datepicker 标记。这是其中之一......
first.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<link rel="stylesheet" type="text/css" href="css/view.css" media="all">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>First JSP</title>
</head>
<body>
<div>
<s:form action="firstAction" >
<sj:datepicker
key="timeStamp"
name="timeStamp"
label="Time Stamp"
timepicker="true"
displayFormat="yy-mm-dd"
timepickerFormat="HH:mm"/>
<s:submit value="Submit"></s:submit>
</s:form>
</div>
</body>
</html>
问题是,第一次加载 index.jsp
时,first.jsp 上的 struts2-jquery datepicker 标签工作正常,但当我切换到第二个标签时;这将在 AJAX 中加载 second.jsp
(second.jsp 包含与 first.jsp 相同的代码) second.jsp
上的 struts2-jquery datepicker 标签不起作用。
现在,当我切换回第一个选项卡以显示 first.jsp
时,struts2-jquery datepicker 标记也不起作用。它只是在第一次加载后停止工作。
最佳答案
问题是您正在调用 JSP 页面,而您应该调用 Struts2 Actions。
Struts2 是 MVC。您不应从 View 调用 View ,而应调用将分派(dispatch)到 View 的 Controller 。
第一次,它起作用了,因为 first.jsp
和 second.jsp
中的 struts 和 struts-jquery 标签的变量取自 IndexAction
.
您应该改为定义 FirstAction
和 SecondAction
并在 href
属性中通过 AJAX 调用它们:
<s:url var="firstActionUrl" action="first" namespace="/" />
<sj:tab id="tab1" href="%{#firstActionUrl}" label="First JSP"/>
<s:url var="secondActionUrl" action="second" namespace="/" />
<sj:tab id="tab2" href="%{#secondActionUrl}" label="Second JSP"/>
关于javascript - struts2-jquery datepicker 标签未加载到 struts2-jquery tabbedpannel 标签中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31017854/