开发者

Default value for h:inputText

开发者 https://www.devze.com 2023-01-06 13:15 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消