0

I want to use gauge.js with my jsf(primefaces) application. I dealt with primefaces components (for which, doesn't require integration) so far. Now, I want to access class property (probably through Json response) from jsf page for generating gauage. I read a solution which suggests to generate json Response but I didn't get it properly. jsFiddle by bernii shows that it requires a dynamic value for creating gauge.

<------sampleClass------>
   public int func(){
      return aValue; }

<-----JSF----->
<canvas id="gauge"></canvas>

<------Script----->
var gaugeTarget = document.getElementById('gauge');
var gauge = new Gauge(gaugeTwoTarget);
gaugeTwo.maxValue = 100;
gaugeTwo.set(); //how can i get value return by func() here...........

Also BalusC wrote awesome article on it(Java/JSP/JSF and JavaScript). Again m not able to implement it.

Thanks

Community
  • 1
  • 1
Dipendra Singh
  • 542
  • 1
  • 6
  • 23

1 Answers1

0

I missed that part in your question regarding the other solution...


Anyway you can also solve it with a hidden field in your page...

Bean (your bean clas)

int theValue;//add getter and setter

@PostConstruct
public void init(){
    theValue = func();  
}

Page (your xhtml)

<h:inputText id="myFuncValueId" value="#{myBean.theValue}" style="display:none"/>

js

gaugeTwo.set(document.getElementById('myFuncValueId').value);
Daniel
  • 36,833
  • 10
  • 119
  • 200
  • k.. it works but i think there may be a better idea to access it as i said..through json so that It will help me in other problems also.. Can u suggest me as told in ans http://stackoverflow.com/questions/10982762/how-to-generate-json-response-from-jsf – Dipendra Singh Feb 11 '13 at 09:16
  • yes, I know the technique but don't know much about FacesContext. So may be my quest become vague. Sorry for that...But i will go for another solution for which i still don't have much idea – Dipendra Singh Feb 11 '13 at 09:37
  • Ohh... Oki , I missed that part in your question regarding the *other* solution... – Daniel Feb 11 '13 at 09:46
  • 1
    take a look at this one : http://stackoverflow.com/questions/4112686/how-to-use-servlets-and-ajax – Daniel Feb 11 '13 at 12:26