如何在 rich:suggestionBox javascript 上重写 markPrevious 和 markNext 方法

发布于 2024-09-24 22:22:29 字数 1705 浏览 2 评论 0原文

我有一个要求,用户应该能够通过按 键从 rich:suggestionBox 列表中的第一项导航到最后一项,反之亦然。

我需要在 richfaces 3.3.x 上完成这项工作。

完成这项工作的追求让我找到了 rich:suggestionBox 背后的 javascript。您可以在 JBoss anon svn。有问题的方法是 markPrevious()markNext()

这就是它们在 Suggestion.Base.prototype 上的定义方式:

markPrevious: function() {
    if (this.index > 0) this.index--;
    //else this.index = this.entryCount - 1;
},

markNext: function() {
    if (this.index < this.entryCount - 1) this.index++;
    //else this.index = 0;
},

如您所见,我需要的功能就在那里,但由于某种原因他们将其放在注释中。因此,我尝试通过在所有页面使用的模板文件中放置以下 javascript 来重写这些方法:

<script type="text/javascript">
    //<![CDATA[

    if(Suggestion) {
        function newMarkPrevious() {
            if (this.index > 0) this.index--;
            else this.index = this.entryCount - 1;
        }

        function newMarkNext() {
            if (this.index < this.entryCount - 1) this.index++;
            else this.index = 0;
        }

        Suggestion.Base.prototype.markPrevious = newMarkPrevious;
        Suggestion.Base.prototype.markNext = newMarkNext;
      }
    //]]>
    </script>

现在,如果我使用 firebug 检查 Suggestion 对象,我可以看到这些方法确实被覆盖。但是,我页面上的所有 rich:suggestionBox 仍然使用旧的实现。所以,我认为,以某种方式,在我覆盖原型之前, rich:suggestionBoxes 背后的对象是被创建的。这就是我被困住的地方。我不知道如何在创建任何建议框之前获得我的版本。

有谁知道如何解决这个问题?

谢谢,

金。

PS 我意识到还可以选择直接在 richfaces-ui.jar 中调整代码,但我不想有一个自定义构建的 jar。

I have a requirement where users should be able to navigate from the first to the last item in a rich:suggestionBox's list by pressing the key, and vice versa by pressing the .

I need to get this working on richfaces 3.3.x

The quest to get this done has led me to the javascript that is behind the rich:suggestionBox. You can find it at JBoss anon svn. The methods in question are markPrevious() and markNext().

This is how they are defined on the Suggestion.Base.prototype :

markPrevious: function() {
    if (this.index > 0) this.index--;
    //else this.index = this.entryCount - 1;
},

markNext: function() {
    if (this.index < this.entryCount - 1) this.index++;
    //else this.index = 0;
},

As you can see, the functionality that I need is there, but for some reason they placed it in comment. So I tried to override the methods by placing the following bit of javascript in my template file that is used by all my pages:

<script type="text/javascript">
    //<![CDATA[

    if(Suggestion) {
        function newMarkPrevious() {
            if (this.index > 0) this.index--;
            else this.index = this.entryCount - 1;
        }

        function newMarkNext() {
            if (this.index < this.entryCount - 1) this.index++;
            else this.index = 0;
        }

        Suggestion.Base.prototype.markPrevious = newMarkPrevious;
        Suggestion.Base.prototype.markNext = newMarkNext;
      }
    //]]>
    </script>

Now, if I inspect the Suggestion object with firebug, I can see that the methods indeed get overridden. However, all rich:suggestionBoxes on my pages still use the old implementation. So, I'm thinking that somehow, the objects behind the rich:suggestionBoxes get created before I override the prototype. And this is where I'm stuck. I don't know how I could get my version in there before any of those suggestionBoxes get created.

Has anyone got an idea on how to solve this?

Thanks,

Kim.

P.S. I realise that there is also the option of just adjusting the code directly in the richfaces-ui.jar, but I don't want to have a custom built jar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

话少情深 2024-10-01 22:22:29

答案是有人在 richfaces 社区论坛上找到的: http://community.jboss.org/message/ 563271

你应该重新定义
RichFaces.Suggestion.prototype 的
函数如下:

if(RichFaces && RichFaces.Suggestion)
{
RichFaces.Suggestion.prototype.markPrevious
= 新标记上一个;
RichFaces.Suggestion.prototype.markNext
= newMarkNext; }

因为RichFaces.Suggetsion.prototype
扩展 Suggestion.Base.prorotype 的
重新定义之前的方法。

The answer was found by someone over on the richfaces community forum: http://community.jboss.org/message/563271

You should redefine
RichFaces.Suggestion.prototype's
functions like this:

if(RichFaces && RichFaces.Suggestion)
{
RichFaces.Suggestion.prototype.markPrevious
= newMarkPrevious;
RichFaces.Suggestion.prototype.markNext
= newMarkNext; }

Because RichFaces.Suggetsion.prototype
extends Suggestion.Base.prorotype's
methods before you redifinition.

葬花如无物 2024-10-01 22:22:29

也许您可以在 rich:suggestionBox 中放置一个 a4j:support 组件,并使用 javascript onKeyUp 事件处理程序调用与此类似的 javascript 函数:

function KeyCheck(e) {

   var KeyID = (window.event) ? event.keyCode : e.keyCode;
   switch(KeyID) {
     case 1:
         markNext function
         break;
     case 2:
         markPrevious function
         break;
   }
}

Maybe you can place an a4j:support component in that rich:suggestionBox with a javascript onKeyUp event handler that calls a javascript function similar to this one:

function KeyCheck(e) {

   var KeyID = (window.event) ? event.keyCode : e.keyCode;
   switch(KeyID) {
     case 1:
         markNext function
         break;
     case 2:
         markPrevious function
         break;
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文