-1

How can I set a default value to my outputText so that the user doesn't have to enter it each time?

    <h:inputText value= "#{bean.cit.nationality}" id="nationality"/>

I would like to set the value to "American" as a default value to nationality.

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
  • Do it in a corresponding/associated managed bean such as a method annotated with `@PostConstruct`. – Tiny Feb 17 '15 at 10:31

1 Answers1

0

You have two choices. Either set the default value in the bean data or use javascript/jquery to set the html input text value.

<h:form id="formId">
    <h:inputText value="#{bean.cit.nationality}" id="nationality"/>
    <script>$("#formId\\:nationality}").val() = "American"</script>
</h:form>

Or you can use a more generic approach to find the client component within its parent or naming container:

$("##{component.namingContainer.findComponent('nationality').clientId}")

You can also use a utility method to escape the JSF colon to reduce conflicts with jquery.

$("(PrimeFaces.escapeClientId('formId:nationality')")
djmj
  • 5,579
  • 5
  • 54
  • 92