素面提供了一个placeholder
最新版本中的属性,您可以使用p:inputText
。另外,还有一个p:watermark组件,它创建基于 JS 的解决方案以实现旧版浏览器兼容性。因此,您不一定需要在支持 bean 中设置默认值。只需使用以下解决方案之一:
<h:outputLabel value="Search: "/>
<p:inputText id="search_input_id" value="#{watermarkBean.keyword}"
required="true" label="Keyword" placeholder="search" />
对于旧版浏览器:
<h:outputLabel value="Search: "/>
<p:inputText id="search_input_id" value="#{watermarkBean.keyword}"
required="true" label="Keyword" />
<p:watermark for="search_input_id" value="search" />
另外如果使用JSF 2.2,您可以使用它的 passthrough 属性。添加xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
命名空间到你的页面,你可以通过以下方式实现,既可以JSF h:inputText
and 素面 p:inputText
:
<h:inputText value="#{watermarkBean.keyword}"
pt:placeholder="search" />
或者使用 TagHandler 将其包装到标签中:
<h:inputText value="#{watermarkBean.keyword}">
<f:passThroughAttribute name="placeholder"
value="search"/>
</h:inputText>
这创造了基于 HTML 5输入与placeholder
属性:
<input placeholder="search">