You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by David Canteros <da...@gmail.com> on 2012/03/09 16:40:27 UTC
Problem with generated javascript and zone update
Hi people
recently I found some problem with one own component, javascript
and zones, may be you can help me to find out a solution.
I have created some component that shows a graphic (something like a
report ) using a javascript library (amCharts). In the component I use a
parameter to pass the graphic data, and build/add the javascript code of
the graphic in the "afterRender" method. Then I have a page with a form to
load the needed info, generate the graphic and show it, all using the same
page. If I use the form without zone, everything works fine, but if I add a
zone to update only the generated graphic zone, it doesn't work (the zone
is updated but the component is not showed).* I think that the problem is
the generated javascript's code in the ajax update, but i don't know where
to search for it.... *
This is my component
@Import(library = { "context:js/amcharts.js", "context:js/raphael.js"})
public class *AmChartDisplay *{
@Parameter(required = true)
private GraphicData graphicData; //Object that contains info to
build the graphic
@Inject
private JavaScriptSupport javaScriptSupport;
public void afterRender() {
String script = "var chart; var chartData = [";
// Here: builds the script using graphicData object
javaScriptSupport.addScript(script);
}
}
Then i have a page which contains a form to configure the graphic (fields
like: dateFrom, dateTo, etc.). In the same page I have a zone with my
graphic component, and the form is linked with the zone by the t:zone
value. When the form is submitted I simply build the graphic data needed by
my component, and show it.
Page.tml
<form t:type="form" t:id="reportConfigurationForm" t:zone="graphicZone" >
(...)
<t:submit t:id="generate" value="Generate" />
</form
<t:zone t:id="graphicZone">
<t:if test="showGraph">
<t:AmChartDisplay graphicData="prop:graphicData" />
</t:if>
</t:zone>
Page.class
@Component
private Zone graphicZone;
public GraphicData getGraphicData() {
// graphic data generation
}
public Object onSubmitFromReportConfigurationForm() {
this.showGraph = true;
return graphicZone
}
Any ideas where is the problem??
Thanks in advance!
David
------------------------------------------------------------------
David Germán Canteros
Re: Problem with generated javascript and zone update
Posted by David Canteros <da...@gmail.com>.
Hi, thanks for the response.
Probably you are right. I'm not an ajax/js expert, so the only thing I can
did is check the "response" when the zone is updated (using firebug
console) and I can see the generated script inside a JSON variable called "*
evalScript*", i think. I dont know why it is not executed (problems with
the quote, maybe?).
The response (from firebug console):
{ "content" : "<div class='t-zone' id='graphZone_13607275c88'><br
clear='none'/><html><form enctype='application/x-www-form-urlencoded'
action='/reports/trainingbudgetreportpage.amchartdisplay.reportexecutionform'
method='post' id='reportExecutionForm_13607275c88'><div
class='t-invisible'><input value='1331559881875' name='ult'
type='hidden'><\/input><input
value='H4sIAAAAAAAAAJXPvUoDQRAH8PHAD9BKG8XGwvrOD+LFDySYRuWQ4FnZyGR32GzY2113N7mksRJ8Bt/BUsGXsvEJ3BwIglWqgf8M/H/z9gWL9THkjqxxwWd3DqWWWlyMuKBw26Q9FHSCFRugC1x6q3Ca+rFghpN30DFOpGiRDSgNaMkHN22lzDhSsh9nZY0mHXx6KTknvdtzhpH35ahfSe+l0fcvOxuT7c+lBBYKWGVGB2fUDVYUYL0Y4hgzhVpkZXDRdTqxAZZjeze21+dwNi+cm1org3xoScyjb7zhv/61/N76eH/uJpAUsMKUjNdX/BGemm9IURWD2TdNNNNv/hKuI+Fh//BoLz/IW6zdDrD2d/UDrNmj75sBAAA='
name='t:formdata' type='hidden'><\/input><\/div><div style='width:
700px; height: 600px; background-color:white; top:0px; bottom:0px;'
class='chartclass' id='chartdiv'><\/div><input id='svgCode' value=''
name='svgCode' type='hidden'><\/input><input
onClick='render(this.form);' value='Export as JPEG' class='ubutton'
id='downloadJpeg_13607275c88' name='downloadJpeg'
type='submit'><\/input><\/form><\/html><br clear='none'/><\/div>",
"scripts" : [ "/assets/1.3.4/ctx/js/amcharts.js",
"/assets/1.3.4/ctx/js/raphael.js",
"/assets/1.3.4/ctx/js/SvgToCanvas.js" ], "inits" : [ {
"formEventManager" : [ { "formId" :
"reportExecutionForm_13607275c88", "validate" : {
"submit" : true, "blur" : true } } ]
}, { * "evalScript" : [** "var chart; var chartData =
[{month: \"01-2011\",travel: 6688.0,training: 3705.0,cumulative:
10393.0,budget: 0.0},{month: \"02-2011\",travel: 3135.0,training:
7593.0,cumulative: 21121.0,budget: 0.0},{month: \"03-2011\",travel:
3490.0,training: 7555.23,cumulative: 32166.23,budget: 0.0},{month:
\"04-2011\",travel: 8696.0,training: 2091.0,cumulative:
42953.23,budget: 0.0},{month: \"05-2011\",travel: 15912.0,training:
5416.0,cumulative: 64281.23,budget: 0.0},{month: \"06-2011\",travel:
13657.449999999999,training: 3832.0,cumulative: 81770.68,budget:
0.0},{month: \"07-2011\",travel: 7491.389999999999,training:
4857.0,cumulative: 12348.39,budget: 0.0},{month: \"08-2011\",travel:
5517.599999999999,training: 2207.0,cumulative: 20072.99,budget:
0.0},{month: \"09-2011\",travel: 17166.18,training:
12551.0,cumulative: 49790.17,budget: 0.0},{month: \"10-2011\",travel:
4151.67,training: 1483.0,cumulative: 55424.840000000004,budget:
0.0},{month: \"11-2011\",travel: 15269.7,training: 10241.0,cumulative:
80935.54000000001,budget: 0.0},{month: \"12-2011\",travel:
13838.3,training: 1608.0,cumulative: 96381.84000000003,budget:
990993.0},{month: \"01-2012\",travel: 4727.59,training:
3954.0,cumulative: 8681.59,budget: 990993.0}];AmCharts.ready(function
() { chart = new AmCharts.AmSerialChart(); chart.dataProvider =
chartData; chart.categoryField = \"month\";chart.startDuration =
1;chart.rotate = false;chart.depth3D = 20;chart.angle = 45;
chart.addTitle(\"Training budget tracking for MS\", 14);var
categoryAxis = chart.categoryAxis;categoryAxis.gridPosition =
\"start\"; categoryAxis.axisColor = \"#DADADA\"; categoryAxis.title =
\"Months \";categoryAxis.dashLength = 5;categoryAxis.labelRotation =
45;var valueAxis0 = new AmCharts.ValueAxis(); valueAxis0.stackType =
\"regular\"; valueAxis0.title = \"Travel and training costs
\";valueAxis0.gridAlpha = 0.1; valueAxis0.axisAlpha =
0;chart.addValueAxis(valueAxis0);var valueAxis1 = new
AmCharts.ValueAxis(); valueAxis1.stackType = \"regular\";
valueAxis1.title = \"Cumulative costs and Budget\";
valueAxis1.gridAlpha = 0.1; valueAxis1.axisAlpha = 0;
valueAxis1.synchronizationMultiplyer =
1;valueAxis1.synchronizeWithAxis(valueAxis0);valueAxis1.position =
\"right\";chart.addValueAxis(valueAxis1);var graph1 = new
AmCharts.AmGraph(); graph1.type = \"column\";graph1.title = \"Travel
cost (flight + expenses)\";graph1.valueField = \"travel\";
graph1.fillColors = \"#8414A5\";graph1.lineAlpha = 0;graph1.fillAlphas
= 1;graph1.axisColor=\"#ADD981\";chart.addGraph(graph1);var graph2 =
new AmCharts.AmGraph(); graph2.type = \"column\";graph2.title =
\"Training cost (fee)\";graph2.valueField = \"training\";
graph2.fillColors = \"#84CB7B\";graph2.lineAlpha = 0;graph2.fillAlphas
= 1;graph2.axisColor=\"#ADD981\";chart.addGraph(graph2);var graph3 =
new AmCharts.AmGraph(); graph3.type = \"line\";graph3.title =
\"Cumulative cost\";graph3.valueField = \"cumulative\";
graph3.lineColor = \"#FFA218\";graph3.lineThickness = 3;graph3.bullet
= \"round\"; graph3.fillAlphas =
0;graph3.axisColor=\"#ADD981\";graph3.valueAxis=valueAxis0;chart.addGraph(graph3);var
graph4 = new AmCharts.AmGraph(); graph4.type = \"line\";graph4.title =
\"Budget\";graph4.valueField = \"budget\"; graph4.lineColor =
\"red\";graph4.lineThickness = 3;graph4.bullet = \"round\";
graph4.fillAlphas =
0;graph4.axisColor=\"#ADD981\";graph4.valueAxis=valueAxis1;chart.addGraph(graph4);var
legend = new AmCharts.AmLegend(); chart.addLegend(legend);
chart.write(\"chartdiv\"); });"** ],* "zone" : [ {
"update" : "highlight", "element" :
"graphZone_13607275c88", "show" : "show" } ] }
]}
------------------------------------------------------------------
David Germán Canteros
2012/3/9 trsvax <tr...@gmail.com>
> My guess would be there is something in your script that cannot be sent in
> a
> JSONObject. Without a zone the script is just included in the HTML but a
> zone update returns a JSONObject and there are rules about what can be
> included.
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Problem-with-generated-javascript-and-zone-update-tp5550938p5551858.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
Re: Problem with generated javascript and zone update
Posted by trsvax <tr...@gmail.com>.
My guess would be there is something in your script that cannot be sent in a
JSONObject. Without a zone the script is just included in the HTML but a
zone update returns a JSONObject and there are rules about what can be
included.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Problem-with-generated-javascript-and-zone-update-tp5550938p5551858.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org