JSF 不呈现自定义 HTML 标记属性 [英] Custom HTML tag attributes are not rendered by JSF

查看:25
本文介绍了JSF 不呈现自定义 HTML 标记属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的登录表单中添加一些特定于 iOS 的标签属性.如果我查看我的网页源代码,属性自动更正、自动大写和拼写检查不存在.这是什么原因?我使用的是 JSF 2.x.

I want to add some iOS specific tag attributes to my login-form. If I have a look on my web page source, the attributes autocorrect, autocapitalize and spellcheck aren't there. What is the reason for this? I am using JSF 2.x.

<h:inputText id="user-name" forceId="true" value="#{login.username}" style="width:120px;"
    autocorrect="off" autocapitalize="off" spellcheck="false" />

推荐答案

这是设计使然.您只能指定 JSF 组件本身支持的属性(即它列在标签文档的属性列表中).您不能指定任意的附加属性,它们都将被完全忽略.

This is by design. You can only specify attributes which are supported by the JSF component itself (i.e. it's listed in the attribute list in the tag documentation). You can't specify arbitrary additional attributes, they will all be plain ignored.

有几种方法可以解决这个问题:

There are several ways to solve this:

  1. 如果您已经使用 JSF 2.2+,只需将其指定为 passthrough 属性:

<html ... xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
...
<h:inputText ... a:autocorrect="off" />

(注意,我使用 xmlns:a 而不是 xmlns:p 来避免与 PrimeFaces 默认命名空间冲突)

(note that I'm using xmlns:a instead of xmlns:p to avoid clash with PrimeFaces default namespace)

或者:

<html ... xmlns:f="http://xmlns.jcp.org/jsf/core">
...
<h:inputText ...>
    <f:passThroughAttribute name="autocorrect" value="off" />
</h:inputText>


  • 创建自定义渲染器.您可以在以下答案中找到几个具体示例:


  • Create a custom renderer. You can find several concrete examples in below answers:

    这篇关于JSF 不呈现自定义 HTML 标记属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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