Liferay 删除操作重定向到不可用的门户
Liferay Delete action redirecting to non available portal
我正在使用 DXP 门户 7.2 并使用 Service Builder 创建一个 CRUD 应用程序(课程)。当对我的数据 table 执行删除任务时,它工作正常,但门户页面重定向到不可用模式,例如它说:课程暂时不可用。
请让我知道我做错了什么。太感谢了!
我的 view.jsp 删除部分如下所示:
<%-- Delete action. --%>
<td>
<liferay-portlet:renderURL var="deleteURL">
<liferay-portlet:param name="mvcRenderCommandName" value="<%=ConstantsCommands.DELETE_COURSE %>"/>
<liferay-portlet:param name="backURL" value="<%= currentURL %>"/>
<liferay-portlet:param name="courseId" value="<%=
String.valueOf(course.getCourseId()) %>"/>
</liferay-portlet:renderURL>
<liferay-ui:icon-menu>
<liferay-ui:icon url="${deleteURL }" message="delete" >
</liferay-ui:icon>
</liferay-ui:icon-menu>
</td>
</tr>
下面是我用于删除的 MVC 渲染命令片段:
public class CourseDeleteMVCRenderCommand implements MVCRenderCommand{
@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {
long courseId = ParamUtil.getLong(renderRequest, "courseId");
try {
// Call service to delete the course.
_courseService.deleteCourse(courseId);
// Set success message.
SessionMessages.add(renderRequest, "courseDeleted");
}catch (PortalException pe) {
// Set error messages from the service layer.
SessionErrors.add(renderRequest, "serviceErrorDetails", pe);
}
return null;
}
@Reference
protected CourseService _courseService;
}
使用 MVCRenderCommand 和 liferay-portlet:actionURL,使用 render url 是可能的但错误的。
错误来自 renderURL 中缺少 mvcPath 参数。 Liferay 不知道目的地 jsp.
这里有一些示例
最重要的是:“不得在渲染操作中更改状态。”
您正在寻找一个 actionURL 和一个 MVCActionCommand 来执行操作(更改状态)。可能是一个单独的渲染,但通常在操作之前(例如显示一个特定的选项,可以删除它(如果你的主 UI 上没有删除按钮)
在 UI 呈现中实施破坏性操作是完全错误的,我建议您阅读您找到的任何教程以了解 portlet 中动作阶段和呈现阶段之间的区别。他们分开是有原因的。
通常,在执行 actionCommand 之后,立即呈现 UI。
最重要的是,MVCRenderCommand 和 MVCActionCommand 的关键部分是 @Component
注释(假设您采用 OSGi 路线)
我正在使用 DXP 门户 7.2 并使用 Service Builder 创建一个 CRUD 应用程序(课程)。当对我的数据 table 执行删除任务时,它工作正常,但门户页面重定向到不可用模式,例如它说:课程暂时不可用。 请让我知道我做错了什么。太感谢了! 我的 view.jsp 删除部分如下所示:
<%-- Delete action. --%>
<td>
<liferay-portlet:renderURL var="deleteURL">
<liferay-portlet:param name="mvcRenderCommandName" value="<%=ConstantsCommands.DELETE_COURSE %>"/>
<liferay-portlet:param name="backURL" value="<%= currentURL %>"/>
<liferay-portlet:param name="courseId" value="<%=
String.valueOf(course.getCourseId()) %>"/>
</liferay-portlet:renderURL>
<liferay-ui:icon-menu>
<liferay-ui:icon url="${deleteURL }" message="delete" >
</liferay-ui:icon>
</liferay-ui:icon-menu>
</td>
</tr>
下面是我用于删除的 MVC 渲染命令片段:
public class CourseDeleteMVCRenderCommand implements MVCRenderCommand{
@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {
long courseId = ParamUtil.getLong(renderRequest, "courseId");
try {
// Call service to delete the course.
_courseService.deleteCourse(courseId);
// Set success message.
SessionMessages.add(renderRequest, "courseDeleted");
}catch (PortalException pe) {
// Set error messages from the service layer.
SessionErrors.add(renderRequest, "serviceErrorDetails", pe);
}
return null;
}
@Reference
protected CourseService _courseService;
}
使用 MVCRenderCommand 和 liferay-portlet:actionURL,使用 render url 是可能的但错误的。
错误来自 renderURL 中缺少 mvcPath 参数。 Liferay 不知道目的地 jsp.
这里有一些示例
最重要的是:“不得在渲染操作中更改状态。”
您正在寻找一个 actionURL 和一个 MVCActionCommand 来执行操作(更改状态)。可能是一个单独的渲染,但通常在操作之前(例如显示一个特定的选项,可以删除它(如果你的主 UI 上没有删除按钮)
在 UI 呈现中实施破坏性操作是完全错误的,我建议您阅读您找到的任何教程以了解 portlet 中动作阶段和呈现阶段之间的区别。他们分开是有原因的。 通常,在执行 actionCommand 之后,立即呈现 UI。
最重要的是,MVCRenderCommand 和 MVCActionCommand 的关键部分是 @Component
注释(假设您采用 OSGi 路线)