Pages

Thursday, 12 April 2012

Getting entire O/P jsp in a string and replace some character or strings

<%@ include file="/html/portlet/blogs/init.jsp" %>

<h6>Some Special Header</h6>

<liferay-util:buffer var="myJspPage">
<liferay-util:include page="/html/portlet/blogs/view.portal.jsp" />
</liferay-util:buffer>
<!-- The below code will help you in replacing all the String "hello" in o/p jsp to HI.-->
<%
    String html = StringUtil.replace(myJspPage, "hello", "HI");
%>
<%= html %>

  1. Using the <liferay-util:buffer /> tag, the entire contents of the original Liferay JSP are placed in a string called "myJspPage".
  2.  Then there is logic which replaces any instance of the character string "hello" with another value. The result of this is then written out to the page. 
  3. Obviously, this can get unwieldy if there are a lot of changes that you need to make, but it is a strategy that has been used successfully.

No comments:

Post a Comment