Default value for h:inputText

谁说我不能喝 提交于 2019-12-13 19:56:12

问题


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



来源:https://stackoverflow.com/questions/3180265/default-value-for-hinputtext

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!