问题
I would like to know all possible ways of displaying a DLFileEntry image in a jsp of a custom portlet. More specifically, I currently use the following way but I have some issues with DLFileEntry objects that have zero values for 'largeimageid'
DLFileEntry image = DLFileEntryLocalServiceUtil.getFileEntry(long_id);
String imageUrl = themeDisplay.getPathImage() + "/image_gallery?img_id=" + image.getLargeImageId() + "&t=" + WebServerServletTokenUtil.getToken(image.getLargeImageId());
Which are the alternatives of getting the image url without use of the large image id?
回答1:
Following is the pattern similar to the one that is used by Liferay Documents and Media portlet:
DLFileEntry image = DLFileEntryLocalServiceUtil.getFileEntry(long_id);
String imageUrl = "";
if (image != null) {
imageUrl =
PortalUtil.getPortalURL(request) + "/documents/" + image.getGroupId() + "/" +
image.getFolderId() + "/" + image.getTitle() + "/" + image.getUuid() + "?t=" +
System.currentTimeMillis();
}
Where PortalUtil.getPortalURL(request)
will return you base URL of your portal based on httpServletRequest
, System.currentTimeMillis()
will give you current time (miliseconds), and rest of the parameters are all available through DLFileEntry
object.
回答2:
I think this can help you
<%@ page import="com.liferay.portlet.documentlibrary.model.DLFolder" %>
<%@ page import="com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil" %>
<%@ page import="com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil" %>
<%@ page import="com.liferay.portlet.documentlibrary.model.DLFileEntry" %>
<%@ page import="java.util.List" %>
<%@ page import="com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil" %>
<%@ page import="com.liferay.portlet.imagegallery.model.IGImage" %>
<%@ include file="init.jsp" %>
<%
String igFolderId = portletPreferences.getValue("igFolderId", "0");
String cycleSpeed = portletPreferences.getValue("cycleSpeed", "1000");
String fxSpeed = portletPreferences.getValue("fxSpeed", "1000");
String type = portletPreferences.getValue("type", "fade");
String height = portletPreferences.getValue("height", "480");
String width = portletPreferences.getValue("width", "640");
List<IGImage> images = IGImageLocalServiceUtil.getImages(Long.valueOf(igFolderId));
%>
<c:choose>
<c:when test="<%= Long.valueOf(igFolderId) != 0%>">
<div id="<portlet:namespace />images">
<%
for (int i = 0; i < images.size(); i++) {
IGImage image = images.get(i);
%>
<img width="<%= width %>" height="<%= height %>" src="/image/image_gallery?img_id=<%=image.getLargeImageId()%>" alt="<%=image.getDescription()%>" <%= i == 0 ? "" : "style=\"display:none;\""%>/>
<%
}
%>
</div>
</c:when>
<c:otherwise>
<span class="portlet-msg-info">
Please configure this portlet.
</span>
</c:otherwise>
</c:choose>
<script type="text/javascript">
jQuery(
function() {
jQuery("#<portlet:namespace />images").cycle({
fx: '<%= type %>',
speed: <%= fxSpeed %>,
timeout: <%= cycleSpeed %>
});
}
);
</script>
Greetings!
来源:https://stackoverflow.com/questions/36863921/liferay-6-2-how-to-display-images-stored-in-documents-and-media