设置热键以折叠面板

时间:2015-01-30 05:52:59

标签: jsf primefaces

我们的项目使用JSF 2.2 primeface 5.1。

我有一个可切换的面板,collapse属性设置为true。

<p:panel id="panel1" toggleable="true" collapsed="true">
...
</p:panel> 

如何在jsf页面中设置p:hotkey以将属性折叠更改为false?

1 个答案:

答案 0 :(得分:4)

在基本级别,您可以使用以下内容展开窗格:

<p:hotkey bind="ctrl+s" handler="thePanelWidgetVar.expand();" />

如果你真正想要的是切换面板的状态,你可以直接调用面板上的collapse()expand()。显然,您需要检查面板的当前状态以确定要调用的内容。您可以将它全部折叠到以下脚本中:

 <script>
      function togglePanelState (thePanel){

        if(thePanel.cfg.collapsed){
             thePanel.expand();
         }else{
             thePanel.collapse();
         }
      }
 </script>

然后您可以使用togglePanelState

 <p:hotkey bind="ctrl+s" handler="togglePanelState(thePanelWidgetVar);" />

修改

感谢Hatem Alimam指出类似于togglePanelState的实现的便捷方法在PF 5.1中以toggle()函数的形式存在。使用它,您可以改为:

 <p:hotkey bind="ctrl+s" handler="PF('thePanelWidgetVar').toggle();" />