tags:

views:

477

answers:

2

I'm using jsp:include inside json-taglib's json:property element. The problem with this is that all HTML elements from included JSP page gets stripped at some point and only plain text remains. I have already stripped all newlines so the result shoud be valid JSON data.

How do I get full HTML returned by json-taglib?

Below is a snippet demonstrating the situation.

<%@ page language="java" %>
<%@ page pageEncoding="UTF-8" %>
<%@ page contentType="text/html; charset=UTF-8" %>

<%@ taglib uri="http://www.atg.com/taglibs/json" prefix="json" %>

<json:object>
  <json:property name="id" value="${element.id}" />
  <json:property name="html" escapeXml="false">
    <jsp:include page="/templates/generate-component.jsp">
      <jsp:param name="element_id" value="${element.id}" />
    </jsp:include>
  </json:property>
</json:object>
A: 

Hi,

Maybe you should encode the data passed to json-taglib.

Regards.

ATorras
Perhaps so. Any suggestions where to do the encoding? There is no escaping-related attribute in jsp:include, which would suit better than perfectly...
Jawa
The JSTL <c:out escapeXml="true"> could do the trick...
ATorras
IIRC, escapeXml="true" works on the directly included page but fails with the nested includes. Plus then the JSON data must be manually unescaped in javascript, which is a bit cumbersome.
Jawa
A: 

One solution is to wrap the jsp:include in <c:out> tag and (mis)use the body-as-default-value, like so:

<c:out value="${null}">
  <jsp:include ...>
    <jsp:param ... />
  </jsp:include>
</c:out>

However, this won't work in a situation where the included JSP itself uses jsp:include.

Jawa