【问题标题】:Richfaces placeholder not workingRichfaces 占位符不起作用
【发布时间】:2013-09-03 22:01:23
【问题描述】:

我正在使用 jsf 2.0,我正在尝试使用 Richfaces 4.3 的占位符。这是jsf代码

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://java.sun.com/jstl/core"
      xmlns:rich="http://richfaces.org/rich">
....
....
<h:form>
    <table>
        <thead>
            <tr>
                <th>
                    <h:outputText value="Header"/>
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    <h:inputText id="first" value="#{bean.firstValue}">
                        <rich:placeholder value="Fill me"/>
                    </h:inputText>
                </td>
            </tr>
        </tbody>
    </table>
</h:form>

这是它的渲染方式:

<form id="j_id_1v" name="j_id_1v" method="post" action"/mypage/app/main.xhtml" enctype="application/x-www-form-urlencoded">
<table>
    <thead>
        <tr>
            <th>
                "Header"
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <span id="j_id_1v:j_id_2r">
                    <script id="j_id_1v:j_id_2rScript" type="text/javascript">
                        <!--
                        new RichFaces.ui.Placeholder("j_id_1v:j_id_2r", {"targetId":"j_id_1v:first","text":"Fill me"} );
                        //-->
                    </script>
                </span>
                <input id="j_id_1v:first" name="j_id_1v:first" type="text" value>
            </td>
        </tr>
    </tbody>
</table>
</form>

#{bean.firstValue}" 为 null,不是空字符串。不确定这是否重要。问题是占位符文本没有显示。

有什么想法吗?

--编辑-- 检查 js 控制台,它显示“未定义 Richfaces”。我确定我使用的是richfaces 4.3。

【问题讨论】:

  • 我工作的地方有自己的 maven 仓库。我可以访问richfaces,但没有primefaces。所以我不能添加新东西,只能使用他们在仓库中的东西。
  • 好吧,那就别管前面的评论了。
  • 没有问题。我注意到渲染的 Richfaces 被 包裹。我见过的一个例子都没有。我不确定这是不是把我的东西搞砸了,但这很奇怪。 ://
  • 这没有害处。这只是为了防止不支持&lt;script&gt; 元素的史前网络浏览器阻塞,例如Netscape 1.0。这些天您为什么在 HTML 代码中看到这一点确实值得怀疑。这些浏览器已近十年不再使用。 RichFaces 在尝试实现最大的浏览器兼容性方面有点过分热心。
  • 有趣...仍然无法理解占位符的情况。无论如何,css 样式会干扰占位符吗?

标签: jsf jsf-2 richfaces


【解决方案1】:

好的,所以,经过大量研究,我想通了。事实证明,如果您使用 &lt;head&gt;,jsf 2.0 和richfaces 就无法相处。您必须使用 &lt;h:head&gt; 以便它插入所有必需的依赖项。而且……就是这样!

【讨论】:

    【解决方案2】:

    对我来说,为 inputText 添加了 ajax 支持,例如

    <h:inputText id="first" value="#{bean.firstValue}">
        <rich:placeholder value="Fill me"/>
        <a4j:ajax/>
    </h:inputText>
    

    【讨论】:

      猜你喜欢
      • 2013-09-28
      • 2014-03-04
      • 2015-03-24
      • 2017-06-29
      • 1970-01-01
      • 2018-02-19
      • 2018-03-05
      • 2013-05-05
      • 2013-10-19
      相关资源
      最近更新 更多