|
How to use get/set custom attributes on page reload |
Posted by Gert Thomas on Mar-14-2014 10:59 |
|
Any advise on the following will be appreciated:
I have a line graph with 10 lines on it, I also have 10 checkboxes on the JSP that the user
can click to show or hide each line.
Everytime a user clicks a checkbox I call a javascript function which adds the values of the
checkboxes as parameters to the url and then reloads the page. This works but if I zoom in
on the graph it throws an error.
I know from other posts on the forum that the error is because ChartDirector cuts off part
of the url if it is to long and with all the parameters I have I have run in to this issue.
I am trying to now use setCustomAttr() and getCustomAttr() with WebChartViewer and
JsChartViewer to achieve this functionality.
So when the user clicks a checkbox can I call the javascript function and have something
like:
var viewer = JsChartViewer.get(<% viewer.id %>);
viewer.setCustomAttr("checkbox1", "true");
viewer.setCustomAttr("checkbox2", "false");
//...set attr for each checkbox...
and then reload the page.
How would I retreive these attributes in the JSP when it has reloaded, something like?
WebChartViewer viewer = new WebChartViewer(request, "chartA")
String checkbox1 = viewer.getCustomAttr(checkbox1);
I am trying something like the above but it is obviously not working and sorry if the question
is a bit vague but how could I get this to work?
Thanks. |
Re: How to use get/set custom attributes on page reload |
Posted by Peter Kwan on Mar-15-2014 00:22 |
|
Hi Gert,
There is a sample code "Zooming and Scrolling with Track Line (Web)" that comes with
ChartDirector that uses checkboxes to select lines. See
http://www.advsofteng.com/doc/cdjava.htm#zoomscrolltrackweb.htm
The example use the setCustomAttr method in the PreUpdate event, so the state of the
checkboxes are always copied to the custom attributes before the update request is sent
to the server. In the sample code, it is done using:
viewer.attachHandler("PreUpdate", function() {
var checkBoxes = ["data0CheckBox", "data1CheckBox", "data2CheckBox"];
for (var i = 0; i < checkBoxes.length; ++i)
viewer.setCustomAttr(checkBoxes[i],
document.getElementById(checkBoxes[i]).checked ? "T" : "F");
});
On the server side, the checkbox state is retreived using something like:
WebChartViewer viewer = new WebChartViewer(request, "chart1");
String checkbox0 = viewer.getCustomAttr("data0CheckBox");
So the method you mentioned should work if the details are correct. For example, the:
var viewer = JsChartViewer.get(<% viewer.id %>);
should be:
var viewer = JsChartViewer.get("<%= viewer.getId() %>");
(Note: "<%" should be "<%=". The ".id" should be ".getId()". The whole <%= .... %>
should be quoted with double or single quotes.
I suspect the code you posted in your message is only a simplification and not the exact
original code. Without the exact code, it is hard to verify if the details are correct. If the
above still does not solve the problem, is it possible to create a short example (may be
you can modify the sample code included in ChartDirector) so I may try to reproduce the
issue?
Regards
Peter Kwan |
Re: How to use get/set custom attributes on page reload |
Posted by Gert Thomas on Mar-16-2014 20:56 |
|
Thanks Peter, that does look like it will put me on the right path. I will go through it and see
if I can apply it. |
|