1

I am using icefaces , the managed bean's postconstruct method populates some data by making a network call. In the xhtml I am binding this to a hidden outputText

   <h:outputText id="hdnBtnForData" value="#{XBean.hiddenData}" style="display: none;" />

This XBean.hiddenData is populated in postconstruct mehtod. Now when i try to get the the value of outputText in Javascript , it always gives me undefined.

In Javascript I am getting the value as below.

 var res = document.getElementById("xxxxForm:hdnBtnForData");
 console.log("value is  + JSON.stringify(res.value));

My understanding is that JS is evaluated even before the postconstruct is able to put data in the variable. How do i solve this. Any pointers would be very helpful.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
TruckDriver
  • 1,383
  • 13
  • 28
  • _"My understanding is that JS is evaluated even before the postconstruct is able to put data in the variable."_ Your understanding is wrong. And there is no need to use hidden fields. Where did you get this example from? – Kukeltje Aug 01 '18 at 07:37
  • @Kukeltje I am using hidden fields, because this data need not be displayed in UI. I did not know any other way to do this. What do you suggest? – TruckDriver Aug 01 '18 at 07:40
  • See the duplicate – Kukeltje Aug 01 '18 at 07:41
  • @Kukeltje : Thanks a lot, i did not know that we directly use JSF el in javascript, that solved my problem. Although i had to declare a global variable in parent xhtml and use it in external JS. thanks – TruckDriver Aug 02 '18 at 04:50

0 Answers0