开发者

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

开发者 https://www.devze.com 2023-03-09 01:46 出处:网络
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:

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>
                 开发者_C百科      </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..


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>


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. :)


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

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

精彩评论

暂无评论...
验证码 换一张
取 消