文档
Liferay提供丰富知识资源,协助我们的社区与我们的技术更好地结合、应用。
Customizing JSPs Without Overriding the Original
If we can override a JSP with a hook plugin, why learn another way to accomplish the same thing? Good question. Each time original (overridden) file is changed by Liferay (for example, to fix a bug) after you override it, you’ll have to make those changes manually to your customized file, to benefit from them.
You can avoid this drawback and make your JSP modifications less invasive by rendering the original JSP into a string and modifying it dynamically afterwards. This way you can change minor elements of a JSP, like adding a new heading or button, without modifying your hook every time you upgrade Liferay. Here’s an example that customizes the search portlet. Specifically, it removes the ability to use a search provider in the browser:
<%@ include file="/html/portlet/search/init.jsp" %>
<liferay-util:buffer var="html">
<liferay-util:include page="/html/portlet/search/view.portal.jsp" />
</liferay-util:buffer>
<%
html = StringUtil.add(html, "Enjoy your search!", "\n");
%>
<%= html %>
Since this technique involves String manipulation, it’s mainly useful for making a small number of changes to a JSP.