Reputation: 524
I'm new on Grails and I'm having trouble to do a form submit.
Here is 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
}
}
Here is 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>
After clicking at the submit button, the URL that is requested is "http://localhost:8080/jogoAnimais/animais/addNode" and I get a 404 error.
I've also tried adding "action" do g:actionSubmit but in this case, Grails requested a addNode.gsp.
Does anyone has any idea?
Upvotes: 1
Views: 464
Reputation: 524
Here's the solution:
GSP:
Add "action" parameter of g:form and a input type "submit" as shown below:
<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>
CONTROLLER:
As mbaird has said, my "addNode" mehtod need to return something, as "render 'ok'"
Upvotes: 1