java h:inputText - jsf 不呈现占位符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16061072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:46:23  来源:igfitidea点击:

h:inputText - jsf does not render the placeholder

javahtmlcssjsfprimefaces

提问by maximus

I want to create a landingPage and I want to save the data in my database through jsf 2.0 and Primefaces 3.5

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

My page *.xhtml page looks like this:

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

enter image description here

在此处输入图片说明

However, I want to make it look like my HTML page:

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

enter image description here

在此处输入图片说明

Besides the CSS my h:inputText should contain a placeholder. My code looks like this:

除了 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>

As you can see the placeholder attribute doesn't get rendered. I would really appreciate any idea as to how to render that properly.

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

UPDATE

更新

My HTML code looks like this:

我的 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>

回答by oko

Use p:watermarkin xhtml instead of your placeholders. Other visual design is totally about your css.

在 xhtml 中使用p:watermark而不是占位符。其他视觉设计完全是关于你的 css。

Here look at this primefaces showcase

看看这个primefaces展示

回答by fr13d

For JSF 2.2(JEE 7), you can use the namespace

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

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

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

then use it e.g.:

然后使用它,例如:

<h:inputText value="#{bean.field}" p:placeholder="supply value"/>

<h:inputText value="#{bean.field}" p:placeholder="supply value"/>

This passes it through to the generated HTML (NB: HTML 5attribute).

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

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

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

回答by Go Rose-Hulman

I ran into this same issue and fixed it. You may not be using the proper xmln namespace on that tag.

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

Make sure the "h" xmln namespace is mapped to PrimeFaces. Normally this is mapped to "http://java.sun.com/jsf/html" and the xmln namespace "p" is normally mapped to PrimeFaces, "http://primefaces.org/ui". If you have the normal mappings then you need to change the xmln on that code to "p" instead of "h":

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

    <h:form class="homepage_invitee_form" action="" method="POST">
       <p:inputText name="email" placeholder="Email Address"
       id="email_address_new" type="text placeholder" />
       <br />
       ...