论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Romain NIO
Create link for a document library in a portlet
2011年10月12日 上午12:02
答复

Romain NIO

等级: New Member

帖子: 4

加入日期: 2011年10月11日

最近的帖子

Hi emoticon,

I'm creating a portlet where users will be able to download files from the liferay document library. I'm able to retrieve and display alldocuments from the database (with com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil) but I want to display a link to download the file, how to do it ? any ideas ?emoticon

Regards,
Romain.
Oliver Bayer
RE: Create link for a document library in a portlet
2011年10月12日 上午1:26
答复

Oliver Bayer

等级: Liferay Master

帖子: 883

加入日期: 2009年2月18日

最近的帖子

Hi Romain,

why not using the already existing document library display portlet? If you want to have your own portlet you can refer to the dl display portlet on how to create the download links.

Greets Oli
Romain NIO
RE: Create link for a document library in a portlet
2011年10月12日 上午5:38
答复

Romain NIO

等级: New Member

帖子: 4

加入日期: 2011年10月11日

最近的帖子

Hi Olivier,

Ok I think this is a good idea, but where could I find the default liferay document portlet? How to see the source code??

Thanks,
Romain.
Oliver Bayer
RE: Create link for a document library in a portlet
2011年10月14日 上午1:27
答复

Oliver Bayer

等级: Liferay Master

帖子: 883

加入日期: 2009年2月18日

最近的帖子

Hi Romain,

sorry for the late reply.

You can find the document library portlet in the control panel or you can add the "document library display porlet" onto each page you like by using the "add application" menu. If you're using Liferay trunk or nightly builds I think it should be called "documents and media portlet" or sth that way (if I remember right).

The source code from the jsps can be found at "webapps \ ROOT \ html \ portlet \ document_library*". If you need the backend/ bean code download Liferay src and look out for DL* interfaces and classes like e.g. "DLFolder" which defines a folder or "DLFileEntry" which defines any element uploaded to the document library . If you want to add/ modify/ delete a file/ folder from the document library take a look at the DL*LocalServiceUtil classes e.g. DLFolderLocalServiceUtil.

HTH Oli
Romain NIO
RE: Create link for a document library in a portlet
2011年10月19日 下午11:47
答复

Romain NIO

等级: New Member

帖子: 4

加入日期: 2011年10月11日

最近的帖子

Thank you so much Olivier (and sorry for the delay..)

I found all files and the document portlet and I managed to find the link to download a file ! emoticon It possible to use it in an other portlet like that :
Java code
 1
 2DLFileEntry fileEntry =com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil.getFileEntry(fileId);
 3fileEntry = fileEntry.toEscapedModel();
 4
 5long fileEntryId = fileEntry.getFileEntryId();
 6long folderId = fileEntry.getFolderId();
 7String name = fileEntry.getName();
 8String extension = fileEntry.getExtension();
 9String title = fileEntry.getTitle();
10
11ThemeDisplay themeDisplay=null;
12if (renderRequest != null) {
13  themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
14}
15String fileUrl = themeDisplay.getPortalURL() + themeDisplay.getPathContext() + "/documents/" + themeDisplay.getScopeGroupId() + "//" + folderId +  "//" + HttpUtil.encodeURL(HtmlUtil.unescape(title));


HTML code
1<a href="<%=fileUrl %>">Download the file</a>


Thank olivier!!
Mittal Patoliya
RE: Create link for a document library in a portlet
2013年3月7日 上午4:07
答复

Mittal Patoliya

等级: New Member

帖子: 24

加入日期: 2011年12月14日

最近的帖子

It is fine we can create document link as suggested above.
But when we do not have themdisplay object how can we create that link?
What I have is just fileentry object inside my model listener?
Anyone has any idea?
Manish Yadav
RE: Create link for a document library in a portlet
2013年8月8日 上午6:31
答复

Manish Yadav

等级: Expert

帖子: 465

加入日期: 2012年5月26日

最近的帖子

Dear Romain NIO,

Create link for file works perfect .Can we create HyperLink for folder ???




Thanks & Regards
Manish Banwari lal yadav
Pawan Kumar
RE: Create link for a document library in a portlet
2013年8月23日 上午2:36
答复

Pawan Kumar

等级: New Member

帖子: 5

加入日期: 2013年8月5日

最近的帖子

DLFileEntry fileEntry =com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil.getFileEntry(fileId);

Can Any one Suggest me where we get it fileId value?

When I am using this code then give the following error:
fileId cannot be resolved to a variable...

Thanks,
Pawan
Akshy Kumar
RE: Create link for a document library in a portlet
2013年8月26日 上午4:59
答复

Akshy Kumar

等级: New Member

帖子: 13

加入日期: 2012年2月21日

最近的帖子

Hi Pawan,

I think it is fileEntryId.

Please use codes mentioned below, as an example to get fileEntryId.

First Create a long variable fileEntryId .


List<DLFileEntry> ls = com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil.getDLFileEntries(-1,-1);

for(DLFileEntry ts:ls)
{

fileEntryId = ts.getFileEntryId();

}

Thanks,