Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDATA error with partial update #32

Open
thombergs opened this issue Apr 21, 2014 · 0 comments
Open

CDATA error with partial update #32

thombergs opened this issue Apr 21, 2014 · 0 comments

Comments

@thombergs
Copy link
Member

Reported by rmillet42, Apr 11, 2014
What steps will reproduce the problem?

  1. Use wicked-charts-jsf21 with JSF ajax partial update

What is the expected output? What do you see instead?
CDATA is not encoded in the response, breaking it.

What version of the product are you using? On what operating system?
Wicked-charts revision 303 (1.5.1-SNAPSHOT)
Mojarra 2.2.6
Tomcat 7

Attached a patch working with my settings (not tested with other JSF implementations) of wicked-charts-jsf21/src/main/java/com/googlecode/wickedcharts/jsf21/UIChart.java

Index: src/main/java/com/googlecode/wickedcharts/jsf21/UIChart.java
===================================================================
--- src/main/java/com/googlecode/wickedcharts/jsf21/UIChart.java    (revision 303)
+++ src/main/java/com/googlecode/wickedcharts/jsf21/UIChart.java    (working copy)
@@ -44,9 +44,6 @@
    private Theme theme;
    private String themeUrlRef;

-   private final static String PRE_JS = "\n<script type=\"text/javascript\">\n/*<![CDATA[*/\n$(function() {\n";
-   private final static String POST_JS = "\n;});\n/*]]>*/\n</script>";
-
    private static final Feature[] SUPPORTED_FEATURES = new Feature[] {

    };
@@ -81,13 +78,19 @@
        // include Theme JS
        this.addThemeJavaScript(writer, renderer);

-       writer.append(UIChart.PRE_JS);
-       // include Chart JS
-       writer.append(MessageFormat.format(
-               "var {0} = {1};\nvar {2} = new Highcharts.Chart({0});",
-               optionsVarname, renderer.toJson(options), chartVarname));
+       StringBuffer sb = new StringBuffer(512);
+       sb.append("//<![CDATA[\n");
+       sb.append("$(function() {\n");
+       sb.append(MessageFormat.format(
+                        "var {0} = {1};\nvar {2} = new Highcharts.Chart({0});",
+                        optionsVarname, renderer.toJson(options), chartVarname));
+       sb.append("\n;});\n");
+       sb.append("//]]>\n");

-       writer.append(UIChart.POST_JS);
+       writer.startElement("script", this);
+       writer.writeAttribute("type", "text/javascript", "type");
+       writer.writeText(sb.toString(), this, null);
+       writer.endElement("script");
    }

    private void addThemeJavaScript(ResponseWriter writer, JsonRenderer renderer)
@@ -101,11 +104,19 @@
                            this.getThemeUrlRef()));

        } else if (this.getTheme() != null) {
-           writer.append(UIChart.PRE_JS);
-           writer.append(MessageFormat.format("Highcharts.setOptions({0})",
-                   renderer.toJson(this.getTheme())));
-           writer.append(UIChart.POST_JS);

+           StringBuffer sb = new StringBuffer(512);
+           sb.append("//<![CDATA[\n");
+           sb.append("$(function() {\n");
+           sb.append(MessageFormat.format("Highcharts.setOptions({0})",
+                                                renderer.toJson(this.getTheme())));
+           sb.append("\n;});\n");
+           sb.append("//]]>\n");
+
+           writer.startElement("script", this);
+           writer.writeAttribute("type", "text/javascript", "type");
+           writer.writeText(sb.toString(), this, null);
+           writer.endElement("script");
        }
    }


@thombergs thombergs modified the milestone: 1.6.0 Apr 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants