2012-10-04 19 views
1

我从展示中遵循此示例:http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=popup&sample=login&skin=blueSky 它显示了我如何点击链接来打开popupPanel并将该面板追加到该链接的相同位置。但我希望如果再次点击,它会关闭面板。任何人都知道如何做到这一点?这里是我的代码如何从同一链接中打开和关闭rich:popupPanel

<h:outputLink value="#" id="sb-dd-ol" > 
     <rich:componentControl event="click" operation="show" target="sb-dd-pp"> 
      <a4j:param noEscape="true" value="event"/> 
      <rich:hashParam> 
       <a4j:param noEscape="true" name="top" 
          value="jQuery(#{rich:element('sb-dd-ol')}.parentNode).offset().top + 
            jQuery(#{rich:element('sb-dd-ol')}.parentNode).height()" /> 
       <a4j:param noEscape="true" name="left" 
          value="jQuery(#{rich:element('sb-dd-ol')}.parentNode).offset().left" /> 
      </rich:hashParam> 
     </rich:componentControl> 
     Test 
    </h:outputLink> 
    <rich:popupPanel id="sb-dd-pp" autosized="true" modal="false" 
        moveable="false" resizeable="false" followByScroll="false"> 
     This is a test 
    </rich:popupPanel> 

回答

0

没有很好地意识到RichFaces的4,但modalpanel呈现DIV,其知名度可以与简单的js控制:

var isShown = false; 
function onlinkclick() { 
    if(isShown) { 
     hideElement(); 
    } else { 
     showElement(); 
    } 
    isShown = !isShown; 
} 
5

可以扩展PopupPanel原型,像这样:

jQuery.extend(RichFaces.ui.PopupPanel.prototype, { 
    toggle: function(event, opts) { 
     if (this.shown) { 
      this.hide(event, opts); 
     } else { 
      this.show(event, opts); 
     } 
    } 
} 

之后,您可以在componentControl中使用operation="toggle"(替代方法是在链接上添加onclick="#{rich:component('sb-dd-pp')}.toggle();")。