Hi,
I've gotten into a situation with the CMS we use in a project, where we need to build a form for a portlet, and that form should have some file fields. I planed to use Spring portlet MVC and their form solution, so that I get my bean/command object populated from the form inputs, and also be able to validate the form with ease.
Now, the problem is that the CMS has some
servlet filter that reads any multipart/form-data information from the request, making it unavailable for me in the portlet.
When I asked the CMS support about this they said that the filter is an internal-only feature, and even though it is possible to get access to the data (ie the files) that the filter has "absorbed", it is not recommended nor supported, since they might change this implementation at any time. The only recommendation they had for me was to post the form to a servlet in the "portlet webapp", since that would not be subjected to the filter.
I tried their solution, and sure thing, I can now get access to the file data using CommonsMultipartResolver. But I still need to somehow show the form page again after the files has been handled. So now I'm faced with two options, that both have serious disadvantages:
1. I do a forward* to the actionURL of the portlet
2. I do a redirect
The problem with the forward is that I noticed that the onSubmitAction method is never triggered, instead the showForm method is triggered. For some reason my actionURL is handled as a RenderRequest instead of an ActionRequest when I do the forward from the servlet. The result is that my command object is not populated with the form values, and no validation is done. So all that happens is that a new empty form is displayed.
Also, a forward causes the URL in the browser to point to the servlet that the POST was issued for, and that is quite ugly. And this causes the relative urls on the page to stop working (even if that can be fixed by using only absolute urls everywhere).
The problem with the redirect is that I have to store everything in the session for retrieval in the portlet (using the APPLICATION scope). To append all the POST parameters as request parameters on the actionURL is not an option, since the form contains quite a few different input fields, and combined together the URL could be quite long.
What I really would want is a way to make the Spring Portlet MVC form population and validation work without having to do a bunch of manual spring-form stuff. But is that possible given the existing conditions?
If not, is there a good way to use Spring Portlet MVC form classes as regular tools somehow?
Or maybe my best choice is to just bite the bullet and do all the bean field population and validation manually?
Regards
/Jimi
* using getServletContext().getContext("/").getRequestDispatcher(actionURL).forward(multipartRequest, response);