简体   繁体   English

h:inputText的默认值

[英]Default value for h:inputText

Imagine a text box, bound to a ManagedBean: 想象一个绑定到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. 我知道我可以在构造时在ManagedBean中设置值,但是这对我不起作用,因为我在不同的xhtml页面中使用相同的ManagedBean作为后备bean。 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. J.

  • you can fill the value in with javascript ( document.getElementById("formName:textName").value = 'defaultValue'; . Perhaps on document.onload 您可以使用javascript( document.getElementById("formName:textName").value = 'defaultValue';来填充值。也许在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. 您可以对托管bean进行子类化,并在默认构造函数或@PostConstruct方法中填充默认值,然后使用子类化bean。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM