[opencms-dev] javascript in resource-type fails to run after property edit and save from workspace

Clement Wee clement at elixirtech.com
Fri Feb 24 11:05:43 CET 2017


The relevant formatter jsp is:

<%@page buffer="none" session="false" trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<cms:formatter var="content">
<c:set var="svg" value="image-${cms.element.id}"/>
<div class="margin-bottom-30">
<div class="panel">
<h3>${cms.element.id}</h3>
</div>
<div class="image" id="${svg}">
<!--<svg width="400" height="110">
  <rect width="300" height="100"
style="fill:${content.value.BGColor};stroke-width:3;stroke:rgb(0,0,0)">
  Sorry, your browser does not support inline SVG.
</rect>
</svg>-->
</div>
<script>
var svg = d3.select("#${svg}").append("svg").attr({"width":"400",
"height":"110"});
var rectStyle =
"fill:${content.value.BGColor};stroke-width:3;stroke:rgb(0,0,0)";
var rect =
svg.append("rect")
.attr("width", 300)
.attr("height", 100)
.attr("style", rectStyle);
</script>
</div>
</cms:formatter>

On Fri, Feb 24, 2017 at 6:00 PM, Clement Wee <clement at elixirtech.com> wrote:

> Hi OpenCMS Admin,
>
> I am a new user of OpenCMS who is developing a module for a client who
> uses OpenCMS.
>
> I have deisgned a simple resource-type to test out D3.JS library.
>
> I coded in an inline script within the resource-type JSP itself, because I
> don't know whether EL is supported in Head Includes Inline javascript.
>
> When I first load a page with an element instance of the module, the SVG
> created using D3 shows up, but once I edit the properties of that element
> via the pencil-edit and save, the SVG disappears, only showing up again
> when I refresh the page.
>
> Can you help me resolve this issue?
>
> Regards,
> Clement Wee
> Singapore
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20170224/df9bafc5/attachment.htm>


More information about the opencms-dev mailing list