首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PrimeFaces -动态menuItem

PrimeFaces -动态menuItem
EN

Stack Overflow用户
提问于 2013-12-13 04:14:59
回答 2查看 5.4K关注 0票数 0

考虑到下面的代码,它显示了一个包含一列和一个过滤器的表,用于显示活动/非活动记录。如何根据过滤器中选择的值禁用菜单项'Inactive‘?换句话说,如果筛选器值是“非激活”,则应禁用“非激活”菜单。

代码语言:javascript
复制
            <p:contextMenu for="ratingScaleTable" id="RsContextMenuId">
                <p:menuitem value="Edit" update=":templateForm:tabView, :templateForm:dirtyFlag"    icon="ui-icon-search" action="#{ratingScaleBK.edit}" />
                <p:menuitem id="inactivate" value="Inactivate"  icon="ui-icon-close" action="#{ratingScaleBK.inactivate}" disabled="#{ratingScaleBK.selectedRatingScale.active==0}" />
                <p:menuitem value="Activate" update=":templateForm:tabView" icon="ui-icon-close" action="#{ratingScaleBK.activate}"/>
                <p:menuitem value="View Archive" update=":templateForm:tabView" icon="ui-icon-close"/>
            </p:contextMenu>                        

            <p:dataTable id="ratingScaleTable" widgetVar="tableWidget"
                value="#{ratingScaleBK.ratingScaleList}" var="item1" 

                selectionMode="single"
                selection="#{ratingScaleBK.selectedRatingScale}"
                rowKey="#{item1.name}"
                rendered="#{not empty ratingScaleBK.ratingScaleList}"
                filteredValue="#{ratingScaleBK.filteredRatingscale}">

                <p:ajax event="rowSelect" process="ratingScaleTable" listener="#{ratingScaleBK.edit}"  update=":templateForm:tabView, :templateForm:dirtyFlag, :templateForm:tabView:RsContextMenuId " />


                <p:column id="activeCol" filterBy="#{item1.active}"
                    filterOptions="#{ratingScaleBK.activeOptions}"
                    filterMatchMode="exact" width="30">
                    <h:outputText value="#{item1.active}" />
                </p:column>
            </p:dataTable>

现在这个代码不起作用,rowSelect上的contextMenu永远不会更新(菜单项'Inactive‘总是启用的)。我猜在特定行上显示菜单的右键单击事件并不会真正触发rowSelect事件,即使该行被突出显示。那么正确的方法是什么呢?

EN

回答 2

Stack Overflow用户

发布于 2014-02-04 00:47:01

我最终使用了PF forum的这个解决方案:

代码语言:javascript
复制
<p:contextMenu for="ratingScaleTable" id="RsContextMenuId"  widgetVar="ctxMenu" beforeShow="return true;">

<p:dataTable id="ratingScaleTable" widgetVar="tableWidget"
...
  <p:ajax event="rowSelect" process="ratingScaleTable" listener="#{ratingScaleBK.edit}"  update=":templateForm:tabView, :templateForm:dirtyFlag, :templateForm:tabView:RsContextMenuId" />
  <p:ajax event="contextMenu" update=":templateForm:tabView:RsContextMenuId" oncomplete="ctxMenu.show(currentEvent);"/>

以及相关的JavaScript:

代码语言:javascript
复制
<script type="text/javascript">
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(); 
  };
});
</script>
票数 2
EN

Stack Overflow用户

发布于 2014-01-17 22:28:06

尝试使用contextMenu事件:

代码语言:javascript
复制
<p:contextMenu for="ratingScaleTable" id="RsContextMenuId" widgetVar="ctxMenu">
    ...
</p:contextMenu>

<p:dataTable ... > 
    ...
    <p:ajax event="contextMenu" process="ratingScaleTable" listener="#{ratingScaleBK.edit}"  update=":templateForm:tabView, :templateForm:dirtyFlag, :templateForm:tabView:RsContextMenuId" oncomplete="PF('ctxMenu').show();" />
    ...
</p:dataTable>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20553319

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档