本文介绍了如何在Primefaces中覆盖ContentFlow配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想覆盖onclickActiveItem函数,并且需要检索当前活动项目索引或在Primefaces中使用onMakeActive调用某项,最佳方法是什么?

I want to override onclickActiveItem function and need to retrieve current active item index or call something with onMakeActive in Primefaces, what best way to do ?

我可以通过以下方式调用函数:

I was able to call function with the following way :

<p:contentFlow value="#{imagesView.images}" var="image" widgetVar="img">
            <p:graphicImage value="/images/imgs/img#{image}.jpg" styleClass="content" onclick="select(#{image})" />
        </p:contentFlow>

然后使用javascript:

then in javascript :

function setImageIndex(i){
        return;
    }
function select(i) {
        ContentFlowGlobal.Flows[0].setConfig({onclickActiveItem:setImageIndex});
    }

但是,如果我尝试这种方式:ContentFlowGlobal.Flows[0].setConfig({onclickActiveItem:setImageIndex(i)});它可以工作,但是有许多控制台错误记录,例如"onclickActiveItem不是函数"!

But if I tried this way :ContentFlowGlobal.Flows[0].setConfig({onclickActiveItem:setImageIndex(i)});it works but many console errors records, like "onclickActiveItem is not a function" !

因此,通过这种方式,我删除了打开图像本身的默认操作,并且可以使用onclick进行调用,我希望有更好的方法来覆盖ContentFlow js,我仍然认为我做错了事.

So in this way I removed default action that open image itself, and I can do my call using onclick, I want better way to override ContentFlow js, I still think I do thing wrongly.

有什么想法可以替代在Primefaces中重写ContentFlow javascript配置的正确方法吗?

Any idea what the correct way to override ContentFlow javascript configuration in primefaces?

推荐答案

通过使用AddOn,我发现了我以前使用的第一种更好,更清洁的方法,并保证了方法的更清晰:

I found better and cleaner way from my previous first way I used and guaranteed way and clearer, by using AddOn, like this :

if (typeof ContentFlowGlobal != 'undefined') {
    new ContentFlowAddOn('ImageSelectAddOn', {
        ContentFlowConf : {
            // onclickInactiveItem: function (item) {
            // this.conf.onclickActiveItem(item);
            // },
            onclickActiveItem : function(item) {
                var content = item.content;
                var i = item.index;
                // console.log("index : "+item.index);
                imageId = i + 1;
                // console.log("select called image id : " + imageId);
                ma([ {
                    name : 'id',
                    value : imageId
                } ]);
            },
            onReachTarget : function(item) {
                this.conf.onclickActiveItem(item);
            }
        }
    });
    ContentFlowGlobal.setAddOnConf("ImageSelectAddOn");
}

可以在以下链接中找到ContentFlow的完整文档: http://www.jacksasylum.eu /ContentFlow/docu.php ,然后可以进行很多自定义.

Full documentation of ContentFlow can be found in this link: http://www.jacksasylum.eu/ContentFlow/docu.php , you can do alot of customization then.

P.S .: ma()p:remoteCommadname,因此我可以将变量传递给backbean.

P.S.: ma() is the name of p:remoteCommad so I can pass variables to backbean.

我的问题就这样解决了,我对这种方式感到满意,希望以后能对其他人有所帮助.

My issue solved like this, and I'm satisfied with this way, I hope I share something helpful for someone else later.

这篇关于如何在Primefaces中覆盖ContentFlow配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 22:28