Laliwala IT Services

Laliwala IT Services
Website Development

Thursday, February 24, 2011

Struts ActionForms with MultiPart forms, liferay libraty, liferay settings, liferay entry, action.java, com.liferay, portlet.document, strutslifera y

Struts ActionForms with MultiPart forms


Jim Klo : Wondering if anyone has any clues what might be going on - while this isn't the first time I've seen this behavior, this is the first time I don't have a workaround...








I need to add some form fields to files within the Document Library that gets stored in the DLFileEntry.getExtraSettingsProperties(). I noticed while looking at the 5.2.3 source there is a file:








/portal-web/docroot/html/portlet/document_library/edit_file_entry_form_extra_fields.jsp








within there is the following:








liferay struts tutorial, liferay forms tutorial, liferay library tutorial, struts action tutorial, liferay administrator tutorial








which looks great, I can just add my extra fields by using the Struts ActionForm notation...








When I look at the Action in com.liferay.portlet.documentlibrary.action.EditFileEntryAction.java of which this Form should post and part of the Struts lifecycle, the form should populate.








However the form never populates, there's obviously a form instance, but the form never gets the values populated. Now technically, but struts definition the property name should start with a lowercase letter on the <input name="extraSettingsProperties(test)" ... />, however I've tried this both ways with no success.








Are Struts forms just inherently broken in Liferay? I've gone down this rat hole before when trying to build my own portlets previously and noticed that the form beans don't work, and had to use the ParamUtils to get the form values.








Does anyone know how to resolve or fix this - it seems no one is either using ActionForms or no one has noticed this problem...








Please someone help!






Jim Klo : Update: After actually stepping through Struts source.... I've determined... It looks like Liferay is broke... or at least not interfacing with Struts 100% correctly.








It turns out that Struts Form Beans work only work for non-multipart forms within Liferay Portlets. The Document Library edit form - is a multi-part form, which would explain why this isn't working.








From what I can tell, it looks like in order to fix this, a custom MultipartRequestHandler needs to be written such that the parameters and file objects get parsed correctly. Then this handler needs to injected at the right time, which I'm not totally sure what conditions need to be met to do this (otherwise, I'd just fix it)






Mazhar Anwar : Hi Jim,








Liferay has taken care for multipart encrypted form by com.liferay.portal.kernel.upload.UploadPortletRequest Interface.

liferay tutorial india, liferay web tutorial








You can use it as follows,








liferay support, liferay website tutorial








Hope this will solve your problem.








Regards,

Mazhar






Jim Klo : Sure... you're missing the point... I know I can do that (and probably will end up having to do that by rewriting the Document Library action so they work)... the problem is there are several touch points in the portal source already that assume that Struts MVC works for multipart forms - when it clearly doesn't.








What I'm proposing is the actual FIX so Struts MVC works as it's supposed to - not by using a workaround method that uses a getter utility.








Part of the beauty of Struts MVC, is that you can have a form bean POJO that get's populated during the request, so when you're in your Action classes execute, you don't have to fetch each of the parameters individually which is what you're solution proposes. (oddly this all works in liferay using the Sample Struts Portlet - assuming because this uses the Struts Bridge, however the Sample Struts Liferay Portlet doesn't even instantiate right for some reason)






Nagendra Kumar Busam
Hi Jim,








Is there any simple way to make it work. BTW, i am using LR 5.2.3








I have a requirement for which i need to add custom attribute like status which will have publish/pending as values.








Any inputs are much welcome








Thanks & Regards,

- Nagendra Kumar






Jim Klo : Yes I got this working, rather trivially.








Extend EditFileEntryAction and Update the Struts Mapping to use your new class.





Override updateFileEntry(...) by copying from the original then change this:
















to this:













Follow the pattern defined in edit_file_entry_form_extra_fields.jsp for adding your extra fields.





Compile and deploy.






Nagendra Kumar Busam : Thank you Jim, i will give it a try & update later about the status

No comments:

Post a Comment