1

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
  • 1
    you can access any JSF UI element (which is rendered in turn into HTML element) from js... Commented May 8, 2012 at 19:35

1 Answer 1

1

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>
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.