此问题与Liferay中的Document and Media Portlet有关。
我正在使用Liferay 6.1.2-ce-ga3。
我有一个portlet,它允许显示在Liferay的文档和媒体portlet中创建的目录的文档列表。
此portlet项目允许在表格中显示文档列表,并使用Liferay和JavaScript下载多个文件。
当我部署新版本或更新liferay portlet时,我遇到以下问题:
com.liferay.portlet.documentlibrary.NoSuchFolderException:No DLFolder 密钥{groupId = 10165,parentFolderId = 0,name =}
存在
在Document and Media Portlet中,该目录已存在。要解决NoSuchFolder问题,我删除旧文件夹,然后创建一个新文件夹。
未捕获(在promise中)错误:未定义的Ajax错误:404 Introuvable 在XMLHttpRequest.n.onreadystatechange
此问题与此问题有关:Why i am getting Ajax error for undefined : 404 Not Found?
要修复多重下载问题,我会删除所有文件,然后添加新文件。
我认为这是liferay本身的一个问题。
我检查了文件夹和文件,它们已经存在。
每当我部署新版本或更新portlet liferay时,我都会遇到问题。我每次都要删除文件夹和这些文件并再次创建它。
重新创建文件没有意义。
如何解决这些问题NoSuchFolderException
和Ajax error for undefined 404
?
java代码:
public class MyPortlet extends MVCPortlet {
private static long ROOT_FOLDER_ID = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
PortletPreferences pref = renderRequest.getPreferences();
String folders_cfg = pref.getValue("foldersKey", "");
FOLDERS_NAME = Collections.unmodifiableList(Arrays.asList(folders_cfg.split(",")));
.
.
.
List<DLFileEntry> listFiles = new ArrayList<DLFileEntry>();
List<DLFileEntry> listContextFiles = new ArrayList<DLFileEntry>();
try {
listFiles = getAllFiles(themeDisplay);
listContextFiles = getAllFiles(themeDisplay);
} catch (PortalException e1) {
e1.printStackTrace();
} catch (SystemException e1) {
e1.printStackTrace();
}
.
.
.
for(DLFileEntry file : listFiles){
...
}
List<DLFileEntry> list = getListFiles(listContextFiles, listAllDate);
renderRequest.setAttribute("listFiles", list);
super.doView(renderRequest, renderResponse);
}
private List<DLFileEntry> getListFiles(List<DLFileEntry> listContextFiles,
List<Date> listAllDate) {
List<DLFileEntry> list = new ArrayList<DLFileEntry>();
for (int i = 0; i <listContextFiles.size(); i++) {
listContextFiles.get(i).setModifiedDate(listAllDate.get(i));
list.add(listContextFiles.get(i));
}
return list;
}
public List<DLFileEntry> getAllFiles(ThemeDisplay themeDisplay) throws PortalException, SystemException{
List<DLFileEntry> fileEntries = new ArrayList<DLFileEntry>();
long globalGroupId = GroupLocalServiceUtil.getCompanyGroup(PortalUtil.getDefaultCompanyId()).getGroupId();
for(String folderName : FOLDERS_NAME){
try {
Folder folder = DLAppServiceUtil.getFolder(globalGroupId, ROOT_FOLDER_ID, folderName);
fileEntries.addAll(DLFileEntryLocalServiceUtil.getFileEntries(globalGroupId,folder.getFolderId(),-1, -1, null));
for(Long subFolder : DLAppServiceUtil.getSubfolderIds(globalGroupId, folder.getFolderId())){
fileEntries.addAll(DLFileEntryLocalServiceUtil.getFileEntries(globalGroupId, subFolder,-1, -1, null));
}
} catch (Exception e) {
e.printStackTrace();
}
}
return fileEntries;
}
}
jsp代码:
<form action="#" id="download_form">
<liferay-ui:search-container orderByCol="<%=sortByCol%>"
orderByType="<%=sortByType%>" iteratorURL="<%=actionURL%>"
delta="10" emptyResultsMessage="no-documents">
<liferay-ui:search-container-results>
<%
List<DLFileEntry> fileList = (List<DLFileEntry>) request.getAttribute("listFiles");
OrderByComparator orderByComparator = OrderByComparatorFactoryUtil.create("DLFileEntry", "modifiedDate", false);
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
OrderByComparator orderByComparatorDate =
CustomComparatorUtil.getFileOrderByComparator(sortByCol, sortByType);
Collections.sort(fileList, orderByComparatorDate);
results = ListUtil.subList(fileList, searchContainer.getStart(),
searchContainer.getEnd());
if (fileList.size()< total)
{
total = fileList.size();
}
pageContext.setAttribute("results", results);
pageContext.setAttribute("total", total);
%>
</liferay-ui:search-container-results>
<liferay-ui:search-container-row modelVar="file"
className="DLFileEntry">
<%
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
String pdfUrl = "", excelUrl = "";
String logo ="", vendor="", technology="", productType="", flashType="", fileTitle="", fileUrl="", file_name="";
long globalGroupId = GroupLocalServiceUtil.getCompanyGroup(PortalUtil.getDefaultCompanyId()).getGroupId();
if(file.getExtension().equalsIgnoreCase("pdf"))
pdfUrl = "<a target='_blank' href='"+ themeDisplay.getPortalURL() + themeDisplay.getPathContext() + "/documents/" + globalGroupId + StringPool.SLASH + file.getUuid()+"' ><img src='/flash-table-portlet/images/pdf.png' width='20px'/> </a>";
else if(file.getExtension().equalsIgnoreCase("xlsx") || file.getExtension().equalsIgnoreCase("xls") || file.getExtension().equalsIgnoreCase("csv") )
excelUrl = "<a target='_blank' href='"+ themeDisplay.getPortalURL() + themeDisplay.getPathContext() + "/documents/" + globalGroupId + StringPool.SLASH + file.getUuid()+"' ><img src='/flash-table-portlet/images/excel.png' width='20px'/> </a>";
String fileDate = dateFormat.format(file.getModifiedDate());
String logoUrl = "";
String maxWidth = "120px";
String marginLeft = "0px";
String marginTop = "0px";
try{
Map<String, Fields> fieldsMap = file.getFieldsMap(file.getFileVersion().getFileVersionId());
Collection<Fields> collectionFields = fieldsMap.values();
for (Fields fields : collectionFields) {
vendor = fields.get("vendor").getValue().toString().replace("[\"", "").replace("\"]", "");
if(vendor.equalsIgnoreCase("other"))
logo="<strong>Other</strong>";
else
{
logoUrl = "/flash-table-portlet/images/vendor/"+vendor.toLowerCase()+".gif";
logo = "<div class='crop'><img src='"+logoUrl
+"' style='margin-left: "+marginLeft
+";margin-top: "+marginTop
+";max-width: "+maxWidth
+";' alt='"+vendor.toLowerCase()+"'/></div>";
}
technology= fields.get("technology").getValue().toString().replace("[\"", "").replace("\"]", "");
productType = fields.get("producttype").getValue().toString().replace("[\"", "").replace("\"]", "");
flashType = fields.get("flashtype").getValue().toString().replace("[\"", "").replace("\"]", "");
if(fields.get("optionaldate") != null ) {
DateFormat inputFormat = new SimpleDateFormat("yyyy/MM/dd");
Date optionalDate = inputFormat.parse((String) fields.get("optionaldate").getValue());
fileDate = dateFormat.format(optionalDate);
}
}
}catch(Exception ex){
ex.printStackTrace();
}
fileUrl = themeDisplay.getPortalURL() + themeDisplay.getPathContext() + "/documents/" + globalGroupId + StringPool.SLASH + file.getUuid();
file_name = file.getTitle() + "." + file.getExtension();
fileTitle = "<div style='display:inline'>"+file.getTitle()+"</div>";
%>
<liferay-ui:search-container-column-text cssClass="width-1">
<input name="<%=file_name%>" type="checkbox" data-url="<%=fileUrl%>"/>
</liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-text name='model'
cssClass="width-15" value="<%=fileTitle%>" />
<liferay-ui:search-container-column-text name='executive-summary'
cssClass="width-4" value="<%=pdfUrl%>" />
<!-- some other search-container-column-text --> ...
</liferay-ui:search-container-row>
<liferay-ui:search-iterator
searchContainer="<%= searchContainer %>"
paginate="${fn:length(listFiles) ge 10}" />
<div style="position: relative;">
<aui:button cssClass="download-button" id="download_files" type="submit" value="Download"></aui:button>
</div>
</liferay-ui:search-container>
</form>
文件夹问题:有时会出现NoSuchFolderException问题,我重命名了文件夹名称以重现错误。
com.liferay.portlet.documentlibrary.NoSuchFolderException:No DLFolder 密钥{groupId = 10256,parentFolderId = 0,name = CONTEXT Flash} at com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistenceImpl.findByG_P_N(DLFolderPersistenceImpl.java:4653) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ... 在 com.liferay.portlet.documentlibrary.service.DLAppServiceUtil.getFolder(DLAppServiceUtil.java:924) 在 com.context.portlet.MyPortlet.getAllFiles(MyPortlet.java:229) 在com.context.portlet.MyPortlet.doView(MyPortlet.java:64)
此问题与此行有关:Folder folder = DLAppServiceUtil.getFolder(globalGroupId, ROOT_FOLDER_ID, folderName);
文件问题:当我选择多个文件并点击下载时,我遇到了此错误404 Introuvable。
GET http://localhost:8080/undefined 404(Introuvable)Uncaught(in promise)错误:未定义的Ajax错误:404 Introuvable at XMLHttpRequest.n.onreadystatechange (jszip-utils.min.js BROWSERID =其他&安培; minifierType = JS&安培; languageId = EN_US和b = 6102&amp; T公司= 1511981499426:10) GET http://localhost:8080/undefined 404(Introuvable)错误:Ajax undefined的错误:404 Introuvable at XMLHttpRequest.n.onreadystatechange (jszip-utils.min.js BROWSERID =其他&安培; minifierType = JS&安培; languageId = EN_US和b = 6102&amp; T公司= 1511981499426:10)
在 docroot / html 目录中,我有以下文件:
1- init.jsp文件 允许初始化变量,它包含类似String folders_cfg = GetterUtil.getString (portletPreferences.getValue ("foldersKey", "CONTEXT Flash"));
的行。语境Flash是文件夹的名称。
2-我有一个配置文件 configuration.jsp ,其中包含这样的行<aui:input name="preferences--foldersKey--" label="Folder List" type="text" required="true" value="<%= folders_cfg %>" style="width: 100%;"/>
3-我还有一个 view.jsp文件 ,该视图部分包含liferay UI Taglib以显示文档表。
FOLDERS_NAME变量在MyPortlet类的doView()方法中初始化:
List<String> FOLDERS_NAME = new ArrayList<String>();
@Override
public void doView()...{
PortletPreferences pref = renderRequest.getPreferences();
String folders_cfg = pref.getValue("foldersKey", "");
FOLDERS_NAME = Collections.unmodifiableList(Arrays.asList(folders_cfg.split(",")));
.
.
}
在 docroot / WEB-INF / src 目录中,我有两个文件:MyPortlet.java和ConfigurationActionImpl.java。
ConfigurationActionImpl.java:
public class ConfigurationActionImpl extends DefaultConfigurationAction{
@Override
public void processAction( PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
super.processAction(portletConfig, actionRequest, actionResponse);
PortletPreferences prefs = actionRequest.getPreferences();
}
}
PortletPreferences pref = renderRequest.getPreferences();
中变量pref的内容: