【问题标题】:How to embed jQuery/javascript in JSF XML如何在 JSF XML 中嵌入 jQuery/javascript
【发布时间】:2010-05-20 12:52:41
【问题描述】:

我想关注我的 RichFaces rich:modalPanel 中的第一个 h:inputSecret 组件。我读过我需要使用下面列表中包含的 javascript,但它根本不起作用(Win FF)。谁能告诉我为什么不呢?我已经尝试在 id="Form" 上自动对焦并给 panelGrid 一个 id 并使用它无济于事。任何帮助表示赞赏。

                    <rich:modalPanel id="PwdPanel" autosized="true" width="300" onshow="autofocus('FormNewP0')">
                    <a4j:region id="FormCont">
                        <a4j:form name="Form">
                            <h:panelGrid columns="2" style="padding: 2px;">
                                <h:outputText value="New password&#160;" />
                                <h:inputSecret id="FormNewP0"
                                    value="#{MyBacking.dbNewPwd0}" />

                                <h:outputText value="Re-enter new password&#160;" />
                                <h:inputSecret id="FormNewP1"
                                    value="#{MyBacking.dbNewPwd1}" />

                                <h:outputText value="" />
                                <h:panelGroup>
                                    <a4j:commandButton value="Submit"
                                        action="#{MyBacking.dbPwdChange}"
                                        oncomplete="#{MyBacking.dbPwdError == true ? 'Richfaces.showModalPanel(\'ErrorPanel\');' : 'Richfaces.hideModalPanel(\'ErrorPanel\');Richfaces.hideModalPanel(\'PwdPanel\');'}"
                                        reRender="FormCont,FormText" />
                                    <h:outputText value="&#160;" />
                                    <a4j:commandButton value="Cancel"
                                        onclick="#{rich:component('PwdPanel')}.hide();return false;" />
                                </h:panelGroup>
                            </h:panelGrid>
                        </a4j:form>
                    </a4j:region>
                </rich:modalPanel>
                <script type="text/javascript" language="JavaScript">
                    function autofocus(containerId) {
                      var element = jQuery(":input:not(:button):visible:enabled:first", '#'+containerId);
                      if (element != null) {
                        element.focus().select();
                      }
                    }
                </script>    

【问题讨论】:

  • 服务器端源代码与故事无关,因为 JavaScript 看不到它的任何行。客户端源代码更有趣,因为它是 JavaScript 唯一可以看到和访问的。在网络浏览器中右键单击页面并选择查看源代码。顺便说一句,您对我在描述与您的症状相同的问题上的其他回答投了反对票,恕我直言有点愚蠢,因为您没有同样的问题
  • 嗯,我实际上正在处理几个类似的问题,所以它可能是相同的。或者这可能是一个错误。

标签: javascript jquery jsf richfaces


【解决方案1】:

你可以试试

jQuery("##{rich:clientId('FormNewP0')").focus().select();

希望对您有所帮助。

【讨论】:

    【解决方案2】:

    您是否在页面中包含了 jQuery 库。尝试使用以下确保包含 jQuery,

    详情请参考以下网站,

    http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_jQuery.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-27
      • 1970-01-01
      • 1970-01-01
      • 2018-03-08
      • 2014-01-04
      • 2013-01-31
      相关资源
      最近更新 更多