History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GRAILS-2774
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Graeme Rocher
Reporter: Jon Gunnip
Votes: 12
Watchers: 8
Operations

If you were logged in you would be able to see more operations.
Grails

g.actionSubmit ignored when form has enctype="multipart/form-data"

Created: 02/Apr/08 11:37 PM   Updated: 15/Sep/08 09:04 AM
Component/s: TagLib
Affects Version/s: 1.0.2
Fix Version/s: 1.0.4

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive test.zip (179 kb)

Environment: Windows XP, Java 1.5


 Description  « Hide
Steps to reproduce:
– See attached application created by: grails create-app test, grails create-domain-class Image, add "String name, byte[] data" to Image class, grails generate-all Image
– grails run-app
– Go to http://localhost/test/image
– Create a new image
– Go to edit the image
– Clicking on the "Edit" or "Delete" (implemented with g.actionSubmit) will just bring user back to index action with no edit or delete performed

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Jon Gunnip - 03/Apr/08 08:44 AM
I forgot to add that removing the enctype="multipart/form-data" from the form tag and commenting out the input type="file" gets the appropriate g.submitAction actions invoked.

Jon Gunnip - 03/Apr/08 11:32 AM
Workaround is to do the following in the controller:
def index = {
        // temporary hack since g.actionSubmit does not work with multipart forms
        if (params["_action_Save"]) {
            save()
        }
        else if (params["_action_Update"]) {
            update()
        }
        else if (params["_action_Delete"]) {
            delete()
        }
        else {
            redirect(action: list)
        }
    }

Brad Whitaker - 12/Jun/08 04:15 PM
I've done some analysis of the cause of this problem (although I have no idea what the solution is). When a multipart request is submitted the request parameter passed to DefaultUrlMappingInfo.checkDispatchAction() is of type org.mortbay.jetty.Request (devel environment) and the Enumeration returned from request.getParameterNames() has no elements. This causes the "action*" parameter to be missed/ignored.

By the time the request is passed on to an application filter the request is of type org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest and the Enumeration returned from request.getParameterNames() contains all expected elements.


Peter Ledbrook - 11/Aug/08 08:27 AM
Another workaround:

1. Run grails install-templates.
2. Edit src/templates/war/web.xml and insert the following fragment before the first filter mapping:

<filter>
    <filter-name>multipartFilter</filter-name>
    <filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>multipartFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
Note that the filter mapping must come before the "charEncodingFilter" one.
3. Add this bean definition to web-app/WEB-INF/applicationContext.xml:
<bean id="filterMultipartResolver"
      class="org.codehaus.groovy.grails.web.multipart.ContentLengthAwareCommonsMultipartResolver"/>


Peter Ledbrook - 15/Sep/08 09:04 AM
I guess that's because the filter comes before the character encoding one. And I can't remember why I said that has to be the order.