我知道您没有使用任何 Ajax 调用来保存数据,因此最简单的方法是设置请求属性并将控件重定向到 JSP,根据您可以执行 javascript 调用的请求属性的值。
在 liferay 中使用 javascript 与在任何其他 web 应用程序中使用它没有什么不同。
这是一些示例代码片段(不是整个代码):
在您的 portlet 的操作方法中:
// either set the renderParameter
actionRequest.setRenderParameter("saveSuccessfulPARAM", "SAVED");
// OR set the request attribute
actionRequest.setAttribute("saveSuccessfulATTR", "SAVED");
现在在成功保存后将呈现的 JSP 中,您可以拥有:
<%
// Note: You can use jstl or liferay tags instead of scriptlets if you want
String savedAttribute = renderRequest.getAttribute("saveSuccessfulATTR");
// OR you can use this, to fetch the renderParamter set by actionResponse
// String saveParameter = ParamUtil.getString(renderRequest, "saveSuccessfulPARAM")
if("SAVED".equals(savedAttribute)) { // if this is true show an alert
%>
<script>
// you can use <aui:script> tag as well
// .. your javascript code will go here
// better would be to run this script on DOM ready
alert("Data Saved Successfully!"); // for example
</script>
<%
}
%>
注意:最好javascript
在DOM
准备好的情况下运行。