我有以下模型,Major
,University
和Application
。在创建新的应用程序时,我希望包含该应用程序的主要列表根据大学字段的选择动态更改。
我在我的代码中使用了dojo,但它无法正常工作..
创建应用程序标记
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields"
xmlns:form="urn:jsptagdir:/WEB-INF/tags/form"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:spring="http://www.springframework.org/tags" version="2.0">
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:output omit-xml-declaration="yes" />
<spring:url value="/applications/majorsByUniversity?university="
var="ajax_url" />
<script type="text/javascript">
// DOM is ready
dojo.addOnLoad(function() {
var universityID = dijit.byId("_university_id");
//var majors = dijit.byId("_majors_id");
var _fragment_item_ = dojo.byId("_fragment_item_");
dojo.connect(universityID, "onChange", function(evt) {
var url = "${ajax_url}?university=" + universityID.get("Value");
dojo.xhrGet({url : "applications/majorsbyuniversity", timeout : 2000, content : {
universityId : dojo.trim(universityID.value)}, load : function(result) {
_fragment_item_.innerHTML = "" + result;
Spring.addDecoration(new Spring.ElementDecoration({
elementId : '_major_id',
widgetType : 'dijit.form.FilteringSelect',
widgetAttrs : {
hasDownArrow : true
}
}));
}
});
});
});
</script>
<form:create id="fc_eu_gju_domain_Application"
modelAttribute="application" path="/applications"
render="${empty dependencies}" z="kI5rm14J9r0TDsEBqiWG5a6bVnw=">
<field:input field="status" id="c_eu_gju_domain_Application_status"
z="v09RNw9OQd32sgV0gnb/TcG4NLY=" />
<field:select field="university"
id="c_eu_gju_domain_Application_university" itemValue="id"
items="${universitys}" path="/universitys"
z="O6M+L2bFaYs9ILR85JMqyqOe3jg=" />
<div id="_fragment_item_">
<field:select field="majors" id="c_eu_gju_domain_Application_majors"
itemValue="id" items="${result}" multiple="true" path="/majors"
z="SToc0qAE7C9u/cHqpb1wizsN1N0=" />
</div>
</form:create>
<form:dependency dependencies="${dependencies}"
id="d_eu_gju_domain_Application" render="${not empty dependencies}"
z="zaFd2zq80iviSNmKnrMKaVLPQQY=" />
</div>
Application.java
@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class Application {
private String status;
@ManyToOne
private University university;
@ManyToMany(cascade = CascadeType.ALL)
private Set<Major> majors = new HashSet<Major>();
}
ApplicationController.java
@RequestMapping("/applications")
@Controller
@RooWebScaffold(path = "applications", formBackingObject = Application.class)
public class ApplicationController {
public @ResponseBody List<Major> majorsByUniversity(@RequestParam Long universityId) {
List<Major> majors = Major.findMajorsByUniversity(University.findUniversity(universityId)).getResultList();
return majors;
}