问题
I tried to add a link for delete an entry of my data lists respective to tutorial1 and tutorial2 but I missed something.
<h1>Task Summary</h1>
Hallo "${reserved_record_set_name}".
<#assign DDLRecordLocalService = serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService")>
<#assign groupService = serviceLocator.findService("com.liferay.portal.service.GroupLocalService")>
<#assign layoutService = serviceLocator.findService("com.liferay.portal.service.LayoutLocalService")>
<#assign records = DDLRecordLocalService.getRecords(reserved_record_set_id)>
<ul>
<#if records?has_content>
<#list records as cur_record>
<li><em>${cur_record.getFieldValue("Author", locale)}</em> will help with
<a href="${ddmUtil.getDisplayFieldValue(themeDisplay, cur_record.getFieldValue("DataSet", locale), cur_record.getFieldType("DataSet"))}">${languageUtil.format(locale, "download-x", "Data Set")}</a>
<#assign controlPanelGroup = groupService.getGroup(portalUtil.getDefaultCompanyId(), "Control Panel")>
<#assign controlPanelPlid = layoutService.getDefaultPlid(controlPanelGroup.getGroupId(), true)>
<#assign portletActionURL = portletURLFactory.create(request,"167",controlPanelPlid,"ACTION_PHASE")>
${portletActionURL.setParameter("recordId", "${cur_record.getRecordId()}")}
${portletActionURL.setParameter("cmd", "delete")}
${portletActionURL.setParameter("struts_action", "/dynamic_data_lists/edit_record")}
${portletActionURL.setParameter("redirect", "${themeDisplay.getPortalURL()}${themeDisplay.getURLCurrent()}")}
<#if permissionChecker.hasPermission(scopeGroupId, "com.liferay.portlet.dynamicdatalists.model.DDLRecordSet", "${reserved_record_set_id}", "DELETE")>
<form action="${portletActionURL}" method="POST">
<input type="submit" value="Delete">
</form>
</#if>
</li>
</#list>
</#if>
This is how the view looks like
and after I click the delete button I get a error
回答1:
That's quite an interesting case, it took me some time to figure it out. This code works for me (on 6.2 CE GA2):
<#assign controlPanelGroup = groupService.getGroup(portalUtil.getDefaultCompanyId(), "Control Panel")>
<#assign controlPanelPlid = layoutService.getDefaultPlid(controlPanelGroup.getGroupId(), true)>
<#assign portletActionURL = portletURLFactory.create(request,"167",controlPanelPlid,"ACTION_PHASE")>
${portletActionURL.setParameter("recordId", "${cur_record.getRecordId()}")}
${portletActionURL.setParameter("cmd", "delete")}
${portletActionURL.setParameter("struts_action", "/dynamic_data_lists/edit_record")}
${portletActionURL.setParameter("redirect", "${themeDisplay.getPortalURL()}${themeDisplay.getURLCurrent()}")}
<#if permissionChecker.hasPermission(scopeGroupId, "com.liferay.portlet.dynamicdatalists.model.DDLRecordSet", "${reserved_record_set_id}", "DELETE")>
<form action="${portletActionURL}" method="POST">
<input type="submit" value="Delete">
</form>
</#if>
The request has to go via POST, otherwise Liferay will print This URL can only be invoked using POST
to the logs. That's why it is a form (but you can naturally submit form with the link).
来源:https://stackoverflow.com/questions/24492606/dynamic-data-lists-display-template