In Liferay Portal, Web Form Portlet is used to create custom forms but the types of field that can be created are limited. One such missing field type is File Upload Control. It’s a common requirement to have file upload control in forms.
Following are the steps to add File Upload Control to Web Form Portlet -
1. Add a new field type to edit_field.jsp
<aui:option selected='<%= fieldType.equals("file") %>' value="file"><liferay-ui:message key="file" /></aui:option>
2. Accordingly update the view.jsp to render the your new field
<c:when test='<%= fieldType.equals("file") %>'>
<aui:input cssClass='<%= fieldOptional ? "optional" : StringPool.BLANK %>' label=" <%=HtmlUtil.escape(fieldLabelDisplay) %>" name="<%= fieldName %>" type="file" value="<%=HtmlUtil.escape(fieldValue) %>"/>
</c:when>
3. Set the preferences for this field in ConfigurationActionImpl.java
boolean isFileUpload = false;
if ("file".equals(fieldType)) {
isFileUpload = true;
}
preferences.setValue("isFileUpload", String.valueOf(isFileUpload));
4. Finally get the file in WebFormPortlet.java and proceed with your implementation…
File file = uploadRequest.getFile(paramName.toString());
Proceed we the implementation with file object for example save to document library, send in mail etc.
[...] um post com algo relacionado a modificar o webform para colocar um campo de file upload aqui [...]
ReplyDeleteHi there, I discovered your website by the use of Google whilst looking for a comparable topic, your web site got here up, it appears great. I've bookmarked it in my google bookmarks.
ReplyDeleteFine information, I will be checking back again frequent to look around for refreshes.
ReplyDeleteThanks for liking the stuff...
ReplyDeleteI'll try to keep it updated and continue to provide latest and meaningful contents...
ReplyDeleteWonderful document along with very easy for you to figure out justification. Exactly how can My spouse and i attempt receiving concur for you to submit element in the document inside my future news letter? Getting suitable credit history to you personally your publisher along with web page link on the blog won't certainly be a trouble.
ReplyDeleteCan you post example of your WebFormPortlet.java or at least part responsible for file handling ?
ReplyDeleteI consider this article one of the most thought-provoking articles I've read over time. Your views and ideas are both unique and informative I've learned something through this information.
ReplyDeleteI'm happy I found this blog, I think it's the most useful on the matter so far. I also run a site and if you want to ever get serious in a little bit of guest writing for me, feel free to let me know, i'm always looking for people to check out my site. Stop by and leave a comment sometime!
ReplyDeleteSuperb post and additionally simple to make sure you comprehend description. Exactly how can Document keep performing obtaining authorization to make sure you publish part for the guide into my approaching e-newsletter? Providing correct credit scores in your direction all the creator and additionally url to website wouldn't deemed a dilemma.
ReplyDeletecouldnt find where to put that line (Step 4)
ReplyDeleteAnywhere in your portlet class where you want to make use of the uploaded file
ReplyDeletehi there, i couldn't find where to put the number 3 lines...pls help.thank you
ReplyDeletehi there, i need to have a text field appear once a radio button is pressed, is it possible?if it is possible, please let me know how can i do this...thank you..
ReplyDeleteCathy
ReplyDeleteIts pretty easy to implement. just have radio button and text box on the form. Use onClick event of radio button to manage the visibility of textbox.
In the ConfigurationActionImpl.java where other preferences are being persisted
ReplyDeleteoh thank.I'll try about that..so far liferay web form portlet is very useful to me.
ReplyDeletehi, im having trouble with the same problem of cathy about radio button, i tried to put 3 radio buttons ,there appear a textbox once the radio button is click but the problem is it applies to all web form portlet that i have.how can i limit it a particular portlet.looking forward to your response.thank u.
ReplyDeleteBexx
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog and posts. Anyway I’ll be subscribing your feed and I hope to read your blog again.
ReplyDeletePretty good post. I just stumbled upon a webpage not to mention wanted towards state who I have truly enjoyed reading a website not to mention articles. Anyway I’ll turn out to be subscribing a give food not to mention I just desire towards read a website yet again.
ReplyDelete[...] can get here.Could you create new thread for new post. Already some discussions are going on. Create new one [...]
ReplyDelete[...] You can get here [...]
ReplyDeleteHi,
ReplyDeleteWhen I try to get the file using this line,
File file = uploadRequest.getFile(paramName.toString());
uploadRequest could not be resolved.
Do I have to create my own method (uploadRequest) inside WebFormPortlet.java?
Or should this line work by itself?
Thank you in advance for any feedback.
What's Happening we are not used to this, I stumbled upon this Ive think it is absolutely helpful and possesses helped me out loads. Hopefully to contribute & assist other users like its solved the problem. Well done.
ReplyDeleteHi...thnx for the great post....
ReplyDeletei am unable to pass "file" object in ur last point no.4.
kindly tell me where to place file object....i mean where to put this code...????
thnx !!
Hi Aira !!
ReplyDeletedid u get the solution for this...?? if yes, plz let me know...
thnx !!!!
Hi,
ReplyDeleteHas anyone figured out how to use:
File file = uploadRequest.getFile(paramName.toString());
I use it on the SaveData method in WebFormPortlet but I get null.
Step 4 is a bit vague. Anyone have a concrete example?
ReplyDeleteplease write whole of ConfigurationActionImpl.java here.tnx
ReplyDeleteHello There ,
ReplyDeleteIts very good post.I have used it but I am stuck at step 4 where i have written following code snippet to save uploaded file to document library.But it does not save my file in Test folder i have created. Please reply.
UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
File file = uploadPortletRequest.getFile("file");
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);
String contentType = MimeTypesUtil.getContentType(file);
InputStream inputStream = new FileInputStream(file);
Folder folderName = DLAppLocalServiceUtil.getFolder(parentRepositoryId, parentFolderId, "Test");
long folderId = folderName.getFolderId();
long repositoryId = folderName.getRepositoryId();
FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(themeDisplay.getUserId(),
repositoryId, folderId, file.getName(),
contentType, file.getName(), "description",
"changeLog", inputStream, file.length(), serviceContext);
Very good post.
ReplyDeleteIn view.jsp file, add enctype=”multipart/form-data” in aui:form