我正在尝试使用ajax创建两个选择,一个填充基于另一个的信息。我所关注的例子是http://www.grails.org/AJAX-Driven+SELECTs+in+GSP。我也在使用scaffold,所以我不得不使用install-templates命令来获取操作gsp文件的视图。通过模板中的一些tweeking,我有一个工作创建视图供我选择构建。但是,如教程中指定的那样输入这些选择会导致错误,我无法解决
Stack trace as below :
| Error 2013-01-12 16:11:46,582 [http-bio-8080-exec-3] ERROR errors.GrailsExceptionResolver - GrailsTagException occurred when processing request: [GET] /TimeTracker2/time/create
Unclosed GSP expression. Stacktrace follows:
Message: Error initializing GroovyPageView
Line | Method
->> 186 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by GrailsTagException: Unclosed GSP expression
->> 33 | doFilter in \grails-app\views\time\create.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
我的GSP在下面,您可以看到所有表达式都已关闭......建议?
<head>
<meta name="layout" content="main">
<g:set var="entityName" value="\${domainClass.propertyName}" />
<title>Create Time</title>
</head>
<body>
<a href="#create-{domainClass.propertyName}" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content…"/></a>
<div class="nav" role="navigation">
<ul>
<li><a class="home" href="/TimeTracker2"><g:message code="default.home.label"/></a></li>
<li><g:link class="list" action="list"><!--g:message code="default.list.label" args="[entityName]" /-->Time List</g:link></li>
</ul>
</div>
<div id="create-{domainClass.propertyName}" class="content scaffold-create" role="main">
<h1><!--g:message code="default.create.label" args="[entityName]" /-->Create Time</h1>
<g:if test="${flash.message}">
<div class="message" role="status">${flash.message}</div>
</g:if>
<g:hasErrors bean="\${propertyName}">
<ul class="errors" role="alert">
<g:eachError bean="\${propertyName}" var="error">
<li <g:if test="\${error in org.springframework.validation.FieldError}">data-field-id="\${error.field}"</g:if>><g:message error="\${error}"/></li>
</g:eachError>
</ul>
</g:hasErrors>
<g:form action="save" method="post" enctype="multipart/form-data" >
<fieldset class="form">
<g:render template="form"/>
<g:select
optionKey="id" optionValue="Project" name="project.name" id="project.name" from="${Project.list()}"
onchange="${remoteFunction(
controller:'project',
action:'ajaxGetClassifications',
params:'\\'id='\\' + escape(this.value)',
onComplete:'updateClassification(e)')}"
></g:select>
</fieldset>
<fieldset class="buttons">
<g:submitButton name="create" class="save" value="Create" />
</fieldset>
</g:form>
</div>
</body>
答案 0 :(得分:0)
Id将select的onChange事件的javascript函数放入单独的函数中,而不是在g:select标记中内联。
答案 1 :(得分:0)
在解决问题之后(并且有很多),答案是提供我的域类的正确的完整位置。
<g:select optionKey="id" optionValue="name" name="project.name" id="project.name"
from="${timetracker2.Project.list()}" onchange="${remoteFunction(controller:'project',
action:'ajaxGetClassifications',
params:'\'id=\' + escape(this.value)',
onComplete:'updateClassification(e)')}"
></g:select>
我现在的问题在于如何持久保存信息,以及如何实际使第二个列表从第一个列表中获取其值。但那是另一天的另一个问题。