• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring portlet MVC forms, multipart data and servlets?

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
 
author
Posts: 469
20
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jimi,

I think switching between servlet and portlet can be tricky, but this is where you can only choose to go the servlet way. I would suggest that you use portlet to render form and use AJAX for uploading files , which'll save the effort to switch between portlets and servlets. You may some details in this Liferay Wiki article (which also contains the source code):http://www.liferay.com/community/wiki/-/wiki/Main/Spring-Hibernate-DWR

regards
ashish
 
Jimi Svedenholm
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ashish Sarin wrote:Hi Jimi,

I think switching between servlet and portlet can be tricky, but this is where you can only choose to go the servlet way. I would suggest that you use portlet to render form and use AJAX for uploading files , which'll save the effort to switch between portlets and servlets. You may some details in this Liferay Wiki article (which also contains the source code):http://www.liferay.com/community/wiki/-/wiki/Main/Spring-Hibernate-DWR

regards
ashish



Hi Ashish,

Thanks for the tip! I don't understand how I have missed DWR. Some simple tests proved that this should work just fine.

/Jimi
reply
    Bookmark Topic Watch Topic
  • New Topic