Default value for h:inputText
Imagine a text box, bound to a ManagedBean:
<h:inputText id="name" value="#{mb.name}"/>
I would like to default the field to a value.
I know I can set the value in the ManagedBean at construction time, but that doesn't work for me as I use the开发者_如何学运维 same ManagedBean as a backing bean in different xhtml pages. And I don't want the 'name' field to be initialized in all those pages.
Can somebody suggest a strategy? Or am I missing something essential?
Thank you very much! J.
you can fill the value in with javascript (
document.getElementById("formName:textName").value = 'defaultValue';
. Perhaps ondocument.onload
you can subclass your managed bean and fill the default value in the default constructor, or in a
@PostConstruct
method, and use the subclassed bean.
精彩评论