adessoSE / wicked-charts

Beautiful and interactive javascript charts for Java-based web applications.
Apache License 2.0
90 stars 48 forks source link

JavaScriptParameters don't parse escaped double quotes #41

Closed acgrama closed 8 years ago

acgrama commented 10 years ago

When adding a Javascript expression on a LiveDataSeries, double quotes are not parsed correctly (expression is taken to be a string), while using simple quotes works. This happens even though the double quotes are escaped.

I have noticed this while using a drop down list to select an id and trying to print it out in the LiveDataSeries' update() method.

HTML snippet:

...
<form wicket:id="form">
    <p>Select cable:</p>
    <select id="cableselect" wicket:id="cable">
        <option></option>
    </select>
    <input wicket:id="start" type="submit" value="Start"/>
</form>
<div wicket:id="tempgraph"></div>
...

Wicket code snippet:

...
List<String> cableIDs = Arrays.asList("1", "2", "3", "4", "5");
form.add(new DropDownChoice("cable", new PropertyModel(cd, "cableID"), cableIDs));        
...
series = new LiveDataSeries(options, 1000) {            
    @Override
    public Point update(final LiveDataUpdateEvent event) {
        JavaScriptParameters params = event.getParameters();
        System.out.println("Cable ID: " + params.getParameterValue("cableID"));
        return new Point(new Date().getTime(), Math.random());
    }
}.addJavaScriptParameter("cableID", "document.getElementById(\"cableselect\").selectedIndex");
options.addSeries(series);    
chart = new Chart("tempgraph", options);
add(chart);
...

In the console, the update() method of LiveDataSeries prints:

Cable ID: document.getElementById("cableselect").selectedIndex

If I change it to addJavaScriptParameter("cableID", "document.getElementById('cableselect').selectedIndex"), it works perfectly:

Cable ID: 3

My configuration: Apache Wicket 6.16.0 Wicked Charts POM Dependency:

<artifactId>wicked-charts-wicket6</artifactId>
<version>1.5.0</version>
thombergs commented 10 years ago

I added a hint in the javadoc to use single quotes for now.