Discussion:
Problem using g:submitToRemote and g:actionSubmit together.
Ivan Staskov
2008-07-07 14:53:12 UTC
Permalink
Hi,

I have tried to migrate my application to Grails-1.0.3 and found problem
using g:submitToRemote and g:actionSubmit tags into the same form.

for example we have following form:

<g:form name="testForm" method="post">
<div id="updateArea">
${message}
</div>
<g:submitToRemote action="submitToRemote"
update="[success:'updateArea']" value='SubmitToRemote'/>
<g:actionSubmit action="actionSubmit" value='ActionSubmit'/>
</g:form>

This code was working properly under Grails-1.0.2 and there were possibility
to submit form as to 'submitToRemote' action (via remote ajax), so and to
'actionSubmit' action. But under Grails-1.0.3 it's not working. When you
press 'SubmitToRemote' button, on server side will be called 'actionSubmit'
action and return wrong result.

I have attached small test application
http://www.nabble.com/file/p18318628/test.zip test.zip where you can
reproduce this problem.

Any ideas? As i already said, till Graills-1.0.3 this functionality worked
properly...

Thank you.
--
View this message in context: http://www.nabble.com/Problem-using-g%3AsubmitToRemote-and-g%3AactionSubmit-together.-tp18318628p18318628.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Brad Whitaker
2008-07-10 03:32:58 UTC
Permalink
I encountered essentially the same problem today on my project. We're not
using submitToRemote but we are doing an ajax submission of a form that
contains <g:actionSubmit>. The problem is that the javascript is submitting
all "inputs" in the request, even the <g:actionSubmit action="foo">, which
results in the following HTML: <input type="submit" name="_action_foo"
....>. Grails sees "_action_foo" in the request parameters and says "aha! we
need to execute action=foo" even though the user didn't click the button
associated with action foo.

I'm not what can be done to fix this. <g:actionSubmit> may simply be
incompatible with forms that are submitted with ajax. Perhaps there is a way
to modify the client side JavaScript so that inputs with type=submit are
omitted from the request parameters? If the client side script can be
modified in this way then I think the problem would be solved.

Brad
Post by Ivan Staskov
Hi,
I have tried to migrate my application to Grails-1.0.3 and found problem
using g:submitToRemote and g:actionSubmit tags into the same form.
<g:form name="testForm" method="post">
<div id="updateArea">
${message}
</div>
<g:submitToRemote action="submitToRemote"
update="[success:'updateArea']" value='SubmitToRemote'/>
<g:actionSubmit action="actionSubmit" value='ActionSubmit'/>
</g:form>
This code was working properly under Grails-1.0.2 and there were
possibility to submit form as to 'submitToRemote' action (via remote
ajax), so and to 'actionSubmit' action. But under Grails-1.0.3 it's not
working. When you press 'SubmitToRemote' button, on server side will be
called 'actionSubmit' action and return wrong result.
I have attached small test application
http://www.nabble.com/file/p18318628/test.zip test.zip where you can
reproduce this problem.
Any ideas? As i already said, till Graills-1.0.3 this functionality worked
properly...
Thank you.
--
View this message in context: http://www.nabble.com/Problem-using-g%3AsubmitToRemote-and-g%3AactionSubmit-together.-tp18318628p18375210.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Brock Heinz
2008-07-10 11:27:08 UTC
Permalink
Hey Guys,

I think the issue described is similar to this one that came up a while ago:
http://www.nabble.com/formRemote--%3E-404----grails-system-update.dispatch-td17810585.html#a17810585

Peter tracked down the problem and described it here:
http://jira.codehaus.org/browse/GRAILS-3109

Brock
Post by Brad Whitaker
I encountered essentially the same problem today on my project. We're not
using submitToRemote but we are doing an ajax submission of a form that
contains <g:actionSubmit>. The problem is that the javascript is submitting
all "inputs" in the request, even the <g:actionSubmit action="foo">, which
results in the following HTML: <input type="submit" name="_action_foo"
....>. Grails sees "_action_foo" in the request parameters and says "aha! we
need to execute action=foo" even though the user didn't click the button
associated with action foo.
I'm not what can be done to fix this. <g:actionSubmit> may simply be
incompatible with forms that are submitted with ajax. Perhaps there is a way
to modify the client side JavaScript so that inputs with type=submit are
omitted from the request parameters? If the client side script can be
modified in this way then I think the problem would be solved.
Brad
Post by Ivan Staskov
Hi,
I have tried to migrate my application to Grails-1.0.3 and found problem
using g:submitToRemote and g:actionSubmit tags into the same form.
<g:form name="testForm" method="post">
<div id="updateArea">
${message}
</div>
<g:submitToRemote action="submitToRemote"
update="[success:'updateArea']" value='SubmitToRemote'/>
<g:actionSubmit action="actionSubmit" value='ActionSubmit'/>
</g:form>
This code was working properly under Grails-1.0.2 and there were
possibility to submit form as to 'submitToRemote' action (via remote
ajax), so and to 'actionSubmit' action. But under Grails-1.0.3 it's not
working. When you press 'SubmitToRemote' button, on server side will be
called 'actionSubmit' action and return wrong result.
I have attached small test application
http://www.nabble.com/file/p18318628/test.zip test.zip where you can
reproduce this problem.
Any ideas? As i already said, till Graills-1.0.3 this functionality worked
properly...
Thank you.
--
View this message in context: http://www.nabble.com/Problem-using-g%3AsubmitToRemote-and-g%3AactionSubmit-together.-tp18318628p18375210.html
Sent from the grails - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Brad Whitaker
2008-07-10 16:59:34 UTC
Permalink
The issue in GRAILS-3109 is related but not really the same. The current
issue is strictly an AJAX issue. If, for instance, you have a non-AJAX form
that looks like this:

<g:form method="post" >
<g:actionSubmit value="Foo #1" action="fooOne" />
<g:actionSubmit value="Foo #2" action="fooTwo" />
</g:form>

You end up with HTML like this:

<form action="/test103/test/failed" method="post" >
<input type="submit" name="_action_fooOne" value="Foo #1" />
<input type="submit" name="_action_fooTwo" value="Foo #2" />
</form>

If you click the button in the browser then the params will contain ONLY the
submit that you clicked -- the other 'submit' will not be included in the
params.

If you add AJAX to the form then you run into problems. Suppose you change
the form like this:

<g:form method="post" >
<g:submitToRemote update="updateMe"/>
<g:actionSubmit value="Foo #1" action="fooOne" />
<g:actionSubmit value="Foo #2" action="fooTwo" />
</g:form>

Then you get HTML like this:

<form action="/test103/test/failed" method="post" >
<input onclick="new
Ajax.Updater('updateMe','/test103/test/failed',{asynchronous:true,evalScripts:true,parameters:Form.serialize(this.form)});return
false" type="button"></input>
<input type="submit" name="_action_fooOne" value="Foo #1" />
<input type="submit" name="_action_fooTwo" value="Foo #2" />
</form>

The problem is that if you click the "Ajax" button then the values of the
two submit buttons, e.g. _action_fooOne and _action_fooTwo are unfortunately
included in the params of the request. Grails chooses an action based upon
the first _action_* param that it finds in the request and ignores the
action associated with the updateMe button that was clicked.
Post by Brock Heinz
Hey Guys,
http://www.nabble.com/formRemote--%3E-404----grails-system-update.dispatch-td17810585.html#a17810585
http://jira.codehaus.org/browse/GRAILS-3109
Brock
Post by Brad Whitaker
I encountered essentially the same problem today on my project. We're not
using submitToRemote but we are doing an ajax submission of a form that
contains <g:actionSubmit>. The problem is that the javascript is submitting
all "inputs" in the request, even the <g:actionSubmit action="foo">, which
results in the following HTML: <input type="submit" name="_action_foo"
....>. Grails sees "_action_foo" in the request parameters and says "aha! we
need to execute action=foo" even though the user didn't click the button
associated with action foo.
I'm not what can be done to fix this. <g:actionSubmit> may simply be
incompatible with forms that are submitted with ajax. Perhaps there is a way
to modify the client side JavaScript so that inputs with type=submit are
omitted from the request parameters? If the client side script can be
modified in this way then I think the problem would be solved.
Brad
Post by Ivan Staskov
Hi,
I have tried to migrate my application to Grails-1.0.3 and found problem
using g:submitToRemote and g:actionSubmit tags into the same form.
<g:form name="testForm" method="post">
<div id="updateArea">
${message}
</div>
<g:submitToRemote action="submitToRemote"
update="[success:'updateArea']" value='SubmitToRemote'/>
<g:actionSubmit action="actionSubmit" value='ActionSubmit'/>
</g:form>
This code was working properly under Grails-1.0.2 and there were
possibility to submit form as to 'submitToRemote' action (via remote
ajax), so and to 'actionSubmit' action. But under Grails-1.0.3 it's not
working. When you press 'SubmitToRemote' button, on server side will be
called 'actionSubmit' action and return wrong result.
I have attached small test application
http://www.nabble.com/file/p18318628/test.zip test.zip where you can
reproduce this problem.
Any ideas? As i already said, till Graills-1.0.3 this functionality worked
properly...
Thank you.
--
http://www.nabble.com/Problem-using-g%3AsubmitToRemote-and-g%3AactionSubmit-together.-tp18318628p18375210.html
Sent from the grails - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
View this message in context: http://www.nabble.com/Problem-using-g%3AsubmitToRemote-and-g%3AactionSubmit-together.-tp18318628p18386409.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Tom Nichols
2008-07-10 17:43:44 UTC
Permalink
Ah, so it does submit both submit buttons as ajax request params.

I think I liked it better when the g:form action was the only
determining factor in which Grails action is called :) If you have
two submit buttons that you want to perform different actions, can't
you just delegate from the your grails action based on the params? It
seems like Grails is _completely_ ignoring the request URL (or at
least the action) altogether in this case.

If you follow the HTTP/HTML paradigm, a form can only submit to _one_
action URL. So in my mind Grails would be better off following that
standard, with a URL mapping to a Grails action (as is still the case
most of the time). I think if you add form parameters as part of the
action determination, it becomes much more difficult to
programmatically call a given action because you need to then give the
correct URL _and_ magical _action_ parameter. I don't like this idea;
it makes me think of JSF and ASP.NET which can barely even perform an
action request without all sorts of convoluted request parameters and
javascript.

I suppose it's a little late for me to complain since the feature is
already implemented, but I don't think I like the idea of the Grails
action being dependent on parameters.

-Tom
Post by Brad Whitaker
The issue in GRAILS-3109 is related but not really the same. The current
issue is strictly an AJAX issue. If, for instance, you have a non-AJAX form
<g:form method="post" >
<g:actionSubmit value="Foo #1" action="fooOne" />
<g:actionSubmit value="Foo #2" action="fooTwo" />
</g:form>
<form action="/test103/test/failed" method="post" >
<input type="submit" name="_action_fooOne" value="Foo #1" />
<input type="submit" name="_action_fooTwo" value="Foo #2" />
</form>
If you click the button in the browser then the params will contain ONLY the
submit that you clicked -- the other 'submit' will not be included in the
params.
If you add AJAX to the form then you run into problems. Suppose you change
<g:form method="post" >
<g:submitToRemote update="updateMe"/>
<g:actionSubmit value="Foo #1" action="fooOne" />
<g:actionSubmit value="Foo #2" action="fooTwo" />
</g:form>
<form action="/test103/test/failed" method="post" >
<input onclick="new
Ajax.Updater('updateMe','/test103/test/failed',{asynchronous:true,evalScripts:true,parameters:Form.serialize(this.form)});return
false" type="button"></input>
<input type="submit" name="_action_fooOne" value="Foo #1" />
<input type="submit" name="_action_fooTwo" value="Foo #2" />
</form>
The problem is that if you click the "Ajax" button then the values of the
two submit buttons, e.g. _action_fooOne and _action_fooTwo are unfortunately
included in the params of the request. Grails chooses an action based upon
the first _action_* param that it finds in the request and ignores the
action associated with the updateMe button that was clicked.
Post by Brock Heinz
Hey Guys,
http://www.nabble.com/formRemote--%3E-404----grails-system-update.dispatch-td17810585.html#a17810585
http://jira.codehaus.org/browse/GRAILS-3109
Brock
Post by Brad Whitaker
I encountered essentially the same problem today on my project. We're not
using submitToRemote but we are doing an ajax submission of a form that
contains <g:actionSubmit>. The problem is that the javascript is submitting
all "inputs" in the request, even the <g:actionSubmit action="foo">, which
results in the following HTML: <input type="submit" name="_action_foo"
....>. Grails sees "_action_foo" in the request parameters and says "aha! we
need to execute action=foo" even though the user didn't click the button
associated with action foo.
I'm not what can be done to fix this. <g:actionSubmit> may simply be
incompatible with forms that are submitted with ajax. Perhaps there is a way
to modify the client side JavaScript so that inputs with type=submit are
omitted from the request parameters? If the client side script can be
modified in this way then I think the problem would be solved.
Brad
Post by Ivan Staskov
Hi,
I have tried to migrate my application to Grails-1.0.3 and found problem
using g:submitToRemote and g:actionSubmit tags into the same form.
<g:form name="testForm" method="post">
<div id="updateArea">
${message}
</div>
<g:submitToRemote action="submitToRemote"
update="[success:'updateArea']" value='SubmitToRemote'/>
<g:actionSubmit action="actionSubmit" value='ActionSubmit'/>
</g:form>
This code was working properly under Grails-1.0.2 and there were
possibility to submit form as to 'submitToRemote' action (via remote
ajax), so and to 'actionSubmit' action. But under Grails-1.0.3 it's not
working. When you press 'SubmitToRemote' button, on server side will be
called 'actionSubmit' action and return wrong result.
I have attached small test application
http://www.nabble.com/file/p18318628/test.zip test.zip where you can
reproduce this problem.
Any ideas? As i already said, till Graills-1.0.3 this functionality worked
properly...
Thank you.
--
http://www.nabble.com/Problem-using-g%3AsubmitToRemote-and-g%3AactionSubmit-together.-tp18318628p18375210.html
Sent from the grails - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
View this message in context: http://www.nabble.com/Problem-using-g%3AsubmitToRemote-and-g%3AactionSubmit-together.-tp18318628p18386409.html
Sent from the grails - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Brad Whitaker
2008-07-10 20:13:35 UTC
Permalink
If that's the behavior that you want then all you have to do is stay away
from <g:actionSubmit> (and undocumented <g:actionSubmitImage>). These tags
are nifty additions that try to augment HTML/HTTP but there are some
difficulties with their usage. If you stick with <g:submitButton> then
you'll be comfortably be in harmony with HTML/HTTP.

BTW, I think an argument could be made that the primary offender is the
JavaScript libraries that serialize the <input type="submit"> tags and
included them in the async requests. These tags hold only static information
(presumably) so there is really no reason to send them in the request. The
behavior of the JavaScript libraries is different from the way a browser
behaves -- browsers omit these tags unless the particular tag (button) has
been clicked.
I think I liked it better when the g:form action was the only determining
factor in which Grails action is called :)
--
View this message in context: http://www.nabble.com/Problem-using-g%3AsubmitToRemote-and-g%3AactionSubmit-together.-tp18318628p18390911.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Tom Nichols
2008-07-10 20:16:04 UTC
Permalink
Hmm. True.
Post by Brad Whitaker
If that's the behavior that you want then all you have to do is stay away
from <g:actionSubmit> (and undocumented <g:actionSubmitImage>). These tags
are nifty additions that try to augment HTML/HTTP but there are some
difficulties with their usage. If you stick with <g:submitButton> then
you'll be comfortably be in harmony with HTML/HTTP.
BTW, I think an argument could be made that the primary offender is the
JavaScript libraries that serialize the <input type="submit"> tags and
included them in the async requests. These tags hold only static information
(presumably) so there is really no reason to send them in the request. The
behavior of the JavaScript libraries is different from the way a browser
behaves -- browsers omit these tags unless the particular tag (button) has
been clicked.
I think I liked it better when the g:form action was the only determining
factor in which Grails action is called :)
--
View this message in context: http://www.nabble.com/Problem-using-g%3AsubmitToRemote-and-g%3AactionSubmit-together.-tp18318628p18390911.html
Sent from the grails - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Peter Ledbrook
2008-07-16 10:55:19 UTC
Permalink
Post by Brad Whitaker
If that's the behavior that you want then all you have to do is stay away
from <g:actionSubmit> (and undocumented <g:actionSubmitImage>). These tags
are nifty additions that try to augment HTML/HTTP but there are some
difficulties with their usage. If you stick with <g:submitButton> then
you'll be comfortably be in harmony with HTML/HTTP.
I wonder whether we might be better off using a <button> tag. So,
<g:actionSubmit/> would become:

<button name="_action_submit" value="update">Update</value>

Then we would either get a single value (for the button that was
clicked) or an array of values if all the buttons are submitted.

Another alternative is to ignore "_action_*" parameters if there is
more than one. If we do decide to change the current behaviour, we
would need to check it against IE6 - from what I remember, it submits
all <button> values, regardless of which one was pressed.

Cheers,

Peter
--
Software Engineer
G2One, Inc.
http://www.g2one.com/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Peter Ledbrook
2008-07-23 09:41:39 UTC
Permalink
Post by Ivan Staskov
<g:form name="testForm" method="post">
<div id="updateArea">
${message}
</div>
<g:submitToRemote action="submitToRemote"
update="[success:'updateArea']" value='SubmitToRemote'/>
<g:actionSubmit action="actionSubmit" value='ActionSubmit'/>
</g:form>
This seems to be a problem with Prototype:

http://dev.rubyonrails.org/ticket/5031

It may be worth trying YUI or some other pluggable Ajax libraries.

Cheers,

Peter
--
Software Engineer
G2One, Inc.
http://www.g2one.com/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Loading...