Reputation: 1523
I have a JavaScript function using a value from a backing bean, like var x = #{bean.value}
.
On page load, the value for x
is final until the page is being reloaded (since EL is being replaced by its actual value string).
However, the bean's value
might change due to ajax requests.
How can I achieve that x
gets updated?
Here's an excerpt from my xml (using primefaces' calendar component) to clarify:
<p:calendar beforeShowDay="highlightDays" ... />
<script>
function highlightDays(){
var highlightedDays= #{bean.specialDays()};
// set css...
}
</script>
Upvotes: 0
Views: 614
Reputation: 10048
You can use the RequestContext to do such an update from the bean:
RequestContext.getCurrentInstance().execute("highlightedDays = " + specialDays());
And the javascript variable should be on the window scope, meaning that you should define the var outside the scope of the function.
highlightedDays= #{bean.specialDays()};
function highlightDays(){
//make use of the var
}
Upvotes: 1