为了使网站对移动设备友好,我想添加
<input type="email">
和
<input type="tel">
但我必须像使用 JSF
<h:inputText value="#{connetcionController.userName}" />
我们如何使用 JSF 生成 html 输入类型?
我也在使用 primefaces,它们有类似的功能吗?
为了使网站对移动设备友好,我想添加
<input type="email">
和
<input type="tel">
但我必须像使用 JSF
<h:inputText value="#{connetcionController.userName}" />
我们如何使用 JSF 生成 html 输入类型?
我也在使用 primefaces,它们有类似的功能吗?
如果你使用 PrimeFaces,你应该可以用这种方式使用type
with<p:inputText>
<p:inputText type="email" ... />
或者
<p:inputText type="tel" ... />
如果您想继续使用<h:inputText>
,您需要至少升级到 JSF 2.2 并添加新的 XML 命名空间xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
,然后您应该可以通过type
这种<h:inputText>
方式覆盖
<h:inputText a:type="email" ... />
或者
<h:inputText a:type="tel" ... />
有一个非常简单的方法。您可以使用直通。将此添加到您的 html 标记
xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
然后,您可以添加您的输入类型。
你必须添加一个a:
之前。
<h:inputText a:type="email" value="#{profileBean.student.privateMail}"/>
这也适用于其他一些定义,例如占位符
<h:inputSecret a:placeholder="Password" value="#{loginBean.credentials.password}" />
您可以使用 jQuery 插件来掩盖这样的正常<input id="phone" />
情况:
jQuery(function($){
$("#phone").mask("(999) 999-9999");
});
使用这个插件:http ://digitalbush.com/projects/masked-input-plugin/
PrimeFaces Extensions 附带pe:inputPhone
使用type="tel"
. 除此之外,它还提供验证、格式化和更多选项。
看: