如何在JSF输入组件中添加占位符属性? [英] How to add placeholder attribute to JSF input component?

查看:113
本文介绍了如何在JSF输入组件中添加占位符属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用html5时,此行代码是否应使用占位符文本"fill me"来呈现inputtext字段?

Shouldn't this line of code render a inputtext field with the placeholder text "fill me" when using html5?

<h:inputText placeholder="fill me" />

我看不到任何占位符文本.我以为不是JSF的所有东西都传递给了浏览器进行渲染?

I do not see any placeholder text. I thought everything that was not JSF was passed to the browser for rendering?

推荐答案

我认为不是JSF的所有内容都传递给浏览器进行渲染了吗?

因此,此假设是错误的. JSF渲染器会忽略未指定组件属性.

This assumption is thus wrong. Unspecified component attributes are ignored by the JSF renderers.

基本上,您可以通过以下选项使其正常工作:

You have basically the following options to get it to work:

  1. 如果您已经在使用JSF 2.2或更高版本,请将其设置为通过属性.

<... xmlns:a="http://xmlns.jcp.org/jsf/passthrough">

<h:inputText a:placeholder="fill me" />

请注意,我使用的XML名称空间前缀为a(属性"),而不是本教程中所示的p,否则它将与PrimeFaces的默认XML名称空间前缀p冲突.

Note that I use a XML namespace prefix of a ("attribute") instead of p as shown in the tutorial, as it would otherwise clash with default XML namespace prefix p of PrimeFaces.

<h:inputText>实施自定义渲染器,在其中您显式检查并写入属性.

Implement a custom renderer for <h:inputText> wherein you explicitly check and write the attribute.

实现使用上述自定义渲染器的自定义组件.

Implement a custom component which uses the aforementioned custom renderer.

实施基于JS的解决方案,其中您从DOM中获取元素并显式设置属性.

Implement a JS based solution wherein you grab the element from DOM and explicitly set the attribute.

寻找一个支持此功能的组件库.例如, PrimeFaces 具有

Look for a component library which supports this out the box. PrimeFaces for example has a <p:watermark> for this purpose with nice JS based graceful degradation for browsers which does not support the placeholder attribute on inputs.

寻找一种渲染工具包,该工具包将HTML5支持添加到标准组件集中.例如, OmniFaces 具有

Look for a render kit which adds HTML5 support to standard component set. OmniFaces for example has a Html5RenderKit for this purpose.

另请参见:

  • JSF不会呈现自定义HTML标记属性
  • See also:

    • Custom HTML tag attributes are not rendered by JSF
    • 这篇关于如何在JSF输入组件中添加占位符属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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