我的ajax生成表单的targets属性似乎不起作用。我似乎也无法从这种形式发表主题。我有以下页面:
<!Doctype html, taglibs, etc here !-->
<html>
<head>
<s:head theme="css_xhtml" />
<sj:head jqueryui="true" />
<script type="text/javascript">
$.subscribe('testtopic', function(event, data) {
alert('testtopic Published!');
});
</script>
<title>Exam CRUD</title>
</head>
<s:url namespace="/exam" action="ReadAll" var="readExamsTag" />
<body>
<s:include value="/WEB-INF/content/navigation.jsp" />
<h2>Exam CRUD</h2>
<sj:div id="formcontainer"></sj:div>
<sj:div id="tablecontainer" loadingText="Loading.."
reloadTopics="reloadTable" href="%{readExamsTag}">
</sj:div>
</body>
</html>
ReadAll将以下jsp加载到“tablecontainer”div:
<s:url namespace="/exam" action="CreateForm" var="createFormTag" />
<p>
Listed below are the exams currently available to students.
<sj:a href="%{createFormTag}" targets="formcontainer">Add an exam</sj:a>
<!The above anchor works perfectly fine. It loads the form into the div as expeceted>
</p>
<table>
<! Table contents over here >
</table>
%{createFormTag}加载到“formcontainer”onclick的表单:
<sj:head />
<s:form theme="css_xhtml" namespace="/exam" action="Create">
<!Form fields>
<input type="button" value="Cancel" onclick="$('#formcontainer').empty();">
<sj:submit targets="formcontainer" onCompleteTopics="reloadTable" value="Add" />
</s:form>
<sj:a href="#" onClickTopics="testtopic">Test</sj:a>
我面临的问题来自上述形式。目标属性不起作用,在提交此表单时,它会将结果加载到新页面中。我还想测试是否可以发布主题,所以我在表单的末尾添加了锚点。当表单加载到页面时单击此锚点不会执行任何操作。 “取消”按钮似乎工作正常,加载此表单的初始锚也是如此,为什么不是表单?
编辑:修正了..
我不确定为什么会这样,必须与css_xhtml模板有关。我通过在表单中添加id属性来修复targets属性。
至于修复发布,我在表单中的datepicker字段中添加了一个id属性,现在一切正常。奇怪的.. 最终代码: crud.jsp:
<!DOCTYPE html>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<s:head theme="css_xhtml" />
<sj:head jqueryui="true"/>
<title>Exam CRUD</title>
</head>
<s:url namespace="/exam" action="ReadAll" var="readExamsTag" />
<body>
<s:include value="/WEB-INF/content/navigation.jsp" />
<h2>Exam CRUD</h2>
<sj:div id="formcontainer"></sj:div>
<sj:div id="tablecontainer" loadingText="Loading.."
reloadTopics="reloadTable" href="%{readExamsTag}">
</sj:div>
</body>
</html>
add.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"%>
<s:form id="addform" theme="css_xhtml" namespace="/exam" action="Create">
<s:textfield name="exam.name" label="Name" required="true" />
<s:textfield name="exam.author" label="Author" />
<s:textfield name="exam.minutesAllotted" label="Time limit"
required="true" />
<sj:datepicker id="startingDate" name="exam.startingDate"
label="Start date" timepicker="true" readonly="true"
displayFormat="dd/mm/yy" changeMonth="true" changeYear="true"
minDate="-0d" maxDate="+2y" />
<sj:datepicker id="endingDate" name="exam.endingDate" label="End date"
timepicker="true" displayFormat="dd/mm/yy" changeMonth="true"
changeYear="true" readonly="true" minDate="-0d" maxDate="+2y" />
<input type="button" value="Cancel"
onclick="$('#formcontainer').empty();">
<sj:submit targets="formcontainer" value="Add" />
</s:form>
我不需要在第二个jsp中更改任何内容。
答案 0 :(得分:1)
包括&lt; sj:head /&gt;只有一次。 - Aleksandr M