I'm pretty new in JS and faced an issue of using managed bean from javascript.
I'm trying to do this by means of h:inputHidden but still don't have a correct behavior.
<h:inputHidden id="hidden" value="#{bean.myVariable}" />
and my script
<script type="text/javascript">
function func(){
var varFromBean = document.getElementById('myForm:myVariable').value;
....
}
</script>
Am i do smth in wrong way? And there are another ways to define JS variable by running managed bean method?
Thanks in advance!
EDIT
I need it for rich:calendar customizing. I need to allow user to pick date from particular period.
<rich:calendar value="#{bean.selectedDate}"
isDayEnabled="disableDays" dayStyleClass="disabledDaysStyle"
firstWeekDay="1"/>
and full JavaScript for this is:
<script type="text/javascript">
function disableDays(day){
var curDt = new Date();
if (curDt == undefined){
curDt = day.date.getDate;
}
var period = document.getElementById('form:period').value;
if ((curDt.getTime() + period) > day.date.getTime()) return true;
if (curDt.getTime() < (day.date.getTime())) return true;
else return false;
}
function disabledDaysStyle(day){
if (!disableDays(day)) return 'rich-calendar-boundary-dates';
}
</script>