JSF,HighCharts和JS [英] JSF, HighCharts and JS

查看:88
本文介绍了JSF,HighCharts和JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的项目中使用highcharts和jsf。我有一个托管bean,它有一个列表,它正在由一个门面进行初始化(它在我的数据库中进行查询)。如果我想将列表的价值传递给高层,那怎么办?
如果有人有一个好主意,请分享。



最好的问候和非常感谢

解决方案

但是我做了其他图表库...



我会给你一些关于如何将基于js的图表目录与JSF结合的说明(我是确定有其他方式就像使用servlet等等)
$ b <1>在你的JSF项目中构建一个工作的硬编码js例子
包括库所需的相关* .js文件
添加页面
所需的容器div,最后添加用硬编码值构建图表的js脚本。$ / b

2)将你的硬编码值放到你的Bean String属性中,并在你的.xhtml页面中放置一个ref属性,就像< h:inputHidden id =chart_input_datavalue =#{myBean.valueOfChart}/> 并在您的js代码中像这样访问它

  //我使用了jQuery select ors .... 
var data_for_chart = $('input [id $ =chart_input_data]')。val(); //你可以使用一个简单的选择器,比如$(#chart_input_data)也可以使用变量

data_for_chart 如图系列输入(或者您的图表构造函数的任何参数)

3)最后,我想你想将Pojos的一些列表变成一个合适的json格式,这对于HigthCharts约束器来说就像是适合手套一样,这可以用<$ c $来实现c> Gson 类似于的库> gson.toJson(yourListOfValues)请参阅 Gson用户指南



注意



这项技术适用于所有图表库,如 flot flotr2 gRaphael jqPlot 等等...


I would like to use in my project highcharts and jsf both. I have a managedbean, which has a list and it is initializing by a facade (it do a query in my database). If I'd like to pass the value of the list to highcharts, how can do this? if anyone has a good idea, please share.

Best regards and thanks a lot

解决方案

Haven't worked with highcharts , but I did with other charting library...

I'll give you general Instructions on how to combine js based charting directory it with JSF (I'm sure that there are others way's like using servlets and etc...)

1) build a working "hard coded" js only example in your JSF project include the relevant *.js files needed by the library add the "container" div that is required to your page and finally wrtie the js script that build your chart with hard coded values

2) place your hard coded values into your Bean String property and place a ref' to that property in your .xhtml page something like that <h:inputHidden id="chart_input_data" value="#{myBean.valueOfChart}" /> and access it in your js code like that

//I used jQuery selectors....
var data_for_chart = $('input[id$="chart_input_data"]').val(); //you can use a simpler selector like $("#chart_input_data") too

than use the variable data_for_chart as chart series input (or for whatever parameter of your chart constructor)

3) finally I guess you would like to turn some list of Pojos into a proper json format which is most like wold "fit like a glove" for the HigthCharts constractor , this you can achieve with Gson library something like gson.toJson(yourListOfValues) see Gson user guide

Note

This technique should work for all charting library's , such as flot , flotr2 , gRaphael , jqPlot and more...

这篇关于JSF,HighCharts和JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆