问题
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.
回答1:
you can fill the value in with javascript (
document.getElementById("formName:textName").value = 'defaultValue';. Perhaps ondocument.onloadyou can subclass your managed bean and fill the default value in the default constructor, or in a
@PostConstructmethod, and use the subclassed bean.
来源:https://stackoverflow.com/questions/3180265/default-value-for-hinputtext