我有一个包含 2 个组件的 JSF 页面:一个按钮和面板。该按钮调用 jQuery toggle
来隐藏和显示面板。我希望当页面加载时,面板最初是隐藏的,这样当我第一次按下按钮时,面板就会显示。
<p:commandButton onclick="PF('panelMatches').toggle()" value="Matches" type="button" />
<p:panel id="button_panel" widgetVar="panelMatches" closable="true" toggleable="true">
Matches: 0
</p:panel>
使用此代码,面板最初始终可见。
最佳答案
只需使用 collapsed="true"
作为 <p:panel>
上的属性。然后它将从一开始就被渲染为“关闭”,并且第一次调用toggle()
将打开它。
请参阅您正在使用的 primefaces 版本的文档:http://www.primefaces.org/documentation.html
Name | Default | Type | Description
collapsed | false | Boolean | Renders a toggleable panel as collapsed.
关于jsf - 如何隐藏可切换 p :panel before the page loads?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31679510/