liferay中使用liferay-ui进行文件上传
来源:互联网 发布:淘宝历史订单无故消失 编辑:程序博客网 时间:2024/06/05 01:13
在liferay中使用liferay-ui进行文件上传比较容易,效果还不错,下面我们来看都需要哪些代码
1,jsp页面中,见下面代码
<%
for (int i = 1; i <= 5; i++) {
%>
<tr>
<td>
<liferay-ui:message key="file" /> <%= i %>
</td>
<td>
<input name="<portlet:namespace />msgFile<%= i %>" size="70" type="file" />
</td>
</tr>
<%
}
%>
通过循环控制上传文件个数
2,我们再看action的部分,如下代码
List files = new ArrayList();
if (attachments) {
UploadPortletRequest uploadReq =
PortalUtil.getUploadPortletRequest(req);
for (int i = 1; i <= 5; i++) {
File file = uploadReq.getFile("msgFile" + i);
String fileName = uploadReq.getFileName("msgFile" + i);
byte[] bytes = FileUtil.getBytes(file);
if ((bytes != null) && (bytes.length > 0)) {
ObjectValuePair ovp = new ObjectValuePair(fileName, bytes);
files.add(ovp);
}
}
}
将request中的文件存放在list中
3,最后在service进行保存,如下代码
if (files.size() > 0) {
long companyId = issue.getCompanyId();
String portletId = CompanyImpl.SYSTEM_STRING;
long groupId1 = GroupImpl.DEFAULT_PARENT_GROUP_ID;
long repositoryId = CompanyImpl.SYSTEM;
String dirName = issue.getAttachmentsDir();
try {
try {
dlService.deleteDirectory(
companyId, portletId, repositoryId, dirName);
}
catch (NoSuchDirectoryException nsde) {
}
dlService.addDirectory(companyId, repositoryId, dirName);
for (int i = 0; i < files.size(); i++) {
ObjectValuePair ovp = (ObjectValuePair)files.get(i);
String fileName = (String)ovp.getKey();
byte[] byteArray = (byte[])ovp.getValue();
try {
dlService.addFile(
companyId, portletId, groupId1, repositoryId,
dirName + "/" + fileName, StringPool.BLANK,
new String[0], byteArray);
}
catch (DuplicateFileException dfe) {
}
}
}
catch (RemoteException re) {
throw new SystemException(re);
}
}
这样通过documentlibrary的DLService进行文件保存
- liferay中使用liferay-ui进行文件上传
- liferay-文件上传处理
- Liferay文件的上传
- 在Liferay中使用Ajax
- 在Liferay中使用Log4j
- Liferay
- Liferay
- Liferay
- liferay
- Liferay
- [Liferay] Liferay 国际化 - 使用 LanguageUtil
- [Liferay]Portlet 之间使用 PortletSession 进行通信
- liferay UI 标签
- liferay UI 标签
- Liferay Alloy UI
- liferay-ui:tabs
- liferay中 liferay-ui:input-asset-links不能正常选择类型的问题
- Liferay中使用Velocity的注意事项
- 海洋进行核武器试验的视频
- SQL里利用自定义函数Group By 数据得到字符串
- oracle trigger for table on commit
- 对于之前commons-beanutils-jesse包的更新
- SQL Server的几个安全问题
- liferay中使用liferay-ui进行文件上传
- 今天正式加入CSDN
- ClientID/UniqueID/ID的区别
- NASM源代码分析之NASM中的指令表示(1)
- Linux下Makefile的automake生成全攻略
- 一些测试网站性能的在线免费工具
- 注意生活
- C#中资源文件管理字符串
- 飞行人!