Jsf 取消在p:accordionPanel中关闭选项卡
我有一个p:accordionPanel,在面板的每个选项卡内都有一些用户可以操作的信息,我需要做的是,如果用户关闭选项卡,则会显示一个确认对话框(在选项卡关闭之前),类似于“您确定要关闭选项卡吗?如果您这样做,您的更改将丢失”。这是我试过的Jsf 取消在p:accordionPanel中关闭选项卡,jsf,primefaces,accordion,Jsf,Primefaces,Accordion,我有一个p:accordionPanel,在面板的每个选项卡内都有一些用户可以操作的信息,我需要做的是,如果用户关闭选项卡,则会显示一个确认对话框(在选项卡关闭之前),类似于“您确定要关闭选项卡吗?如果您这样做,您的更改将丢失”。这是我试过的 <p:ajax event="tabClose" onstart="return myFunction()" listener" {myBean.myMethod}" process="@this" /> 问题是,如果我在“确认”对话框中选
<p:ajax event="tabClose" onstart="return myFunction()"
listener" {myBean.myMethod}" process="@this" />
问题是,如果我在“确认”对话框中选择“取消”,选项卡仍然会关闭。选项卡关闭不应该被
onStart=“return false”
取消吗?有什么方法可以实现我想做的吗?最后我解决了我的问题,显然onStart=“return false”
不能阻止选项卡更改其状态,但是p:accordionPanel的onTabChange
属性可以,唯一的问题是,由于某种原因,在打开选项卡时关闭选项卡时,手风琴的onTabchange
事件无法执行,因此我必须重写primefaces的acordionPanel unselect函数来调用onTabchange事件
PrimeFaces.widget.AccordionPanel.prototype.unselect = (function(index) {
var cached_function = PrimeFaces.widget.AccordionPanel.prototype.unselect;
return function() {
var panel = this.panels.eq(index);
if(this.cfg.onTabChange) {
var result = this.cfg.onTabChange.call(this, panel);
if(result === false)
return false;
}
var result = cached_function.apply(this, arguments);
return result;
};
})();
然后我只需要放置myFunction()在相应面板的onTabChange事件(onTabChange=“return myFunction()”
)上执行代码>,并且它可以工作
PrimeFaces.widget.AccordionPanel.prototype.unselect = (function(index) {
var cached_function = PrimeFaces.widget.AccordionPanel.prototype.unselect;
return function() {
var panel = this.panels.eq(index);
if(this.cfg.onTabChange) {
var result = this.cfg.onTabChange.call(this, panel);
if(result === false)
return false;
}
var result = cached_function.apply(this, arguments);
return result;
};
})();