号码:文本菜单
<p:contextMenu for="dt" id="_context_menu">
<p:menuitem value="View Distribution" update="act_dist_dt" icon="ui-icon-close" actionListener="#{bankTransactionInqMB.viewDisctributionAcct}" onsuccess="act_dist.show()" />
<p:menuitem value="Issued" update="dt" icon="ui-icon-close" actionListener="#{bankTransactionInqMB.issuedOrUpdate}" rendered="#{bankTransactionInqMB.issueOrUpdate == true}" />
<p:menuitem value="Cleared" update="dt" icon="ui-icon-close" actionListener="#{bankTransactionInqMB.postBankTransaction}" rendered="#{bankTransactionInqMB.cleared == true}" />
<p:menuitem value="Posted" update="dt" icon="ui-icon-close" actionListener="#{bankTransactionInqMB.clearBankTransaction}" rendered="#{bankTransactionInqMB.posted == true}" />
</p:contextMenu>
号码:dataTable中
<p:dataTable var="item" id="dt" style="width: 1200px; margin: 0 auto;" value="#{bankTransactionInqMB.bankTransactions}" rows="15" paginator="true"
paginatorTemplate="{CurrentPageReport} {PreviousPageLink} {NextPageLink} " rowKey="#{item.id}" selectionMode="single" paginatorPosition="bottom"
selection="#{bankTransactionInqMB.bankTransaction}">
....
<p:ajax event="contextMenu" listener="#{bankTransactionInqMB.contextMenuListener}" update=":main:_context_menu" oncomplete="_context_menu.show()" />
</p:dataTable>
当我右键单击数据表时,它会显示上下文菜单,然后立即消失,然后在每个下一个右键单击上下文菜单中显示但是没有调用listener =“#{bankTransactionInqMB.contextMenuListener}”。它仅在第一次右键单击时调用。
我有两个问题:
我基本上想要为每一行实现动态上下文菜单。当用户右键单击时,监听器将决定哪个菜单对于特定行应该可见。
任何更新?
答案 0 :(得分:2)
问题是在更新之前在上下文菜单上调用了show,然后更新隐藏了菜单。
我找到了一个解决方案,取代了主要的JS。
p:contextMenu
<p:contextMenu for="dt" id="_context_menu" widgetVar="_context_menu">
....
</p:contextMenu>
<强>号码:dataTable中强>
<p:dataTable id="dt" .... >
....
<p:ajax event="contextMenu" update=":main:_context_menu" oncomplete="PF('_context_menu').show(currentEvent);" listener="#{bankTransactionInqMB.contextMenuListener}" />
....
</p:dataTable>
添加以下JavaScript: contextMenu.js
var currentEvent;
$(document).ready(function() {
PrimeFaces.widget.ContextMenu.prototype.show = function(e) {
//hide other contextmenus if any
$(document.body).children('.ui-contextmenu:visible').hide();
if(e) {
currentEvent = e;
}
var win = $(window),
left = e.pageX,
top = e.pageY,
width = this.jq.outerWidth(),
height = this.jq.outerHeight();
//collision detection for window boundaries
if((left + width) > (win.width())+ win.scrollLeft()) {
left = left - width;
}
if((top + height ) > (win.height() + win.scrollTop())) {
top = top - height;
}
if(this.cfg.beforeShow) {
this.cfg.beforeShow.call(this);
}
this.jq.css({
'left': left,
'top': top,
'z-index': ++PrimeFaces.zindex
}).show();
e.preventDefault();
};
});
它有效。 资料来源:http://forum.primefaces.org/viewtopic.php?f=3&t=26813#p93374
答案 1 :(得分:-1)
在Primfaces社区论坛中找到this解决方案。希望它有所帮助。