1.jsp:
<script type="text/javascript">
jQuery( function() { new Liferay.Upload({ allowedFileTypes: '<%= StringUtil.merge(PropsValues.DL_FILE_EXTENSIONS) %>', container: '#<portlet:namespace />fileUpload', fileDescription: '<%= StringUtil.merge(PropsValues.DL_FILE_EXTENSIONS) %>', fallbackContainer: '#<portlet:namespace />fallback', maxFileSize: <%= PropsValues.DL_FILE_MAX_SIZE %>, namespace: '<portlet:namespace />', uploadFile: '<liferay-portlet:actionURL windowState="<%= LiferayWindowState.POP_UP.toString() %>"><portlet:param name="struts_action" value="save请求的action" /><portlet:param name="<%= Constants.CMD %>" value="<%= Constants.ADD %>" /></liferay-portlet:actionURL>' }); } ); //验证上传文件类型 jQuery( function() { for (var i = 1; i < 4; i++) { jQuery("#<portlet:namespace />file" + i).change( function() { var value = jQuery(this).val(); if ((value != null) && (value != "")) { var extension = value.substring(value.lastIndexOf(".")).toLowerCase(); var validExtensions = new Array("<%= StringUtil.merge(PropsValues.DL_FILE_EXTENSIONS, "\", \"") %>"); if (jQuery.inArray(extension, validExtensions) == -1) { alert('<%= UnicodeLanguageUtil.get(pageContext, "document-names-must-end-with-one-of-the-following-extensions") %> <%= StringUtil.merge(PropsValues.DL_FILE_EXTENSIONS, ", ") %>'); jQuery(this).val(""); } } } ).change(); } } ); </script>
<div class="lfr-dynamic-uploader"> <div class="lfr-upload-container" id="<portlet:namespace />fileUpload"></div> </div> <div class="lfr-fallback" id="<portlet:namespace />fallback"> <fieldset class="block-labels"> <legend><liferay-ui:message key="upload-files" /></legend> <div class="ctrl-holder"> <label for="<portlet:namespace />file1"><liferay-ui:message key="file" /> 1</label> <input id="<portlet:namespace />file1" name="<portlet:namespace />file1" type="file" /> </div> <div class="ctrl-holder"> <label for="<portlet:namespace />file2"><liferay-ui:message key="file" /> 2</label> <input id="<portlet:namespace />file2" name="<portlet:namespace />file2" type="file" /> </div> <div class="ctrl-holder"> <label for="<portlet:namespace />file3"><liferay-ui:message key="file" /> 3</label> <input id="<portlet:namespace />file3" name="<portlet:namespace />file3" type="file" /> </div> </fieldset> <div class="button-holder"> <input type="submit" value="<liferay-ui:message key="save" />" /> <input type="button" value="<liferay-ui:message key="cancel" />" onClick="parent.location = '<%= HtmlUtil.escape("") %>';" /> </div>
2.liferay-portlet.xml :
<portlet> <portlet-name>workflow</portlet-name> <struts-path>workflow</struts-path> <configuration-action-class>com.liferay.workflow.action.ConfigurationActionImpl</configuration-action-class>
//导入swfupload.js <footer-portal-javascript>/html/js/misc/swfupload/swfupload.js</footer-portal-javascript> </portlet>
3.在liferay src的/html/js/misc/swfupload里找到swfupload.js,copy到war包的相应目录下。
以上三步可以使页面上显示出liferay的upload链接。
相关资源:Liferay workflow