Is there a way to get the value from UI to javascript other than inputHidden and inputText. When there is an error in the input field, the input hidden field is not being updated. If we have to use binding value, a lot of code should be changed.
1 Answer
JSF ultimately produces HTML. JS is part of HTML. Just let JSF print it as if it is a JS variable.
E.g.
<script>var someString = '#{bean.someString}';</script>
<script>doSomething('#{bean.someString}');</script>
<script>var someNumber = #{bean.someNumber};</script>
<script>var someJsonObject = #{bean.someJsonObject};</script>
You can also use <h:outputScript> instead of <script>. This allows for easy relocation to head or to bottom of body, regardless of wherever you declare it. E.g.
<h:outputScript target="body">doSomething('#{bean.someString}');</h:outputScript>