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());
For more : http://www.liferaying.com/extending-web-form-portlet-%E2%80%93-adding-file-upload-control/
Can you please share th ConfigurationActionImpl.java and WebFormPortlet.java ?
ReplyDeleteIt would be really helpful.
Hi Himanshu,
ReplyDeletehere you can find the ConfigurationActionImpl.java I used in my portalet (a web form with file upload)
http://www.filippodelprete.com/2014/12/the-liferay-web-form-portlet-modified