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

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

问题描述

我想为我的登录表单添加一些iOS特定的标签属性。如果我看看我的网页源代码,autocorrect,autocapitalize和拼写检查的属性就不存在了。这是什么原因?

 < h:inputText id =user-nameforceId =truevalue =#{login.username}style =width:120px; 
autocorrect =offautocapitalize =offspellcheck =false/>


解决方案

这是设计。您只能指定属性由JSF组件本身支持(即,它已列在标签文档)。您不能指定任意的附加属性,它们将被全部忽略。



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


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

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

    (注意我使用 xmlns:a 代替 xmlns:p 以避免与PrimeFaces默认命名空间冲突)

    或者:
    $ b

     < html ... xmlns:f =http:// xmlns。 jcp.org/jsf/core\"> 
    ...
    < h:inputText ...>
    < / h:inputText>





  2. 使用 OmniFaces Html5RenderKit 。自1.5版本以来,它支持通过< context-param> 指定自定义属性。另请参阅展示范例 Javadoc




    创建一个自定义的渲染器。你可以在下面的答案中找到几个具体的例子:



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" />

解决方案

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. If you're already on JSF 2.2+, simply specify it as passthrough attribute:

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

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

    Or:

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


  2. Use OmniFaces Html5RenderKit. Since the 1.5 release, it supports specifying custom attributes by <context-param>. See also the showcase example or Javadoc.


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

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

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