-
1. Re: Is possible : javascript to get bean list value during onload?
liuliu Dec 23, 2010 2:57 AM (in response to eswaramoorthy1985)hi,
why you need this?
-
2. Re: Is possible : javascript to get bean list value during onload?
eswaramoorthy1985 Dec 23, 2010 7:46 AM (in response to liuliu)Thanks for your response.
In my application , show the student result using piechart. That piechart fully write javascript code.
So i need to pass the value into that piechart.
I want to iterate the bean value in javascript and pass the value (number , percentage) into piechart.
-
3. Re: Is possible : javascript to get bean list value during onload?
ilya40umov Dec 23, 2010 8:31 AM (in response to eswaramoorthy1985)This is an example from one of my applications:
<script type="text/javascript">//<![CDATA[var usersOnlineCount = [];var requestsCount = [];var averageRequestTime = [];var maximumRequestTime = [];//]]><c:forEach items="#{statisticBean.items}" var="item">usersOnlineCount.push([${item.finishedUTC}, ${item.usersOnlineCount}]);</c:forEach><c:forEach items="#{statisticBean.items}" var="item">requestsCount.push([${item.finishedUTC}, ${item.requestsCount}]);</c:forEach><script type="text/javascript">
//<![CDATA[
var requestsCount = [];
//]]>
<c:forEach items="#{statisticBean.items}" var="item">
requestsCount.push([${item.finishedUTC}, ${item.requestsCount}]);
</c:forEach>
//<![CDATA[
jQuery.plot(jQuery("#requestsCount"),
[ { data: requestsCount, label: "Reuests Count" },
],
{
xaxis: { mode: 'time' },
yaxis: { min: 0 },
legend: { position: 'sw' } });
//]]>
</script>
-
4. Re: Is possible : javascript to get bean list value during onload?
eswaramoorthy1985 Dec 23, 2010 10:29 PM (in response to ilya40umov)
Thanks for your reply.But i can't pass the bean data into pieChart.
First i want to show static content in piechart (i used highChart)
<script type="text/javascript"> jQuery(document).ready(function() { var optionsPie = { chart: { renderTo: 'container', defaultSeriesType: 'pie' }, series: [{ data: [ ['1001', 45], ['1002', 80], ['1003', 60], ['1004', 75], ] }] }; chart = new Highcharts.Chart(optionsPie); }); </script>
Here, in my above script i use static content "1001,45" "1002,80" "1003,60" 1004,75".
My problem :
onload i want to read c:forEach tag content and pass into pieChart .
Because the piechart content read from backing bean and store into c:forEach.
Otherwise any otherway, javascript to read the backing beanlist value??
<script type="text/javascript"> jQuery(document).ready(function() { var optionsPie = { chart: { renderTo: 'container', defaultSeriesType: 'pie' }, series: [] }; getForEachDataAndPassToChart(); // This method for get data for forEach tag and // those data pass into piechart }); function getForEachDataAndPassToChart() { //Here i want write code to get data from forEach tag and pass that data into chart .... .... chart = new Highcharts.Chart(optionsPie); } </script>
Is possible to pass? Otherwise give me a some sample to pass content into piehart.
-
5. Re: Is possible : javascript to get bean list value during onload?
ilya40umov Dec 24, 2010 2:06 AM (in response to eswaramoorthy1985)If I understand you right this is what you need:
<script type="text/javascript">jQuery(document).ready(function() {//defining arrayvar loadedData= [];//pusing datanto array<c:forEach items="${DataBean.studentList}" var="student">loadedData.push([${student.number}, ${student.percentage}]);</c:forEach>//using array data for chartvar optionsPie = {chart: {renderTo: 'container',defaultSeriesType: 'pie'},series: [{data: loadedData}]};chart = new Highcharts.Chart(optionsPie);});</script><script type="text/javascript">
jQuery(document).ready(function() {
//defining array
var loadedData= [];
//pusing datanto array
<c:forEach items="${DataBean.studentList}" var="student">
loadedData.push([${student.number}, ${student.percentage}]);
</c:forEach>
//using array data for chart
var optionsPie = {
chart: {
renderTo: 'container',
defaultSeriesType: 'pie'
},
series: [{
data: loadedData
}]
};
chart = new Highcharts.Chart(optionsPie);
});
</script>
-
6. Re: Is possible : javascript to get bean list value during onload?
ilya40umov Dec 24, 2010 2:39 AM (in response to ilya40umov)I suddenly understood that you might need to load data using AJAX. So if you realy want to load some data for your chart from the server at the moment when the page is aleady loaded you should use AJAX call. You can use servlet/jsp/jsf to form XML/JSON and pass it to client. I suggest you to use aj4:jsFunction. You may use 'data' attribute of this tag and simply form JSON on the server. Then just use eval and "enjoy" JS development.
-
7. Re: Is possible : javascript to get bean list value during onload?
eswaramoorthy1985 Dec 27, 2010 12:04 AM (in response to ilya40umov)1 of 1 people found this helpfulMore thanks to you.
Its worked for me...
-
8. Re: Is possible : javascript to get bean list value during onload?
nbelaevski Dec 27, 2010 4:03 AM (in response to eswaramoorthy1985)Use ScriptUtils#toScript to serialize into JavaScript.
-
9. Re: Is possible : javascript to get bean list value during onload?
ilya40umov Dec 27, 2010 4:39 AM (in response to nbelaevski)Nick Belaevski wrote:
Use ScriptUtils#toScript to serialize into JavaScript.
Is it possible to use ScriptUtils#toScript on a xhtml page directly?
-
10. Re: Is possible : javascript to get bean list value during onload?
nbelaevski Dec 27, 2010 4:45 AM (in response to ilya40umov)Hi Ilya,
It's possible via bean or by wrapping as custom EL function.
-
11. Re: Is possible : javascript to get bean list value during onload?
ilya40umov Dec 27, 2010 4:51 AM (in response to nbelaevski)Thank's I've understood.
-
12. Re: Is possible : javascript to get bean list value during onload?
eswaramoorthy1985 Dec 27, 2010 9:32 PM (in response to eswaramoorthy1985)Hi, I have another problem regarding this post.
I write this script code in one seperate file. But not work.
pieScript.js
function pieLoad() { alert("start 1..........."); //This alert showed successfully var loadedData= []; <c:forEach items="${DataBean.studentList}" var="student"> loadedData.push(['${student.number}', ${ student.percentage }]); </c:forEach> alert("Start 2 ........"); //This alert message not execute var optionsPie = { chart: { renderTo: 'chartForm:container', defaultSeriesType: 'pie' }, series: [{ data: loadedData }] }; chart = new Highcharts.Chart(optionsPie); alert("pieload end!!!"); //This alert also not came... }
pie.jsp
<head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <a4j:loadScript src="resource:///org/richfaces/renderkit/html/scripts/jquery/jquery.js" /> <a4j:loadScript src="highcharts.js"/> <a4j:loadScript src="pieScript.js"/> <script type="text/javascript"> jQuery(document).ready(function() { pieLoad(); }); </script> </head>
If i use this script same page then its worked..
help me.
Thanks in advance...
-
13. Re: Is possible : javascript to get bean list value during onload?
ilya40umov Dec 28, 2010 4:16 AM (in response to eswaramoorthy1985)It does not work because JS files are not processed by FacesServet and it's not a JSP so Servlets Container does not process it either. That is why c:forEach does not work. You still can generate your JS file by servlet or jsp page. Like this
<a4j:loadScript src="pieScript.jsp"/>