0

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>

1 Answer 1

1

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  
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.