VictorArgentin
VictorArgentin

Reputation: 433

Grails g:Button name coming from params and no form to use

Is there any possibility of having a button which will execute and action in a controller without a form ?. Also, i would like do do something like this, but i see that's not possible:

<g:form action="addFavourite">
                                                <td>
        <g:submitButton name="${it.area.name}" value="Add" class="button small blue"/><br><br>
        </td>
                       </g:form>

To name the button with a value that comes from a controller isnt working. Any possible alternative for that? It gives me a null-error-code. And i'm 100% sure the value isnt null..

Upvotes: 0

Views: 5159

Answers (3)

Amit Jain
Amit Jain

Reputation: 1382

What does "it" stands here for? I think that is the culprit..

<g:submitButton name="${it.area.name}" value="Add" class="button small blue"/>

Upvotes: 0

D&#243;nal
D&#243;nal

Reputation: 187399

You can create a button outside a form that executes a controller action when it's clicked using the remoteFunction tag

<button type="button" name="myButton"
    onclick="${remoteFunction(action:'bookByName', controller: 'book'
    params:'\'bookName=\' + this.value')}">Click Here</button>

Upvotes: 1

Gregg
Gregg

Reputation: 35904

It kind of depends. If you want a button to submit to a server via a standard POST then no. HTML doesn't even have a button that works without a form. You can fake this with an image link that looks like a button, but really it just submits via a standard anchor tag. And this would perform a GET, not a POST.

However, if you want to use ajax, you could skip the Grails tags (as I often do) and use the HTML BUTTON element. Could even use the remoteFunction to make the ajax call if you want.

UPDATE: Doh! 2 of the same answers. :)

Upvotes: 0

Related Questions