h:inputText的默认值 [英] Default value for h:inputText

查看:125
本文介绍了h:inputText的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一个绑定到ManagedBean的文本框:

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.

我知道我可以在构造时在ManagedBean中设置值,但是这对我不起作用,因为我在不同的xhtml页面中使用相同的ManagedBean作为后备bean.而且我不想在所有这些页面中初始化名称"字段.

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?

非常感谢!

推荐答案

  • 您可以使用javascript(document.getElementById("formName:textName").value = 'defaultValue';.也许在document.onload

    • you can fill the value in with javascript (document.getElementById("formName:textName").value = 'defaultValue';. Perhaps on document.onload

      您可以对托管bean进行子类化,并在默认构造函数或@PostConstruct方法中填充默认值,然后使用子类化的bean.

      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.

      这篇关于h:inputText的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆