tags:

views:

263

answers:

2

I have a gsp view, with an , and 2 input text. I have a button to save and submit.

Now I would like to add another button with a new action, in my case a button to schedule save.

Note : in my controller I have define : def save (corresponding to button action save) and def schedule (corresponding to button action schedule).

What is the best way to add Schedule in this gsp view :

<g:uploadForm action="save" method="post" >
    <div class="dialog">
        <table>
            <tbody>

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="payload">File:</label>
                </td>
                <td valign="top">
                  <input type="file" id="payload" name="payload"/>
                </td>
                <td valign="top">
                  <input type="file" id="payload2" name="payload2"/>
                </td>
              </tr>

                <tr class="prop">
                    <td valign="top" class="name">
                        <label for="lvalue">Lvalue:</label>
                    </td>
                    <td valign="top" class="value ${hasErrors(bean:rmmInstance,field:'lvalue','errors')}">
                        <input type="text" id="lvalue" name="lvalue" value="${fieldValue(bean:rmmInstance,field:'lvalue')}" />
                    </td>
                </tr> 

                <tr class="prop">
                    <td valign="top" class="name">
                        <label for="wvalue">Wvalue:</label>
                    </td>
                    <td valign="top" class="value ${hasErrors(bean:rmmInstance,field:'wvalue','errors')}">
                        <input type="text" id="wvalue" name="wvalue" value="${fieldValue(bean:rmmInstance,field:'wvalue')}" />
                    </td>
                </tr> 

            </tbody>
        </table>
    </div>
    <div class="buttons">
        <span class="button"><input class="save" type="submit" value="Run Now" /></span>
    </div>
</g:uploadForm>

I have just one form, but 2 different actions.

Thanks !

+1  A: 

With an actionSubmit:

Purpose

Creates a submit button that maps to a specific action, which allows you to have multiple submit buttons in a single form. Javascript event handlers can be added using the same parameter names as in HTML.

From the Grails reference docs.

Cesar
A: 

This is just an example, but If I'm using actionSubmit, I can have :

        <div class="buttons">
            <g:form>
                <input type="hidden" name="id" value="${Instance?.id}" />
                <span class="button"><g:actionSubmit class="save" value="Run" /></span>
                <span class="button"><g:actionSubmit class="schedule" onclick="return confirm('Are you sure?');" value="Schedule" /></span>
            </g:form>
        </div>

I suppose, if I want to define action, I need to add : action="save" or action="schedule" with span. Or class definition is enough.

If I'm using actionSubmit, I can't use tag uploadForm ? Or I just need to delete action="save" with this tag ?

Fabien Barbier
You need to define the action using the "action" attribute on the actionSubmit tag, otherwise it's derived from the value itself.Also, you don't need to define an action in the form itself (it's discouraged) and you can use regular forms or uploadForms.
Cesar
Thank you for those tips and your time, I understand better now !
Fabien Barbier