Hi All,
I have an edit button
<span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
But when click on it the adderess on the browser was not http:\...\edit,
it was http:\...\index. Why?
I tried to delete or rename the name of Edit in controller, it still not influence. Why?
Thanks!!!
Try specifying controller's name with g:form like
<g:form controller="CONTROLLER_NAME">
Related
I'm completely new to grails, and I appreciate any help.
This code is in my gsp file:
<g:form action="backfillMachineTags">
<fieldset class="buttons">
<g:submitButton name="create" class="save"
value="${message(code: 'default.button.create.label', default: 'Create')}"/>
</fieldset>
</g:form>
And this code is in my RegressionPoolMachineController.groovy file:
def backfillMachineTags()
{
flash.message = "testing message"
redirect(action: "list")
}
But when I click the submit button on the form, the method is never entered and I get a 404 not found.
message:/pool-manager/regressionPoolMachine/backfillMachineTags
status: The requested resource is not available.
I also tried doing:
<g:form url="[action:'backfillMachineTags',controller:'RegressionPoolMachineController']">
but get a similar 404 not found.
Am I missing a step to connect my form and controller?
Try to use the following:
<g:form controller = "controllerName" action ="actionName" >
<fieldset class="buttons">
<g:submitButton name="create" class="save" value ="${message(code: 'default.button.create.label', default: 'Create')}"/>
</fieldset>
</g:form>
Try adding a "controller" attribute to your form in addition to the "action" attribute. You could use url instead of controller and action, but you would need something like
url="${createLink(controller: "myController", action: "myAction")}" instead of what you've shown here.
For reference: http://docs.grails.org/2.5.6/ref/Tags/form.html
You can also look at the generated HTML in your browser (just view source) and see what is actually being generated on the resulting web page. That's usually pretty helpful for finding out why things aren't going where you want them to!
is there a way to call a method from a controller using a button? i did this:
<g:form controller="aluno" action="pesquisar"><input type="submit" value="Pesquisar"></g:form>
it worked, but, is there another way?
You can use actionSubmit tag:
<g:actionSubmit value="My Button" action="myAction" />
In a general way, you can use createLink to generate links to actions:
<a href="${createLink(action:'myAction', controller:'myController')}">
Try this.
<g:link class="btn btn-info btn-sm" action="pesquisar" resource="${instance}">TRY IT</g:link>
Note : When you click try it Button it will automatically get controller which you currently used.
An alternative, you can use a button in place of an input:
<g:link controller="yourcontroller" action="yourfunction">
<button type="button">Press me!!!</button>
</g:link>
Recently I began to study Grails, and I noticed that the file create.groovy is generated by a dynamic scaffold. The form tag doesn't have an attribute called controller, only action.
So my question is, how does the Grails framework discover the controller that should be called?
<g:form action="save">
<fieldset class="form">
<f:field bean="categoria" property="nome" class="form-control" />
</fieldset>
<fieldset class="buttons">
<g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" />
</fieldset>
</g:form>
Thanks, and sorry for my bad english!
Grails uses "convention over configuration" so whenever you use a form without controller, grails will use the default convention.
Since your view is put in a folder named after a controller, grails will assume that the default controller for any view inside that folder is the one that matches with the folder name. Example
BookController is the default controller for any gsp inside the grails-app/views/book folder.
*This convention also applies to things like links.
I'm working on a Grails application and as you can see from the screenshot below, at the bottom of my create page I have two submit buttons, the one on the left creates and saves the instance and takes me to the show page of the instance I have just created.
The submit button on the right does exactly the same thing however I now want that button to save/create the instance but stay on this same (create) page and not redirect me to show.gsp with the fields still filled with the data previously entered. Is this possible?
Here is the code for the two buttons at the bottom of create.gsp
<g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" />
<g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" />
instead of <g:submitButton> you should use:
<g:actionSubmit value="${message(default:'Create')}" action="create" />
<g:actionSubmit value="${message(default:'Create and Stay')}" action="createAndStay" />
in the corresponding controler actions you decide wether you redirect to list or to create actions
I have created a very simple form for signing up a user
<g:form name="signupForm" url="[controller:'users', action:'signup']">
<g:textField name="username" placeholder="Username" />
<g:passwordField name="password" placeholder="Password" />
<g:textField name="email" placeholder="Email" />
<g:actionSubmit class="right" value="Signup" action="update" />
</g:form>
When I click the submit button I get a 404 error The requested resource is not available. However, if I navigate to the exact same URL manually (or even just select the address bar on the 404 error page and press enter) then it works!
My controller looks like this, it's very simple.
class UsersController {
def signup() {
render "Hello World"
}
}
Sorry if this is a noob question, but I've looked all over the Grails docs and can't figure out why this is happening. Any help much appreciated. Thanks.
The g:actionSubmit has the parameter action="update" which will push it to the UsersController def update which isn't there so it will throw a 404.
You can remove the action="update" or add that action to the controller.
http://grails.org/doc/latest/ref/Tags/actionSubmit.html
There is also a g:submitButton you can use instead.
http://grails.org/doc/latest/ref/Tags/submitButton.html