如何在 rich:suggestionBox javascript 上重写 markPrevious 和 markNext 方法
我有一个要求,用户应该能够通过按 键从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案是有人在 richfaces 社区论坛上找到的: http://community.jboss.org/message/ 563271
The answer was found by someone over on the richfaces community forum: http://community.jboss.org/message/563271
也许您可以在 rich:suggestionBox 中放置一个 a4j:support 组件,并使用 javascript onKeyUp 事件处理程序调用与此类似的 javascript 函数:
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: