【问题标题】:h:inputText - jsf does not render the placeholderh:inputText - jsf 不呈现占位符
【发布时间】:2013-04-10 06:37:55
【问题描述】:

我想创建一个landingPage,我想通过jsf 2.0和Primefaces 3.5将数据保存在我的数据库中

我的页面 *.xhtml 页面如下所示:

但是,我想让它看起来像我的 HTML 页面:

除了 CSS 我的 h:inputText 应该包含一个占位符。我的代码如下所示:

<h:form class="homepage_invitee_form" action="" method="POST">
    <h:inputText name="email" placeholder="Email Address"
                 id="email_address_new" type="text placeholder" />
    <br />
    <h:inputText name="firstName" placeholder="First Name"
                 id="firstname_new" type="text placeholder" />
    <h:inputText name="lastName" placeholder="Last Name"
                 id="lastname_new" type="text placeholder" />
    <br />
    <h:button value="Request Invitation" type="submit" class="btn btn-primary opal_btn"
              id="submit_form_new" />
</h:form>

如您所见,占位符属性没有被渲染。我真的很感激任何关于如何正确渲染的想法。

更新

我的 HTML 代码如下所示:

<form class="homepage_invitee_form" action="" method="POST">
    <input name="email" placeholder="Email Address" id="email_address_new" type="text placeholder"><br>
    <input name="firstName" placeholder="First Name" id="firstname_new" type="text placeholder">
    <input name="lastName" placeholder="Last Name" id="lastname_new" type="text placeholder"><br> 
    <button type="submit" class="btn btn-primary opal_btn" id="submit_form_new">Request Invitation</button>
</form>

【问题讨论】:

标签: java html css jsf primefaces


【解决方案1】:

在 xhtml 中使用 p:watermark 而不是占位符。其他视觉设计完全取决于您的 CSS。

看这里primefaces showcase

【讨论】:

    【解决方案2】:

    对于 JSF 2.2 (JEE 7),您可以使用命名空间

    xmlns:p="http://xmlns.jcp.org/jsf/passthrough"

    然后使用它,例如:

    &lt;h:inputText value="#{bean.field}" p:placeholder="supply value"/&gt;

    这会将其传递给生成的 HTML(注意:HTML 5 属性)。

    http://www.adam-bien.com/roller/abien/entry/jsf_2_2_and_html

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题并修复了它。您可能没有在该标记上使用正确的 xmln 命名空间。

      确保“h”xmln 命名空间映射到 PrimeFaces。通常这映射到“http://java.sun.com/jsf/html”,而 xmln 命名空间“p”通常映射到 PrimeFaces,“http://primefaces.org/ui”。如果您有正常的映射,那么您需要将该代码上的 xmln 更改为“p”而不是“h”:

      p:inputText name="email" placeholder="Email 地址" id="email_address_new" type="文本占位符" />
      ...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-05
        • 2012-12-10
        • 2014-07-14
        • 1970-01-01
        • 2013-11-23
        • 1970-01-01
        • 2021-08-07
        • 1970-01-01
        相关资源
        最近更新 更多