Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
想象一个绑定到 ManagedBean 的文本框:
<h:inputText id="name" value="#{mb.name}"/>
我想将该字段默认为一个值。
我知道我可以在构建时设置 ManagedBean 中的值,但这对我不起作用,因为我在不同的 xhtml 页面中使用相同的 ManagedBean 作为支持 bean。而且我不希望在所有这些页面中初始化“名称”字段。
有人可以提出一个策略吗?还是我错过了一些重要的东西?
非常感谢你!J。
您可以使用 javascript ( document.getElementById("formName:textName").value = 'defaultValue';. 也许在document.onload
document.getElementById("formName:textName").value = 'defaultValue';
document.onload
您可以将托管 bean 子类化并在默认构造函数或@PostConstruct方法中填充默认值,然后使用子类化 bean。
@PostConstruct