我是Grails的新手,我在表单提交方面遇到了麻烦。
这是AnimaisController:
package jogoanimais
class AnimaisController {
def index() {
def animalsTreeObj = AnimaisTreeMap.list()
render(view: "show", model: [animalList: animalsTreeObj])
}
def addNode()
{
log.info "add node"
log.info params
}
}
这是show.gsp
<g:form controller="animais" action="addNode">
<div>Pense em um animal</div>
<g:textField name="myField" value="${myValue}" />
<g:actionSubmit value="OK, próximo" />
<g:each in="${animalList}" var="row" status="i">
<h3> ${row.nodeDescription}, ${row.yesAnswerNode}</h3>
<br/>
</g:each>
</g:form>
点击提交按钮后,请求的网址为&#34; http://localhost:8080/jogoAnimais/animais/addNode&#34;我收到404错误。
我也试过添加&#34;动作&#34;执行g:actionSubmit但在这种情况下,Grails请求addNode.gsp。
有没有人有任何想法?
答案 0 :(得分:1)
以下是解决方案:
<强> GSP:强>
添加&#34;行动&#34; g:form和输入类型的参数&#34;提交&#34;如下图所示:
<g:form controller="animais" action="addNode">
<div>Pense em um animal</div>
<div>
<label for="questionToUser">Questão:</label>
<g:textField name="questionToUser" maxlength="50"/>
</div>
<input type="submit" value="Submit">
<g:each in="${animalList}" var="row" status="i">
<h3> ${row.nodeDescription}, ${row.yesAnswerNode}</h3>
<br/>
</g:each>
</g:form>
<强>控制器:强>
正如mbaird所说,我的&#34; addNode&#34; mehtod需要返回一些东西,因为&#34;渲染&#39; ok&#39;&#34;