The only way JavaScript can set a backing bean property is by making a request to the server, since that's where the backing bean lives. That means that the client must make an HTTP URL request to the server. The brute-force way of doing that would be to set a form control property (you can use a hidden text control) and pass the value in when the form is submitted.
A more elegant approach that avoids the need to submit and re-render the entire page is to do an AJAX request. That can be done in a number of ways, including:
1. brute-force javascript
2. Using an AJAX support javascript library like dojo or jQuery
3. Using the JSF2 AJAX support features
4. Using third-party
JSF AJAX support packages such as RichFaces or IceFaces.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.